blob: b3f94aa7fc440101bc48ea5fed63384a27ef8339 [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
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090027 For a full list of available parameters, please refer to the official
28 API reference:
29 http://developer.openstack.org/api-ref/identity/v2-ext/?expanded=#create-service-admin-extension
Lv Fumeid1945ff2016-07-07 11:03:39 +080030 """
ghanshyam6ce39212016-06-15 13:20:11 +090031 post_body = json.dumps({'OS-KSADM:service': kwargs})
Daniel Mellado72f24ec2015-12-21 10:26:42 +000032 resp, body = self.post('/OS-KSADM/services', post_body)
33 self.expected_success(200, resp.status)
34 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080035 return rest_client.ResponseBody(resp, body)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000036
37 def show_service(self, service_id):
38 """Get Service."""
39 url = '/OS-KSADM/services/%s' % service_id
40 resp, body = self.get(url)
41 self.expected_success(200, resp.status)
42 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080043 return rest_client.ResponseBody(resp, body)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000044
ghanshyam6ce39212016-06-15 13:20:11 +090045 def list_services(self, **params):
Lv Fumeid1945ff2016-07-07 11:03:39 +080046 """List Service - Returns Services.
47
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090048 For a full list of available parameters, please refer to the official
49 API reference:
50 http://developer.openstack.org/api-ref/identity/v2-ext/?expanded=#list-services-admin-extension
Lv Fumeid1945ff2016-07-07 11:03:39 +080051 """
ghanshyam6ce39212016-06-15 13:20:11 +090052 url = '/OS-KSADM/services'
53 if params:
54 url += '?%s' % urllib.urlencode(params)
55 resp, body = self.get(url)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000056 self.expected_success(200, resp.status)
57 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080058 return rest_client.ResponseBody(resp, body)
Daniel Mellado72f24ec2015-12-21 10:26:42 +000059
60 def delete_service(self, service_id):
61 """Delete Service."""
62 url = '/OS-KSADM/services/%s' % service_id
63 resp, body = self.delete(url)
64 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080065 return rest_client.ResponseBody(resp, body)