blob: c26d41954aba1a96617c77dd79c17ca6f258ed3b [file] [log] [blame]
Daniel Mellado72f24ec2015-12-21 10:26:42 +00001# 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
15from oslo_serialization import jsonutils as json
ghanshyam6ce39212016-06-15 13:20:11 +090016from six.moves.urllib import parse as urllib
Daniel Mellado72f24ec2015-12-21 10:26:42 +000017
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080018from tempest.lib.common import rest_client
Daniel Mellado72f24ec2015-12-21 10:26:42 +000019
20
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080021class ServicesClient(rest_client.RestClient):
Daniel Mellado72f24ec2015-12-21 10:26:42 +000022 api_version = "v2.0"
23
ghanshyam6ce39212016-06-15 13:20:11 +090024 def create_service(self, **kwargs):
Lv Fumeid1945ff2016-07-07 11:03:39 +080025 """Create a service.
26
27 Available params: see http://developer.openstack.org/api-ref/identity/
28 v2-ext/?expanded=#create-service-admin-extension
29 """
ghanshyam6ce39212016-06-15 13:20:11 +090030 post_body = json.dumps({'OS-KSADM:service': kwargs})
Daniel Mellado72f24ec2015-12-21 10:26:42 +000031 resp, body = self.post('/OS-KSADM/services', post_body)
32 self.expected_success(200, resp.status)
33 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080034 return rest_client.ResponseBody(resp, body)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000035
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 Ohmichid35a1332016-03-02 10:38:07 -080042 return rest_client.ResponseBody(resp, body)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000043
ghanshyam6ce39212016-06-15 13:20:11 +090044 def list_services(self, **params):
Lv Fumeid1945ff2016-07-07 11:03:39 +080045 """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 """
ghanshyam6ce39212016-06-15 13:20:11 +090050 url = '/OS-KSADM/services'
51 if params:
52 url += '?%s' % urllib.urlencode(params)
53 resp, body = self.get(url)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000054 self.expected_success(200, resp.status)
55 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080056 return rest_client.ResponseBody(resp, body)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000057
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 Ohmichid35a1332016-03-02 10:38:07 -080063 return rest_client.ResponseBody(resp, body)