blob: 2fa822fed325f2293f30ae19c755a18daf55f9df [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
19from tempest.common import service_client
20
21
22class ProjectsClient(service_client.ServiceClient):
23 api_version = "v3"
24
25 def create_project(self, name, **kwargs):
26 """Creates a project."""
27 description = kwargs.get('description', None)
28 en = kwargs.get('enabled', True)
29 domain_id = kwargs.get('domain_id', 'default')
30 post_body = {
31 'description': description,
32 'domain_id': domain_id,
33 'enabled': en,
34 'name': name
35 }
36 post_body = json.dumps({'project': post_body})
37 resp, body = self.post('projects', post_body)
38 self.expected_success(201, resp.status)
39 body = json.loads(body)
40 return service_client.ResponseBody(resp, body)
41
42 def list_projects(self, params=None):
43 url = "projects"
44 if params:
45 url += '?%s' % urllib.urlencode(params)
46 resp, body = self.get(url)
47 self.expected_success(200, resp.status)
48 body = json.loads(body)
49 return service_client.ResponseBody(resp, body)
50
51 def update_project(self, project_id, **kwargs):
52 body = self.show_project(project_id)['project']
53 name = kwargs.get('name', body['name'])
54 desc = kwargs.get('description', body['description'])
55 en = kwargs.get('enabled', body['enabled'])
56 domain_id = kwargs.get('domain_id', body['domain_id'])
57 post_body = {
58 'id': project_id,
59 'name': name,
60 'description': desc,
61 'enabled': en,
62 'domain_id': domain_id,
63 }
64 post_body = json.dumps({'project': post_body})
65 resp, body = self.patch('projects/%s' % project_id, post_body)
66 self.expected_success(200, resp.status)
67 body = json.loads(body)
68 return service_client.ResponseBody(resp, body)
69
70 def show_project(self, project_id):
71 """GET a Project."""
72 resp, body = self.get("projects/%s" % project_id)
73 self.expected_success(200, resp.status)
74 body = json.loads(body)
75 return service_client.ResponseBody(resp, body)
76
77 def delete_project(self, project_id):
78 """Delete a project."""
79 resp, body = self.delete('projects/%s' % str(project_id))
80 self.expected_success(204, resp.status)
81 return service_client.ResponseBody(resp, body)