Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 1 | # Copyright 2015 Red Hat, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | from oslo_serialization import jsonutils as json |
ghanshyam | 6ce3921 | 2016-06-15 13:20:11 +0900 | [diff] [blame] | 16 | from six.moves.urllib import parse as urllib |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 17 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 18 | from tempest.lib.common import rest_client |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 19 | |
| 20 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 21 | class ServicesClient(rest_client.RestClient): |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 22 | api_version = "v2.0" |
| 23 | |
ghanshyam | 6ce3921 | 2016-06-15 13:20:11 +0900 | [diff] [blame] | 24 | def create_service(self, **kwargs): |
Lv Fumei | d1945ff | 2016-07-07 11:03:39 +0800 | [diff] [blame] | 25 | """Create a service. |
| 26 | |
| 27 | Available params: see http://developer.openstack.org/api-ref/identity/ |
| 28 | v2-ext/?expanded=#create-service-admin-extension |
| 29 | """ |
ghanshyam | 6ce3921 | 2016-06-15 13:20:11 +0900 | [diff] [blame] | 30 | post_body = json.dumps({'OS-KSADM:service': kwargs}) |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 31 | resp, body = self.post('/OS-KSADM/services', post_body) |
| 32 | self.expected_success(200, resp.status) |
| 33 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 34 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 35 | |
| 36 | def show_service(self, service_id): |
| 37 | """Get Service.""" |
| 38 | url = '/OS-KSADM/services/%s' % service_id |
| 39 | resp, body = self.get(url) |
| 40 | self.expected_success(200, resp.status) |
| 41 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 42 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 43 | |
ghanshyam | 6ce3921 | 2016-06-15 13:20:11 +0900 | [diff] [blame] | 44 | def list_services(self, **params): |
Lv Fumei | d1945ff | 2016-07-07 11:03:39 +0800 | [diff] [blame] | 45 | """List Service - Returns Services. |
| 46 | |
| 47 | Available params: see http://developer.openstack.org/api-ref/identity/ |
| 48 | v2-ext/?expanded=#list-services-admin-extension |
| 49 | """ |
ghanshyam | 6ce3921 | 2016-06-15 13:20:11 +0900 | [diff] [blame] | 50 | url = '/OS-KSADM/services' |
| 51 | if params: |
| 52 | url += '?%s' % urllib.urlencode(params) |
| 53 | resp, body = self.get(url) |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 54 | self.expected_success(200, resp.status) |
| 55 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 56 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 72f24ec | 2015-12-21 10:26:42 +0000 | [diff] [blame] | 57 | |
| 58 | def delete_service(self, service_id): |
| 59 | """Delete Service.""" |
| 60 | url = '/OS-KSADM/services/%s' % service_id |
| 61 | resp, body = self.delete(url) |
| 62 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 63 | return rest_client.ResponseBody(resp, body) |