blob: ce2f38d991ecdba0696c5bf246d0fdba8775a5bf [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
28 Available params: see http://developer.openstack.org/
29 api-ref-identity-v3.html#createProject
30
31 """
32 # Include the project name to the kwargs parameters
33 kwargs['name'] = name
34 post_body = json.dumps({'project': kwargs})
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060035 resp, body = self.post('projects', post_body)
36 self.expected_success(201, resp.status)
37 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080038 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060039
40 def list_projects(self, params=None):
41 url = "projects"
42 if params:
43 url += '?%s' % urllib.urlencode(params)
44 resp, body = self.get(url)
45 self.expected_success(200, resp.status)
46 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080047 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060048
49 def update_project(self, project_id, **kwargs):
Castulo J. Martinez43cee112016-05-11 09:16:37 -070050 """Update a Project.
51
52 Available params: see http://developer.openstack.org/
53 api-ref-identity-v3.html#updateProject
54
55 """
56 post_body = json.dumps({'project': kwargs})
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060057 resp, body = self.patch('projects/%s' % project_id, post_body)
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)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060061
62 def show_project(self, project_id):
63 """GET a Project."""
64 resp, body = self.get("projects/%s" % project_id)
65 self.expected_success(200, resp.status)
66 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080067 return rest_client.ResponseBody(resp, body)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060068
69 def delete_project(self, project_id):
70 """Delete a project."""
guo yunxian6cdf0562016-08-17 16:21:52 +080071 resp, body = self.delete('projects/%s' % project_id)
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060072 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080073 return rest_client.ResponseBody(resp, body)