Support package update, toggle_active and filter methods.
Change-Id: Ic82fc95c36d00653c46ead28e580238351516353 Partially-implements: blueprint service-defitions-migrate-to-apps-ui
This commit is contained in:
parent
3e387adf1e
commit
b06d943e32
|
@ -240,9 +240,10 @@ class HTTPClient(object):
|
|||
|
||||
return resp, body_iter
|
||||
|
||||
def json_request(self, method, url, **kwargs):
|
||||
def base_json_request(self, method, url, content_type='application/json',
|
||||
**kwargs):
|
||||
kwargs.setdefault('headers', {})
|
||||
kwargs['headers'].setdefault('Content-Type', 'application/json')
|
||||
kwargs['headers'].setdefault('Content-Type', content_type)
|
||||
|
||||
if 'body' in kwargs:
|
||||
kwargs['body'] = json.dumps(kwargs['body'])
|
||||
|
@ -260,6 +261,14 @@ class HTTPClient(object):
|
|||
|
||||
return resp, body
|
||||
|
||||
def json_request(self, method, url, **kwargs):
|
||||
return self.base_json_request(method, url, **kwargs)
|
||||
|
||||
def json_patch_request(self, url, method='PATCH', **kwargs):
|
||||
content_type = 'application/murano-packages-json-patch'
|
||||
return self.base_json_request(
|
||||
method, url, content_type=content_type, **kwargs)
|
||||
|
||||
def raw_request(self, method, url, **kwargs):
|
||||
kwargs.setdefault('headers', {})
|
||||
kwargs['headers'].setdefault('Content-Type',
|
||||
|
|
|
@ -61,9 +61,23 @@ class PackageManager(base.Manager):
|
|||
def get(self, app_id):
|
||||
return self._get('/v1/catalog/packages/{0}'.format(app_id))
|
||||
|
||||
def filter(self, **kwargs):
|
||||
# TODO(tsufiev): make it more bulletproof
|
||||
query_string = '&'.join(['{0}={1}'.format(k, v)
|
||||
for (k, v) in kwargs.iteritems()])
|
||||
url = '/v1/catalog/packages?{0}'.format(query_string)
|
||||
return self._list(url, 'packages')
|
||||
|
||||
def delete(self, app_id):
|
||||
return self._delete('/v1/catalog/packages/{0}'.format(app_id))
|
||||
|
||||
def update(self, app_id, body):
|
||||
url = '/v1/catalog/packages/{0}'.format(app_id)
|
||||
data = []
|
||||
for key, value in body.iteritems():
|
||||
data.append({'op': 'replace', 'path': '/' + key, 'value': value})
|
||||
return self.api.json_patch_request(url, body=data)
|
||||
|
||||
def download(self, app_id):
|
||||
url = '/v1/catalog/packages/{0}/download'.format(app_id)
|
||||
response, iterator = self.api.raw_request('GET', url)
|
||||
|
@ -72,6 +86,12 @@ class PackageManager(base.Manager):
|
|||
else:
|
||||
raise exceptions.from_response(response)
|
||||
|
||||
def toggle_active(self, app_id):
|
||||
url = '/v1/catalog/packages/{0}'.format(app_id)
|
||||
enabled = self.get(app_id).enabled
|
||||
data = [{'op': 'replace', 'path': '/enabled', 'value': not enabled}]
|
||||
return self.api.json_patch_request(url, body=data)
|
||||
|
||||
def get_ui(self, app_id):
|
||||
url = '/v1/catalog/packages/{0}/ui'.format(app_id)
|
||||
response, iterator = self.api.raw_request('GET', url)
|
||||
|
|
Loading…
Reference in New Issue