blob: 7bbe850b59d55a72ecbe2dac064834acecac9849 [file] [log] [blame]
harika-vakadia92dd742013-02-19 20:41:22 +05301# 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 Lobankov61db2d92015-11-11 16:51:23 +030016"""
zhufl03e1ad72017-03-08 14:07:01 +080017https://developer.openstack.org/api-ref/identity/v3/index.html#service-catalog-and-endpoints
Yaroslav Lobankov61db2d92015-11-11 16:51:23 +030018"""
19
Matthew Treinish21905512015-07-13 10:33:35 -040020from oslo_serialization import jsonutils as json
ghanshyamef301d82016-08-01 17:04:28 +090021from six.moves.urllib import parse as urllib
harika-vakadia92dd742013-02-19 20:41:22 +053022
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080023from tempest.lib.common import rest_client
harika-vakadia92dd742013-02-19 20:41:22 +053024
25
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080026class ServicesClient(rest_client.RestClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090027 api_version = "v3"
harika-vakadia92dd742013-02-19 20:41:22 +053028
29 def update_service(self, service_id, **kwargs):
Yaroslav Lobankov61db2d92015-11-11 16:51:23 +030030 """Updates a service.
31
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090032 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 Lobankov61db2d92015-11-11 16:51:23 +030035 """
36 patch_body = json.dumps({'service': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020037 resp, body = self.patch('services/%s' % service_id, patch_body)
David Kranze9d2f422014-07-02 13:57:41 -040038 self.expected_success(200, resp.status)
harika-vakadia92dd742013-02-19 20:41:22 +053039 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080040 return rest_client.ResponseBody(resp, body)
harika-vakadia92dd742013-02-19 20:41:22 +053041
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +000042 def show_service(self, service_id):
harika-vakadia92dd742013-02-19 20:41:22 +053043 """Get Service."""
44 url = 'services/%s' % service_id
45 resp, body = self.get(url)
David Kranze9d2f422014-07-02 13:57:41 -040046 self.expected_success(200, resp.status)
harika-vakadia92dd742013-02-19 20:41:22 +053047 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080048 return rest_client.ResponseBody(resp, body)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000049
Yaroslav Lobankov61db2d92015-11-11 16:51:23 +030050 def create_service(self, **kwargs):
51 """Creates a service.
52
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090053 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 Lobankov61db2d92015-11-11 16:51:23 +030056 """
57 body = json.dumps({'service': kwargs})
vponomaryovf4c27f92014-02-18 10:56:42 +020058 resp, body = self.post("services", body)
David Kranze9d2f422014-07-02 13:57:41 -040059 self.expected_success(201, resp.status)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000060 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080061 return rest_client.ResponseBody(resp, body)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000062
ghanshyamef301d82016-08-01 17:04:28 +090063 def delete_service(self, service_id):
64 url = "services/" + service_id
vponomaryovf4c27f92014-02-18 10:56:42 +020065 resp, body = self.delete(url)
David Kranze9d2f422014-07-02 13:57:41 -040066 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080067 return rest_client.ResponseBody(resp, body)
nayna-patel54b0fb52014-04-25 13:19:16 +000068
ghanshyamef301d82016-08-01 17:04:28 +090069 def list_services(self, **params):
70 """List services.
71
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090072 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
ghanshyamef301d82016-08-01 17:04:28 +090075 """
76 url = 'services'
77 if params:
78 url += '?%s' % urllib.urlencode(params)
Felipe Monteiro14570062017-05-31 13:25:14 +010079 resp, body = self.get(url)
nayna-patel54b0fb52014-04-25 13:19:16 +000080 self.expected_success(200, resp.status)
81 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080082 return rest_client.ResponseBody(resp, body)