Further refactor of Glare API urls

This patch makes addressing to urls within file more convenient

Change-Id: I1fe086d2f29569ca73908da49e0ee77fd450fced
Related-Bug: #1576192
This commit is contained in:
Omar Shykhkerimov 2016-05-19 13:38:21 +03:00
parent 3c36f1b70d
commit 9e86f6c855

View File

@ -22,12 +22,15 @@ from muranoclient.glance import ArtifactType
glare_urls = {
'create': '/v%s/artifacts/%s/v%s/drafts',
'update_get_delete': '/v%s/artifacts/%s/v%s/%s',
'list_drafts': '/v%s/artifacts/%s/v%s/drafts?',
'list_no_drafts': '/v%s/artifacts/%s/v%s?',
'publish': '/v%s/artifacts/%s/v%s/%s/publish',
'blob': '/v%s/artifacts/%s/v%s/%s/%s',
'create': '/v{version}/artifacts/{type_name}/v{type_version}/drafts',
'update_get_delete': '/v{version}/artifacts/{type_name}/v{type_version}'
'/{artifact_id}',
'list_drafts': '/v{version}/artifacts/{type_name}/v{type_version}/drafts?',
'list_no_drafts': '/v{version}/artifacts/{type_name}/v{type_version}?',
'publish': '/v{version}/artifacts/{type_name}/v{type_version}/'
'{artifact_id}/publish',
'blob': '/v{version}/artifacts/{type_name}/v{type_version}/{artifact_id}'
'/{blob_property}',
}
@ -82,7 +85,9 @@ class Controller(object):
type_name, type_version = self._check_type_params(type_name,
type_version)
kwargs.update({'name': name, 'version': version})
url = glare_urls['create'] % (self.version, type_name, type_version)
url = glare_urls['create'].format(version=self.version,
type_name=type_name,
type_version=type_version)
resp, body = self.http_client.post(url, data=kwargs)
return ArtifactType(**body)
@ -96,8 +101,10 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = glare_urls['update_get_delete'] % (self.version, type_name,
type_version, artifact_id)
url = glare_urls['update_get_delete'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id)
hdrs = {
'Content-Type': 'application/openstack-images-v2.1-json-patch'}
@ -143,8 +150,10 @@ class Controller(object):
type_name, type_version = self._check_type_params(type_name,
type_version)
url = glare_urls['update_get_delete'] % (self.version, type_name,
type_version, artifact_id)
url = glare_urls['update_get_delete'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id)
if show_level:
if show_level not in ArtifactType.supported_show_levels:
msg = "Invalid show level: %s" % show_level
@ -206,11 +215,15 @@ class Controller(object):
url_params.append({param: value})
if drafts:
url = glare_urls['list_drafts'] % (self.version, type_name,
type_version)
url = glare_urls['list_drafts'].format(version=self.version,
type_name=type_name,
type_version=type_version)
else:
url = glare_urls['list_no_drafts'] % (self.version, type_name,
type_version)
url = glare_urls['list_no_drafts'].format(
version=self.version,
type_name=type_name,
type_version=type_version
)
for param in url_params:
url = '%s&%s' % (url, parse.urlencode(param))
@ -230,8 +243,10 @@ class Controller(object):
type_name, type_version = self._check_type_params(type_name,
type_version)
url = glare_urls['publish'] % (self.version, type_name,
type_version, artifact_id)
url = glare_urls['publish'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id)
resp, body = self.http_client.post(url)
return ArtifactType(**body)
@ -246,8 +261,10 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = glare_urls['update_get_delete'] % (self.version, type_name,
type_version, artifact_id)
url = glare_urls['update_get_delete'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id)
self.http_client.delete(url)
def upload_blob(self, artifact_id, blob_property, data, position=None,
@ -263,8 +280,11 @@ class Controller(object):
type_version)
hdrs = {'Content-Type': 'application/octet-stream'}
url = glare_urls['blob'] % (self.version, type_name, type_version,
artifact_id, blob_property)
url = glare_urls['blob'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id,
blob_property=blob_property)
if position:
url += "/%s" % position
@ -282,8 +302,11 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = glare_urls['blob'] % (self.version, type_name, type_version,
artifact_id, blob_property)
url = glare_urls['blob'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id,
blob_property=blob_property)
if position:
url += '/%s' % position
@ -309,8 +332,11 @@ class Controller(object):
"""
type_name, type_version = self._check_type_params(type_name,
type_version)
url = glare_urls['blob'] % (self.version, type_name, type_version,
artifact_id, blob_property)
url = glare_urls['blob'].format(version=self.version,
type_name=type_name,
type_version=type_version,
artifact_id=artifact_id,
blob_property=blob_property)
if position:
url += '/%s' % position
self.http_client.delete(url)