blob: 09618adfdc0798c7db9f326b692f065dfd0cc3e8 [file] [log] [blame]
ghanshyam17193062016-06-24 10:36:54 +09001# 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
16from six.moves.urllib import parse as urllib
17
18from tempest.lib.common import rest_client
19
20
21class TenantsClient(rest_client.RestClient):
22 api_version = "v2.0"
23
24 def create_tenant(self, **kwargs):
25 """Create a tenant
26
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090027 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/v2-admin/index.html#create-tenant
ghanshyam17193062016-06-24 10:36:54 +090030 """
31 post_body = json.dumps({'tenant': kwargs})
32 resp, body = self.post('tenants', post_body)
33 self.expected_success(200, resp.status)
34 body = json.loads(body)
35 return rest_client.ResponseBody(resp, body)
36
37 def delete_tenant(self, tenant_id):
38 """Delete a tenant.
39
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090040 For a full list of available parameters, please refer to the official
41 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020042 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#delete-tenant
ghanshyam17193062016-06-24 10:36:54 +090043 """
44 resp, body = self.delete('tenants/%s' % str(tenant_id))
45 self.expected_success(204, resp.status)
46 return rest_client.ResponseBody(resp, body)
47
48 def show_tenant(self, tenant_id):
49 """Get tenant details.
50
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090051 For a full list of available parameters, please refer to the official
52 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020053 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#show-tenant-details-by-id
ghanshyam17193062016-06-24 10:36:54 +090054 """
55 resp, body = self.get('tenants/%s' % str(tenant_id))
56 self.expected_success(200, resp.status)
57 body = json.loads(body)
58 return rest_client.ResponseBody(resp, body)
59
60 def list_tenants(self, **params):
61 """Returns tenants.
62
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090063 For a full list of available parameters, please refer to the official
64 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020065 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#list-tenants-admin-endpoint
ghanshyam17193062016-06-24 10:36:54 +090066 """
67 url = 'tenants'
68 if params:
69 url += '?%s' % urllib.urlencode(params)
70 resp, body = self.get(url)
71 self.expected_success(200, resp.status)
72 body = json.loads(body)
73 return rest_client.ResponseBody(resp, body)
74
75 def update_tenant(self, tenant_id, **kwargs):
76 """Updates a tenant.
77
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090078 For a full list of available parameters, please refer to the official
79 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020080 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#update-tenant
ghanshyam17193062016-06-24 10:36:54 +090081 """
82 if 'id' not in kwargs:
83 kwargs['id'] = tenant_id
84 post_body = json.dumps({'tenant': kwargs})
85 resp, body = self.post('tenants/%s' % tenant_id, post_body)
86 self.expected_success(200, resp.status)
87 body = json.loads(body)
88 return rest_client.ResponseBody(resp, body)
89
90 def list_tenant_users(self, tenant_id, **params):
91 """List users for a Tenant.
92
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090093 For a full list of available parameters, please refer to the official
94 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020095 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#list-users-on-a-tenant
ghanshyam17193062016-06-24 10:36:54 +090096 """
97 url = '/tenants/%s/users' % tenant_id
98 if params:
99 url += '?%s' % urllib.urlencode(params)
100 resp, body = self.get(url)
101 self.expected_success(200, resp.status)
102 body = json.loads(body)
103 return rest_client.ResponseBody(resp, body)