harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [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 | |
Yaroslav Lobankov | 5918c45 | 2015-11-11 16:03:12 +0300 | [diff] [blame] | 16 | """ |
| 17 | http://developer.openstack.org/api-ref-identity-v3.html#policies-v3 |
| 18 | """ |
| 19 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 20 | from oslo_serialization import jsonutils as json |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 21 | |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 22 | from tempest.common import service_client |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 23 | |
| 24 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 25 | class PolicyClient(service_client.ServiceClient): |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 26 | api_version = "v3" |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 27 | |
Yaroslav Lobankov | 5918c45 | 2015-11-11 16:03:12 +0300 | [diff] [blame] | 28 | 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 Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 35 | resp, body = self.post('policies', post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 36 | self.expected_success(201, resp.status) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 37 | body = json.loads(body) |
John Warren | 7d31472 | 2015-08-13 13:15:11 +0000 | [diff] [blame] | 38 | return service_client.ResponseBody(resp, body) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 39 | |
| 40 | def list_policies(self): |
| 41 | """Lists the policies.""" |
| 42 | resp, body = self.get('policies') |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 43 | self.expected_success(200, resp.status) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 44 | body = json.loads(body) |
John Warren | 7d31472 | 2015-08-13 13:15:11 +0000 | [diff] [blame] | 45 | return service_client.ResponseBody(resp, body) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 46 | |
| 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 Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 51 | self.expected_success(200, resp.status) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 52 | body = json.loads(body) |
John Warren | 7d31472 | 2015-08-13 13:15:11 +0000 | [diff] [blame] | 53 | return service_client.ResponseBody(resp, body) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 54 | |
| 55 | def update_policy(self, policy_id, **kwargs): |
Yaroslav Lobankov | 5918c45 | 2015-11-11 16:03:12 +0300 | [diff] [blame] | 56 | """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-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 62 | url = 'policies/%s' % policy_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 63 | resp, body = self.patch(url, post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 64 | self.expected_success(200, resp.status) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 65 | body = json.loads(body) |
John Warren | 7d31472 | 2015-08-13 13:15:11 +0000 | [diff] [blame] | 66 | return service_client.ResponseBody(resp, body) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 67 | |
| 68 | def delete_policy(self, policy_id): |
| 69 | """Deletes the policy.""" |
| 70 | url = "policies/%s" % policy_id |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 71 | resp, body = self.delete(url) |
| 72 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 73 | return service_client.ResponseBody(resp, body) |