blob: c92ff3a0184bd4834e3d3c7de10122e04323445f [file] [log] [blame]
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -07001# Copyright 2013 IBM Corp.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_serialization import jsonutils as json
17
18from tempest.lib.common import rest_client
19
20
21class NamespacesClient(rest_client.RestClient):
22 api_version = "v2"
23
24 def create_namespace(self, **kwargs):
25 """Create a namespace.
26
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090027 For a full list of available parameters, please refer to the official
28 API reference:
29 http://developer.openstack.org/api-ref/image/v2/metadefs-index.html#create-namespace
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070030 """
31 data = json.dumps(kwargs)
32 resp, body = self.post('metadefs/namespaces', data)
33 self.expected_success(201, resp.status)
34 body = json.loads(body)
35 return rest_client.ResponseBody(resp, body)
36
37 def show_namespace(self, namespace):
guo yunxian45912d22016-08-26 19:32:11 +080038 """Show namespace details.
39
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090040 For a full list of available parameters, please refer to the official
41 API reference:
42 http://developer.openstack.org/api-ref/image/v2/metadefs-index.html#get-namespace-details
guo yunxian45912d22016-08-26 19:32:11 +080043 """
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070044 url = 'metadefs/namespaces/%s' % namespace
45 resp, body = self.get(url)
46 self.expected_success(200, resp.status)
47 body = json.loads(body)
48 return rest_client.ResponseBody(resp, body)
49
50 def update_namespace(self, namespace, **kwargs):
51 """Update a namespace.
52
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090053 For a full list of available parameters, please refer to the official
54 API reference:
55 http://developer.openstack.org/api-ref/image/v2/metadefs-index.html#update-namespace
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070056 """
57 # NOTE: On Glance API, we need to pass namespace on both URI
58 # and a request body.
59 params = {'namespace': namespace}
60 params.update(kwargs)
61 data = json.dumps(params)
62 url = 'metadefs/namespaces/%s' % namespace
63 resp, body = self.put(url, body=data)
64 self.expected_success(200, resp.status)
65 body = json.loads(body)
66 return rest_client.ResponseBody(resp, body)
67
68 def delete_namespace(self, namespace):
bkopilovcb1c6292016-06-30 09:20:34 +030069 """Delete a namespace.
70
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090071 For a full list of available parameters, please refer to the official
72 API reference:
73 http://developer.openstack.org/api-ref/image/v2/metadefs-index.html#delete-namespace
bkopilovcb1c6292016-06-30 09:20:34 +030074 """
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070075 url = 'metadefs/namespaces/%s' % namespace
76 resp, _ = self.delete(url)
77 self.expected_success(204, resp.status)
78 return rest_client.ResponseBody(resp)