blob: b186fba3225d7a591352ec0a685f8c7a339546b0 [file] [log] [blame]
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -06001# 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
16from oslo_serialization import jsonutils as json
17from six.moves.urllib import parse as urllib
18
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080019from tempest.lib.common import rest_client
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060020
21
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080022class ProjectsClient(rest_client.RestClient):
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060023 api_version = "v3"
24
25 def create_project(self, name, **kwargs):
Castulo J. Martinez43cee112016-05-11 09:16:37 -070026 """Create a Project.
27
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090028 For a full list of available parameters, please refer to the official
29 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020030 https://docs.openstack.org/api-ref/identity/v3/index.html#create-project
Castulo J. Martinez43cee112016-05-11 09:16:37 -070031
32 """
33 # Include the project name to the kwargs parameters
34 kwargs['name'] = name
35 post_body = json.dumps({'project': kwargs})
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060036 resp, body = self.post('projects', post_body)
37 self.expected_success(201, resp.status)
38 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080039 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060040
41 def list_projects(self, params=None):
42 url = "projects"
43 if params:
44 url += '?%s' % urllib.urlencode(params)
45 resp, body = self.get(url)
46 self.expected_success(200, resp.status)
47 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080048 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060049
50 def update_project(self, project_id, **kwargs):
Castulo J. Martinez43cee112016-05-11 09:16:37 -070051 """Update a Project.
52
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090053 For a full list of available parameters, please refer to the official
54 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020055 https://docs.openstack.org/api-ref/identity/v3/index.html#update-project
Castulo J. Martinez43cee112016-05-11 09:16:37 -070056
57 """
58 post_body = json.dumps({'project': kwargs})
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060059 resp, body = self.patch('projects/%s' % project_id, post_body)
60 self.expected_success(200, resp.status)
61 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080062 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060063
64 def show_project(self, project_id):
65 """GET a Project."""
66 resp, body = self.get("projects/%s" % project_id)
67 self.expected_success(200, resp.status)
68 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080069 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060070
71 def delete_project(self, project_id):
72 """Delete a project."""
guo yunxian6cdf0562016-08-17 16:21:52 +080073 resp, body = self.delete('projects/%s' % project_id)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060074 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080075 return rest_client.ResponseBody(resp, body)