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 | |
| 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 Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 35 | resp, body = self.post('projects', post_body) |
| 36 | self.expected_success(201, resp.status) |
| 37 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 38 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 39 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 47 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 48 | |
| 49 | def update_project(self, project_id, **kwargs): |
Castulo J. Martinez | 43cee11 | 2016-05-11 09:16:37 -0700 | [diff] [blame] | 50 | """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 Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 57 | resp, body = self.patch('projects/%s' % project_id, post_body) |
| 58 | self.expected_success(200, resp.status) |
| 59 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 60 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 61 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 67 | return rest_client.ResponseBody(resp, body) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 68 | |
| 69 | def delete_project(self, project_id): |
| 70 | """Delete a project.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 71 | resp, body = self.delete('projects/%s' % project_id) |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 72 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 73 | return rest_client.ResponseBody(resp, body) |