Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 1 | # 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 | |
| 16 | from oslo_serialization import jsonutils as json |
| 17 | from six.moves.urllib import parse as urllib |
| 18 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 19 | from tempest.lib.common import rest_client |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 20 | |
| 21 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 22 | class ProjectsClient(rest_client.RestClient): |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 23 | api_version = "v3" |
| 24 | |
| 25 | def create_project(self, name, **kwargs): |
Castulo J. Martinez | 43cee11 | 2016-05-11 09:16:37 -0700 | [diff] [blame] | 26 | """Create a Project. |
| 27 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 28 | For a full list of available parameters, please refer to the official |
| 29 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 30 | https://docs.openstack.org/api-ref/identity/v3/index.html#create-project |
Castulo J. Martinez | 43cee11 | 2016-05-11 09:16:37 -0700 | [diff] [blame] | 31 | |
| 32 | """ |
| 33 | # Include the project name to the kwargs parameters |
| 34 | kwargs['name'] = name |
| 35 | post_body = json.dumps({'project': kwargs}) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 36 | resp, body = self.post('projects', post_body) |
| 37 | self.expected_success(201, resp.status) |
| 38 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 39 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 40 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 48 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 49 | |
| 50 | def update_project(self, project_id, **kwargs): |
Castulo J. Martinez | 43cee11 | 2016-05-11 09:16:37 -0700 | [diff] [blame] | 51 | """Update a Project. |
| 52 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 53 | For a full list of available parameters, please refer to the official |
| 54 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 55 | https://docs.openstack.org/api-ref/identity/v3/index.html#update-project |
Castulo J. Martinez | 43cee11 | 2016-05-11 09:16:37 -0700 | [diff] [blame] | 56 | |
| 57 | """ |
| 58 | post_body = json.dumps({'project': kwargs}) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 59 | resp, body = self.patch('projects/%s' % project_id, post_body) |
| 60 | self.expected_success(200, resp.status) |
| 61 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 62 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 63 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 69 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 70 | |
| 71 | def delete_project(self, project_id): |
| 72 | """Delete a project.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 73 | resp, body = self.delete('projects/%s' % project_id) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 74 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 75 | return rest_client.ResponseBody(resp, body) |