blob: d0d9ca1c111be496a239243be59dd3f7f2da4667 [file] [log] [blame]
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -04001# Copyright 2013 IBM Corp
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
Matthew Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040017
ghanshyamaa93b4b2015-03-20 11:03:44 +090018from tempest.api_schema.response.compute.v2_1 import fixed_ips as schema
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000019from tempest.common import service_client
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040020
21
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000022class FixedIPsClient(service_client.ServiceClient):
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040023
Ken'ichi Ohmichi5628f3f2015-05-22 20:17:56 +000024 def show_fixed_ip(self, fixed_ip):
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000025 url = "os-fixed-ips/%s" % fixed_ip
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040026 resp, body = self.get(url)
27 body = json.loads(body)
Rohan Kanade0fe20f72015-03-23 17:18:58 +053028 self.validate_response(schema.get_fixed_ip, resp, body)
David Kranze4e3b412015-02-10 10:50:42 -050029 return service_client.ResponseBody(resp, body['fixed_ip'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040030
Ken'ichi Ohmichi15895742015-07-17 05:34:36 +000031 def reserve_fixed_ip(self, fixed_ip, **kwargs):
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040032 """This reserves and unreserves fixed ips."""
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000033 url = "os-fixed-ips/%s/action" % fixed_ip
Ken'ichi Ohmichi15895742015-07-17 05:34:36 +000034 resp, body = self.post(url, json.dumps(kwargs))
Rohan Kanade0fe20f72015-03-23 17:18:58 +053035 self.validate_response(schema.reserve_fixed_ip, resp, body)
David Kranze4e3b412015-02-10 10:50:42 -050036 return service_client.ResponseBody(resp)