Make use of version passed to glare artifacts_client

Url for artifacts in Controller class uses client version as a variable
instead of hardcoded '0.1'

Change-Id: I2e1036d536dcd906cc1683ff4031cc23e9b507b9
Closes-bug: #1551736
This commit is contained in:
Valerii Kovalchuk 2016-03-23 17:14:54 +02:00
parent e0da03f978
commit 5555dbaa7e
2 changed files with 29 additions and 22 deletions

View File

@ -22,10 +22,12 @@ from muranoclient.glance import ArtifactType
class Controller(object):
def __init__(self, http_client, type_name=None, type_version=None):
def __init__(self, http_client, type_name=None, type_version=None,
version='0.1'):
self.http_client = http_client
self.type_name = type_name
self.type_version = type_version
self.version = version
self.default_page_size = 20
self.sort_dir_values = ('asc', 'desc')
@ -70,7 +72,8 @@ class Controller(object):
type_name, type_version = self._check_type_params(type_name,
type_version)
kwargs.update({'name': name, 'version': version})
url = '/v0.1/artifacts/%s/v%s/drafts' % (type_name, type_version)
url = '/v%s/artifacts/%s/v%s/drafts' % (self.version, type_name,
type_version)
resp, body = self.http_client.post(url, data=kwargs)
return ArtifactType(**body)
@ -84,8 +87,8 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = '/v0.1/artifacts/%s/v%s/%s' % (type_name, type_version,
artifact_id)
url = '/v%s/artifacts/%s/v%s/%s' % (self.version, type_name,
type_version, artifact_id)
hdrs = {
'Content-Type': 'application/openstack-images-v2.1-json-patch'}
@ -131,8 +134,8 @@ class Controller(object):
type_name, type_version = self._check_type_params(type_name,
type_version)
url = '/v0.1/artifacts/%s/v%s/%s' % (type_name, type_version,
artifact_id)
url = '/v%s/artifacts/%s/v%s/%s' % (self.version, type_name,
type_version, artifact_id)
if show_level:
if show_level not in ArtifactType.supported_show_levels:
msg = "Invalid show level: %s" % show_level
@ -194,10 +197,11 @@ class Controller(object):
url_params.append({param: value})
if drafts:
url = '/v0.1/artifacts/%s/' \
'v%s/drafts?' % (type_name, type_version)
url = '/v%s/artifacts/%s/' \
'v%s/drafts?' % (self.version, type_name, type_version)
else:
url = '/v0.1/artifacts/%s/v%s?' % (type_name, type_version)
url = '/v%s/artifacts/%s/v%s?' % (self.version, type_name,
type_version)
for param in url_params:
url = '%s&%s' % (url, parse.urlencode(param))
@ -217,8 +221,8 @@ class Controller(object):
type_name, type_version = self._check_type_params(type_name,
type_version)
url = '/v0.1/artifacts/%s/v%s/%s/publish' % (type_name, type_version,
artifact_id)
url = '/v%s/artifacts/%s/v%s/%s/publish' % (self.version, type_name,
type_version, artifact_id)
resp, body = self.http_client.post(url)
return ArtifactType(**body)
@ -233,8 +237,8 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = '/v0.1/artifacts/%s/v%s/%s' % (type_name, type_version,
artifact_id)
url = '/v%s/artifacts/%s/v%s/%s' % (self.version, type_name,
type_version, artifact_id)
self.http_client.delete(url)
def upload_blob(self, artifact_id, blob_property, data, position=None,
@ -250,8 +254,9 @@ class Controller(object):
type_version)
hdrs = {'Content-Type': 'application/octet-stream'}
url = '/v0.1/artifacts/%s/v%s/%s/%s' % (type_name, type_version,
artifact_id, blob_property)
url = '/v%s/artifacts/%s/v%s/%s/%s' % (self.version, type_name,
type_version, artifact_id,
blob_property)
if position:
url += "/%s" % position
@ -269,8 +274,9 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = '/v0.1/artifacts/%s/v%s/%s/%s' % (type_name, type_version,
artifact_id, blob_property)
url = '/v%s/artifacts/%s/v%s/%s/%s' % (self.version, type_name,
type_version, artifact_id,
blob_property)
if position:
url += '/%s' % position
@ -296,8 +302,9 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = '/v0.1/artifacts/%s/v%s/%s/%s' % (type_name, type_version,
artifact_id, blob_property)
url = '/v%s/artifacts/%s/v%s/%s/%s' % (self.version, type_name,
type_version, artifact_id,
blob_property)
if position:
url += '/%s' % position
self.http_client.delete(url)

View File

@ -30,8 +30,7 @@ class Client(object):
def __init__(self, endpoint, type_name, type_version, **kwargs):
endpoint, version = utils.strip_version(endpoint)
# TODO(kzaitsev): start using this variable
self.version = version or 0.1
self.version = version or '0.1'
self.http_client = http.HTTPClient(endpoint, **kwargs)
self.type_name = type_name
@ -39,4 +38,5 @@ class Client(object):
self.artifacts = artifacts.Controller(self.http_client,
self.type_name,
self.type_version)
self.type_version,
self.version)