blob: ecc9df70a97c7eb9ca9d6c8c867739fc417396d6 [file] [log] [blame]
harika-vakadi40e10112013-02-08 14:38:09 +05301# 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
Yaroslav Lobankov5918c452015-11-11 16:03:12 +030016"""
17http://developer.openstack.org/api-ref-identity-v3.html#policies-v3
18"""
19
Matthew Treinish21905512015-07-13 10:33:35 -040020from oslo_serialization import jsonutils as json
harika-vakadi40e10112013-02-08 14:38:09 +053021
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000022from tempest.common import service_client
harika-vakadi40e10112013-02-08 14:38:09 +053023
24
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000025class PolicyClient(service_client.ServiceClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090026 api_version = "v3"
harika-vakadi40e10112013-02-08 14:38:09 +053027
Yaroslav Lobankov5918c452015-11-11 16:03:12 +030028 def create_policy(self, **kwargs):
29 """Creates a Policy.
30
31 Available params: see http://developer.openstack.org/
32 api-ref-identity-v3.html#createPolicy
33 """
34 post_body = json.dumps({'policy': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020035 resp, body = self.post('policies', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040036 self.expected_success(201, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053037 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000038 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053039
40 def list_policies(self):
41 """Lists the policies."""
42 resp, body = self.get('policies')
David Kranz2aaf5312014-08-29 09:22:10 -040043 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053044 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000045 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053046
47 def get_policy(self, policy_id):
48 """Lists out the given policy."""
49 url = 'policies/%s' % policy_id
50 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040051 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053052 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000053 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053054
55 def update_policy(self, policy_id, **kwargs):
Yaroslav Lobankov5918c452015-11-11 16:03:12 +030056 """Updates a policy.
57
58 Available params: see http://developer.openstack.org/
59 api-ref-identity-v3.html#updatePolicy
60 """
61 post_body = json.dumps({'policy': kwargs})
harika-vakadi40e10112013-02-08 14:38:09 +053062 url = 'policies/%s' % policy_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020063 resp, body = self.patch(url, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040064 self.expected_success(200, resp.status)
harika-vakadi40e10112013-02-08 14:38:09 +053065 body = json.loads(body)
John Warren7d314722015-08-13 13:15:11 +000066 return service_client.ResponseBody(resp, body)
harika-vakadi40e10112013-02-08 14:38:09 +053067
68 def delete_policy(self, policy_id):
69 """Deletes the policy."""
70 url = "policies/%s" % policy_id
David Kranz2aaf5312014-08-29 09:22:10 -040071 resp, body = self.delete(url)
72 self.expected_success(204, resp.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000073 return service_client.ResponseBody(resp, body)