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 | |
| 27 | Available params: see http://developer.openstack.org/ |
guo yunxian | 45912d2 | 2016-08-26 19:32:11 +0800 | [diff] [blame] | 28 | api-ref/image/v2/metadefs-index.html#create-namespace |
Ken'ichi Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 29 | """ |
| 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 yunxian | 45912d2 | 2016-08-26 19:32:11 +0800 | [diff] [blame] | 37 | """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 Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 42 | 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 yunxian | 45912d2 | 2016-08-26 19:32:11 +0800 | [diff] [blame] | 52 | api-ref/image/v2/metadefs-index.html#update-namespace |
Ken'ichi Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 53 | """ |
| 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): |
bkopilov | cb1c629 | 2016-06-30 09:20:34 +0300 | [diff] [blame] | 66 | """Delete a namespace. |
| 67 | |
| 68 | Available params: http://developer.openstack.org/ |
guo yunxian | 45912d2 | 2016-08-26 19:32:11 +0800 | [diff] [blame] | 69 | api-ref/image/v2/metadefs-index.html#delete-namespace |
bkopilov | cb1c629 | 2016-06-30 09:20:34 +0300 | [diff] [blame] | 70 | """ |
Ken'ichi Ohmichi | 0288697 | 2016-06-06 17:21:27 -0700 | [diff] [blame] | 71 | url = 'metadefs/namespaces/%s' % namespace |
| 72 | resp, _ = self.delete(url) |
| 73 | self.expected_success(204, resp.status) |
| 74 | return rest_client.ResponseBody(resp) |