Ken'ichi Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 1 | # 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 | |
| 16 | from oslo_serialization import jsonutils as json |
| 17 | |
| 18 | from tempest.lib.common import rest_client |
| 19 | |
| 20 | |
| 21 | class NamespacesClient(rest_client.RestClient): |
| 22 | api_version = "v2" |
| 23 | |
| 24 | def create_namespace(self, **kwargs): |
| 25 | """Create a namespace. |
| 26 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 27 | 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 Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 30 | """ |
| 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 yunxian | 45912d2 | 2016-08-26 19:32:11 +0800 | [diff] [blame] | 38 | """Show namespace details. |
| 39 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 40 | 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 yunxian | 45912d2 | 2016-08-26 19:32:11 +0800 | [diff] [blame] | 43 | """ |
Ken'ichi Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 44 | 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, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 53 | 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 Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 56 | """ |
| 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): |
bkopilov | cb1c629 | 2016-06-30 09:20:34 +0300 | [diff] [blame] | 69 | """Delete a namespace. |
| 70 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 71 | 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 |
bkopilov | cb1c629 | 2016-06-30 09:20:34 +0300 | [diff] [blame] | 74 | """ |
Ken'ichi Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 75 | url = 'metadefs/namespaces/%s' % namespace |
| 76 | resp, _ = self.delete(url) |
| 77 | self.expected_success(204, resp.status) |
| 78 | return rest_client.ResponseBody(resp) |