blob: bd32cfc8e7de751ffda18a68c20d6448e78f51e3 [file] [log] [blame]
Daniel Mellado91a26b62016-02-11 11:13:04 +00001# Copyright 2016 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
16from six.moves.urllib import parse as urllib
17
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080018from tempest.lib.common import rest_client
Daniel Mellado91a26b62016-02-11 11:13:04 +000019
20
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080021class DomainsClient(rest_client.RestClient):
Daniel Mellado91a26b62016-02-11 11:13:04 +000022 api_version = "v3"
23
ghanshyam8af17d62016-08-01 16:19:42 +090024 def create_domain(self, **kwargs):
25 """Creates a domain.
26
27 For a full list of available parameters, please refer to the official
28 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020029 https://docs.openstack.org/api-ref/identity/v3/index.html#create-domain
ghanshyam8af17d62016-08-01 16:19:42 +090030 """
31 post_body = json.dumps({'domain': kwargs})
Daniel Mellado91a26b62016-02-11 11:13:04 +000032 resp, body = self.post('domains', post_body)
33 self.expected_success(201, resp.status)
34 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080035 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000036
37 def delete_domain(self, domain_id):
ghanshyam8af17d62016-08-01 16:19:42 +090038 """Deletes a domain.
39
40 For APi details, please refer to the official API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020041 https://docs.openstack.org/api-ref/identity/v3/index.html#delete-domain
ghanshyam8af17d62016-08-01 16:19:42 +090042 """
guo yunxian6cdf0562016-08-17 16:21:52 +080043 resp, body = self.delete('domains/%s' % domain_id)
Daniel Mellado91a26b62016-02-11 11:13:04 +000044 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080045 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000046
ghanshyam8af17d62016-08-01 16:19:42 +090047 def list_domains(self, **params):
48 """List Domains.
49
50 For a full list of available parameters, please refer to the official
51 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020052 https://docs.openstack.org/api-ref/identity/v3/index.html#list-domains
ghanshyam8af17d62016-08-01 16:19:42 +090053 """
Daniel Mellado91a26b62016-02-11 11:13:04 +000054 url = 'domains'
55 if params:
56 url += '?%s' % urllib.urlencode(params)
57 resp, body = self.get(url)
58 self.expected_success(200, resp.status)
59 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080060 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000061
62 def update_domain(self, domain_id, **kwargs):
ghanshyam8af17d62016-08-01 16:19:42 +090063 """Updates a domain.
64
65 For a full list of available parameters, please refer to the official
66 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020067 https://docs.openstack.org/api-ref/identity/v3/index.html#update-domain
ghanshyam8af17d62016-08-01 16:19:42 +090068 """
69 post_body = json.dumps({'domain': kwargs})
Daniel Mellado91a26b62016-02-11 11:13:04 +000070 resp, body = self.patch('domains/%s' % domain_id, post_body)
71 self.expected_success(200, resp.status)
72 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080073 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000074
75 def show_domain(self, domain_id):
ghanshyam8af17d62016-08-01 16:19:42 +090076 """Get Domain details.
77
78 For API details, please refer to the official API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020079 https://docs.openstack.org/api-ref/identity/v3/index.html#show-domain-details
ghanshyam8af17d62016-08-01 16:19:42 +090080 """
Daniel Mellado91a26b62016-02-11 11:13:04 +000081 resp, body = self.get('domains/%s' % domain_id)
82 self.expected_success(200, resp.status)
83 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080084 return rest_client.ResponseBody(resp, body)