blob: 33c754adda7601c38693a84d0f0e15f2cc512491 [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 Ohmichid35a1332016-03-02 10:38:07 -080023from tempest.lib.common import rest_client
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000024
25
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080026class RegionsClient(rest_client.RestClient):
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
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090032 For a full list of available parameters, please refer to the official
33 API reference:
34 http://developer.openstack.org/api-ref/identity/v3/index.html#create-region
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030035 """
36 if region_id is not None:
37 method = self.put
38 url = 'regions/%s' % region_id
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000039 else:
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030040 method = self.post
41 url = 'regions'
42 req_body = json.dumps({'region': kwargs})
43 resp, body = method(url, req_body)
David Kranz2aaf5312014-08-29 09:22:10 -040044 self.expected_success(201, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000045 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080046 return rest_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000047
48 def update_region(self, region_id, **kwargs):
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030049 """Updates a region.
50
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090051 For a full list of available parameters, please refer to the official
52 API reference:
53 http://developer.openstack.org/api-ref/identity/v3/index.html#update-region
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030054 """
55 post_body = json.dumps({'region': kwargs})
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000056 resp, body = self.patch('regions/%s' % region_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040057 self.expected_success(200, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000058 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080059 return rest_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000060
lei zhangcc5a0f82015-11-28 23:55:23 +080061 def show_region(self, region_id):
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000062 """Get region."""
63 url = 'regions/%s' % region_id
64 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040065 self.expected_success(200, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000066 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080067 return rest_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000068
69 def list_regions(self, params=None):
70 """List regions."""
71 url = 'regions'
72 if params:
73 url += '?%s' % urllib.urlencode(params)
74 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040075 self.expected_success(200, resp.status)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000076 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080077 return rest_client.ResponseBody(resp, body)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000078
79 def delete_region(self, region_id):
80 """Delete region."""
81 resp, body = self.delete('regions/%s' % region_id)
David Kranz2aaf5312014-08-29 09:22:10 -040082 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080083 return rest_client.ResponseBody(resp, body)