blob: d129a0a7dab909b23cd6e54c6795b6a9f135dfa6 [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
24 def create_domain(self, name, **kwargs):
25 """Creates a domain."""
26 description = kwargs.get('description', None)
27 en = kwargs.get('enabled', True)
28 post_body = {
29 'description': description,
30 'enabled': en,
31 'name': name
32 }
33 post_body = json.dumps({'domain': post_body})
34 resp, body = self.post('domains', post_body)
35 self.expected_success(201, resp.status)
36 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080037 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000038
39 def delete_domain(self, domain_id):
40 """Deletes a domain."""
41 resp, body = self.delete('domains/%s' % str(domain_id))
42 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080043 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000044
45 def list_domains(self, params=None):
46 """List Domains."""
47 url = 'domains'
48 if params:
49 url += '?%s' % urllib.urlencode(params)
50 resp, body = self.get(url)
51 self.expected_success(200, resp.status)
52 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080053 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000054
55 def update_domain(self, domain_id, **kwargs):
56 """Updates a domain."""
57 body = self.show_domain(domain_id)['domain']
58 description = kwargs.get('description', body['description'])
59 en = kwargs.get('enabled', body['enabled'])
60 name = kwargs.get('name', body['name'])
61 post_body = {
62 'description': description,
63 'enabled': en,
64 'name': name
65 }
66 post_body = json.dumps({'domain': post_body})
67 resp, body = self.patch('domains/%s' % domain_id, post_body)
68 self.expected_success(200, resp.status)
69 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080070 return rest_client.ResponseBody(resp, body)
Daniel Mellado91a26b62016-02-11 11:13:04 +000071
72 def show_domain(self, domain_id):
73 """Get Domain details."""
74 resp, body = self.get('domains/%s' % domain_id)
75 self.expected_success(200, resp.status)
76 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080077 return rest_client.ResponseBody(resp, body)