Docker hub root paths were incorrect, also include content-type headers just incase.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a3ed405e Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a3ed405e Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a3ed405e Branch: refs/heads/trunk Commit: a3ed405e7b5ec32d0d42bdf00bfca5cc600c424f Parents: 621ec71 Author: anthony-shaw <[email protected]> Authored: Mon Jan 11 15:51:43 2016 +1100 Committer: anthony-shaw <[email protected]> Committed: Mon Jan 11 15:51:43 2016 +1100 ---------------------------------------------------------------------- libcloud/container/utils/docker.py | 33 +++++++++++++++-------- libcloud/test/container/test_docker_utils.py | 14 +++------- 2 files changed, 25 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/a3ed405e/libcloud/container/utils/docker.py ---------------------------------------------------------------------- diff --git a/libcloud/container/utils/docker.py b/libcloud/container/utils/docker.py index a8a544a..ba83097 100644 --- a/libcloud/container/utils/docker.py +++ b/libcloud/container/utils/docker.py @@ -29,12 +29,23 @@ __all__ = [ class DockerHubConnection(Connection): responseCls = JsonResponse - def __init__(self, host, username=None, password=None, **kwargs): - super(DockerHubConnection, self).__init__(host=host, **kwargs) + def __init__(self, host, username=None, password=None, + secure=True, + port=None, url=None, timeout=None, + proxy_url=None, backoff=None, retry_delay=None): + super(DockerHubConnection, self).__init__( + secure=secure, host=host, + port=port, url=url, + timeout=timeout, + proxy_url=proxy_url, + backoff=backoff, + retry_delay=retry_delay + ) self.username = username self.password = password def add_default_headers(self, headers): + headers['Content-Type'] = 'application/json' if self.username is not None: authstr = 'Basic ' + str( b64encode( @@ -63,10 +74,10 @@ class RegistryClient(object): :param password: (optional) Your hub account password :type password: ``str`` """ - self.connection = DockerHubConnection(host, - username, - password, - **kwargs) + self.connection = self.connectionCls(host, + username, + password, + **kwargs) def list_images(self, repository_name, namespace='library', max_count=100): """ @@ -84,7 +95,7 @@ class RegistryClient(object): :return: A list of images :rtype: ``list`` of :class:`libcloud.container.base.ContainerImage` """ - path = 'v2/repositories/%s/%s/tags/?page=1&page_size=%s' \ + path = '/v2/repositories/%s/%s/tags/?page=1&page_size=%s' \ % (namespace, repository_name, max_count) response = self.connection.request(path) images = [] @@ -105,7 +116,7 @@ class RegistryClient(object): :return: The details of the repository :rtype: ``object`` """ - path = 'v2/repositories/%s/%s' % (namespace, repository_name) + path = '/v2/repositories/%s/%s' % (namespace, repository_name) response = self.connection.request(path) return response.object @@ -125,7 +136,7 @@ class RegistryClient(object): :return: A container image :rtype: :class:`libcloud.container.base.ContainerImage` """ - path = 'v2/repositories/%s/%s/tags/%s' \ + path = '/v2/repositories/%s/%s/tags/%s' \ % (namespace, repository_name, tag) response = self.connection.request(path) return self._to_image(repository_name, response.object) @@ -164,5 +175,5 @@ class HubClient(RegistryClient): :param password: (optional) Your hub account password :type password: ``str`` """ - self.connection = DockerHubConnection(self.host, username, - password, **kwargs) + super(HubClient, self).__init__(self.host, username, + password, **kwargs) http://git-wip-us.apache.org/repos/asf/libcloud/blob/a3ed405e/libcloud/test/container/test_docker_utils.py ---------------------------------------------------------------------- diff --git a/libcloud/test/container/test_docker_utils.py b/libcloud/test/container/test_docker_utils.py index d209447..8c8bd90 100644 --- a/libcloud/test/container/test_docker_utils.py +++ b/libcloud/test/container/test_docker_utils.py @@ -50,15 +50,7 @@ class DockerUtilitiesTestCase(unittest.TestCase): class DockerMockHttp(MockHttp): fixtures = ContainerFileFixtures('docker_utils') - def _version( - self, method, url, body, headers): - if method == 'GET': - body = self.fixtures.load('version.json') - else: - raise AssertionError('Unsupported method') - return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - - def v2_repositories_library_ubuntu_tags_latest( + def _v2_repositories_library_ubuntu_tags_latest( self, method, url, body, headers): if method == 'GET': body = self.fixtures.load('v2_repositories_library_ubuntu_tags_latest.json') @@ -66,7 +58,7 @@ class DockerMockHttp(MockHttp): raise AssertionError('Unsupported method') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - def v2_repositories_library_ubuntu_tags( + def _v2_repositories_library_ubuntu_tags( self, method, url, body, headers): if method == 'GET': body = self.fixtures.load('v2_repositories_library_ubuntu_tags.json') @@ -74,7 +66,7 @@ class DockerMockHttp(MockHttp): raise AssertionError('Unsupported method') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - def v2_repositories_library_ubuntu( + def _v2_repositories_library_ubuntu( self, method, url, body, headers): if method == 'GET': body = self.fixtures.load('v2_repositories_library_ubuntu.json')
