harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 1 | # Copyright 2013 OpenStack Foundation |
| 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 | |
Yaroslav Lobankov | 61db2d9 | 2015-11-11 16:51:23 +0300 | [diff] [blame] | 16 | """ |
zhufl | 03e1ad7 | 2017-03-08 14:07:01 +0800 | [diff] [blame] | 17 | https://developer.openstack.org/api-ref/identity/v3/index.html#service-catalog-and-endpoints |
Yaroslav Lobankov | 61db2d9 | 2015-11-11 16:51:23 +0300 | [diff] [blame] | 18 | """ |
| 19 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 20 | from oslo_serialization import jsonutils as json |
ghanshyam | ef301d8 | 2016-08-01 17:04:28 +0900 | [diff] [blame] | 21 | from six.moves.urllib import parse as urllib |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 22 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 23 | from tempest.lib.common import rest_client |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 24 | |
| 25 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 26 | class ServicesClient(rest_client.RestClient): |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 27 | api_version = "v3" |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 28 | |
| 29 | def update_service(self, service_id, **kwargs): |
Yaroslav Lobankov | 61db2d9 | 2015-11-11 16:51:23 +0300 | [diff] [blame] | 30 | """Updates a service. |
| 31 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 32 | For a full list of available parameters, please refer to the official |
| 33 | API reference: |
| 34 | http://developer.openstack.org/api-ref/identity/v3/index.html#update-service |
Yaroslav Lobankov | 61db2d9 | 2015-11-11 16:51:23 +0300 | [diff] [blame] | 35 | """ |
| 36 | patch_body = json.dumps({'service': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 37 | resp, body = self.patch('services/%s' % service_id, patch_body) |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 38 | self.expected_success(200, resp.status) |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 39 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 40 | return rest_client.ResponseBody(resp, body) |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 41 | |
Ken'ichi Ohmichi | 402b875 | 2015-11-09 10:47:16 +0000 | [diff] [blame] | 42 | def show_service(self, service_id): |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 43 | """Get Service.""" |
| 44 | url = 'services/%s' % service_id |
| 45 | resp, body = self.get(url) |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 46 | self.expected_success(200, resp.status) |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 47 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 48 | return rest_client.ResponseBody(resp, body) |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 49 | |
Yaroslav Lobankov | 61db2d9 | 2015-11-11 16:51:23 +0300 | [diff] [blame] | 50 | def create_service(self, **kwargs): |
| 51 | """Creates a service. |
| 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/identity/v3/index.html#create-service |
Yaroslav Lobankov | 61db2d9 | 2015-11-11 16:51:23 +0300 | [diff] [blame] | 56 | """ |
| 57 | body = json.dumps({'service': kwargs}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 58 | resp, body = self.post("services", body) |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 59 | self.expected_success(201, resp.status) |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 60 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 61 | return rest_client.ResponseBody(resp, body) |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 62 | |
ghanshyam | ef301d8 | 2016-08-01 17:04:28 +0900 | [diff] [blame] | 63 | def delete_service(self, service_id): |
| 64 | url = "services/" + service_id |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 65 | resp, body = self.delete(url) |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 66 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 67 | return rest_client.ResponseBody(resp, body) |
nayna-patel | 54b0fb5 | 2014-04-25 13:19:16 +0000 | [diff] [blame] | 68 | |
ghanshyam | ef301d8 | 2016-08-01 17:04:28 +0900 | [diff] [blame] | 69 | def list_services(self, **params): |
| 70 | """List services. |
| 71 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 72 | For a full list of available parameters, please refer to the official |
| 73 | API reference: |
| 74 | http://developer.openstack.org/api-ref/identity/v3/#list-services |
ghanshyam | ef301d8 | 2016-08-01 17:04:28 +0900 | [diff] [blame] | 75 | """ |
| 76 | url = 'services' |
| 77 | if params: |
| 78 | url += '?%s' % urllib.urlencode(params) |
Felipe Monteiro | 1457006 | 2017-05-31 13:25:14 +0100 | [diff] [blame] | 79 | resp, body = self.get(url) |
nayna-patel | 54b0fb5 | 2014-04-25 13:19:16 +0000 | [diff] [blame] | 80 | self.expected_success(200, resp.status) |
| 81 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 82 | return rest_client.ResponseBody(resp, body) |