From 24340329cf0abb03533920b6e71014c3a59da482 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Mon, 9 Dec 2013 18:32:29 +0200 Subject: [PATCH] Replace inheritance hierarchy with composition In the process of unification of the clients code we should use composition to allow easier replacement with common HTTPClient. Related to blueprint common-client-library-2 Change-Id: I5addc38eb2e2dd0be91b566fda7c0d81787ffa75 --- glanceclient/v1/client.py | 8 ++++---- glanceclient/v1/legacy_shell.py | 2 +- tests/v1/test_legacy_shell.py | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/glanceclient/v1/client.py b/glanceclient/v1/client.py index d28b663..bc020b6 100644 --- a/glanceclient/v1/client.py +++ b/glanceclient/v1/client.py @@ -18,7 +18,7 @@ from glanceclient.v1 import images from glanceclient.v1 import image_members -class Client(http.HTTPClient): +class Client(object): """Client for the OpenStack Images v1 API. :param string endpoint: A user-supplied endpoint URL for the glance @@ -30,6 +30,6 @@ class Client(http.HTTPClient): def __init__(self, *args, **kwargs): """Initialize a new client for the Images v1 API.""" - super(Client, self).__init__(*args, **kwargs) - self.images = images.ImageManager(self) - self.image_members = image_members.ImageMemberManager(self) + self.http_client = http.HTTPClient(*args, **kwargs) + self.images = images.ImageManager(self.http_client) + self.image_members = image_members.ImageMemberManager(self.http_client) diff --git a/glanceclient/v1/legacy_shell.py b/glanceclient/v1/legacy_shell.py index 605ce8f..77e4372 100644 --- a/glanceclient/v1/legacy_shell.py +++ b/glanceclient/v1/legacy_shell.py @@ -75,7 +75,7 @@ def print_image_formatted(client, image): :param client: The Glance client object :param image: The image metadata """ - uri_parts = urlparse.urlparse(client.endpoint) + uri_parts = urlparse.urlparse(client.http_client.endpoint) if uri_parts.port: hostbase = "%s:%s" % (uri_parts.hostname, uri_parts.port) else: diff --git a/tests/v1/test_legacy_shell.py b/tests/v1/test_legacy_shell.py index c939e5d..53adb45 100644 --- a/tests/v1/test_legacy_shell.py +++ b/tests/v1/test_legacy_shell.py @@ -27,7 +27,9 @@ class LegacyShellV1Test(testtools.TestCase): def test_print_image_formatted(self): class FakeClient(): - endpoint = 'http://is.invalid' + class FakeHTTPClient(): + endpoint = 'http://is.invalid' + http_client = FakeHTTPClient() class FakeImage(): id = 1