blob: 6ccdc314ed7a8ae29b38d1b425fad54679a47ec8 [file] [log] [blame]
ravikumar-venkatesanacf99d72014-07-09 14:58:25 +00001# Copyright 2014 Hewlett-Packard Development Company, L.P
ravikumar-venkatesan3052e942014-05-12 18:25:17 +00002# 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 Lobankov1a67f7b2015-11-11 16:27:15 +030016"""
17http://developer.openstack.org/api-ref-identity-v3.html#regions-v3
18"""
19
Matthew Treinish21905512015-07-13 10:33:35 -040020from oslo_serialization import jsonutils as json
Matthew Treinish89128142015-04-23 10:44:30 -040021from six.moves.urllib import parse as urllib
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000022
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000023from tempest.common import service_client
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000024
25
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000026class RegionClient(service_client.ServiceClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090027 api_version = "v3"
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000028
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030029 def create_region(self, region_id=None, **kwargs):
30 """Create region.
31
32 Available params: see http://developer.openstack.org/
33 api-ref-identity-v3.html#createRegion
34
35 see http://developer.openstack.org/
36 api-ref-identity-v3.html#createRegionWithID
37 """
38 if region_id is not None:
39 method = self.put
40 url = 'regions/%s' % region_id
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000041 else:
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030042 method = self.post
43 url = 'regions'
44 req_body = json.dumps({'region': kwargs})
45 resp, body = method(url, req_body)
David Kranz2aaf5312014-08-29 09:22:10 -040046 self.expected_success(201, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000047 body = json.loads(body)
John Warrenc3e50142015-08-13 13:31:56 +000048 return service_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000049
50 def update_region(self, region_id, **kwargs):
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030051 """Updates a region.
52
53 Available params: see http://developer.openstack.org/
54 api-ref-identity-v3.html#updateRegion
55 """
56 post_body = json.dumps({'region': kwargs})
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000057 resp, body = self.patch('regions/%s' % region_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040058 self.expected_success(200, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000059 body = json.loads(body)
John Warrenc3e50142015-08-13 13:31:56 +000060 return service_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000061
62 def get_region(self, region_id):
63 """Get region."""
64 url = 'regions/%s' % region_id
65 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040066 self.expected_success(200, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000067 body = json.loads(body)
John Warrenc3e50142015-08-13 13:31:56 +000068 return service_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000069
70 def list_regions(self, params=None):
71 """List regions."""
72 url = 'regions'
73 if params:
74 url += '?%s' % urllib.urlencode(params)
75 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040076 self.expected_success(200, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000077 body = json.loads(body)
John Warrenc3e50142015-08-13 13:31:56 +000078 return service_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000079
80 def delete_region(self, region_id):
81 """Delete region."""
82 resp, body = self.delete('regions/%s' % region_id)
David Kranz2aaf5312014-08-29 09:22:10 -040083 self.expected_success(204, resp.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000084 return service_client.ResponseBody(resp, body)