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
1 changed files with 11 additions and 4 deletions

View File

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