Refactor glance version call into method

In order to switch behavior between glance v1 and glance v2 image
uploading, it needs to be possible to get the version in other places
other than just client initialization.

Change-Id: I1c7bcc9948c6ff7de5d4e14ce31b26e83328d5b8
This commit is contained in:
Monty Taylor 2015-01-07 10:08:06 -05:00
parent 4e5a7d160a
commit e42b44f67e

View File

@ -115,6 +115,7 @@ class OpenStackCloud(object):
self._nova_client = None self._nova_client = None
self._glance_client = None self._glance_client = None
self._glance_endpoint = None
self._ironic_client = None self._ironic_client = None
self._keystone_client = None self._keystone_client = None
self._cinder_client = None self._cinder_client = None
@ -204,11 +205,12 @@ class OpenStackCloud(object):
"Error authenticating to the keystone: %s " % e.message) "Error authenticating to the keystone: %s " % e.message)
return self._keystone_client return self._keystone_client
def _get_glance_api_version(self, endpoint): def _get_glance_api_version(self):
if 'image' in self.api_versions: if 'image' in self.api_versions:
return self.api_versions['image'] return self.api_versions['image']
# Yay. We get to guess ... # Yay. We get to guess ...
# Get rid of trailing '/' if present # Get rid of trailing '/' if present
endpoint = self._get_glance_endpoint()
if endpoint.endswith('/'): if endpoint.endswith('/'):
endpoint = endpoint[:-1] endpoint = endpoint[:-1]
url_bits = endpoint.split('/') url_bits = endpoint.split('/')
@ -216,13 +218,18 @@ class OpenStackCloud(object):
return url_bits[-1][1] return url_bits[-1][1]
return '1' # Who knows? Let's just try 1 ... return '1' # Who knows? Let's just try 1 ...
def _get_glance_endpoint(self):
if self._glance_endpoint is None:
self._glance_endpoint = self.get_endpoint(
service_type=self.get_service_type('image'))
return self._glance_endpoint
@property @property
def glance_client(self): def glance_client(self):
if self._glance_client is None: if self._glance_client is None:
token = self.keystone_client.auth_token token = self.keystone_client.auth_token
endpoint = self.get_endpoint( endpoint = self._get_glance_endpoint()
service_type=self.get_service_type('image')) glance_api_version = self._get_glance_api_version()
glance_api_version = self._get_glance_api_version(endpoint)
try: try:
self._glance_client = glanceclient.Client( self._glance_client = glanceclient.Client(
glance_api_version, endpoint, token=token, glance_api_version, endpoint, token=token,