blob: aafa93646104c85454489a9a38ab9f0910339f8a [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
27 Available params: see http://developer.openstack.org/
guo yunxian45912d22016-08-26 19:32:11 +080028 api-ref/image/v2/metadefs-index.html#create-namespace
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070029 """
30 data = json.dumps(kwargs)
31 resp, body = self.post('metadefs/namespaces', data)
32 self.expected_success(201, resp.status)
33 body = json.loads(body)
34 return rest_client.ResponseBody(resp, body)
35
36 def show_namespace(self, namespace):
guo yunxian45912d22016-08-26 19:32:11 +080037 """Show namespace details.
38
39 Available params: see http://developer.openstack.org/
40 api-ref/image/v2/metadefs-index.html#get-namespace-details
41 """
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070042 url = 'metadefs/namespaces/%s' % namespace
43 resp, body = self.get(url)
44 self.expected_success(200, resp.status)
45 body = json.loads(body)
46 return rest_client.ResponseBody(resp, body)
47
48 def update_namespace(self, namespace, **kwargs):
49 """Update a namespace.
50
51 Available params: see http://developer.openstack.org/
guo yunxian45912d22016-08-26 19:32:11 +080052 api-ref/image/v2/metadefs-index.html#update-namespace
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070053 """
54 # NOTE: On Glance API, we need to pass namespace on both URI
55 # and a request body.
56 params = {'namespace': namespace}
57 params.update(kwargs)
58 data = json.dumps(params)
59 url = 'metadefs/namespaces/%s' % namespace
60 resp, body = self.put(url, body=data)
61 self.expected_success(200, resp.status)
62 body = json.loads(body)
63 return rest_client.ResponseBody(resp, body)
64
65 def delete_namespace(self, namespace):
bkopilovcb1c6292016-06-30 09:20:34 +030066 """Delete a namespace.
67
68 Available params: http://developer.openstack.org/
guo yunxian45912d22016-08-26 19:32:11 +080069 api-ref/image/v2/metadefs-index.html#delete-namespace
bkopilovcb1c6292016-06-30 09:20:34 +030070 """
Ken'ichi Ohmichi02886972016-06-06 17:21:27 -070071 url = 'metadefs/namespaces/%s' % namespace
72 resp, _ = self.delete(url)
73 self.expected_success(204, resp.status)
74 return rest_client.ResponseBody(resp)