blob: 2e66082274fed2030746dbea7dfc26e928ef1944 [file] [log] [blame]
Dan Smith8ad1c472013-02-26 13:03:16 -05001# 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
Dan Smith8ad1c472013-02-26 13:03:16 -050017
ghanshyamaa93b4b2015-03-20 11:03:44 +090018from tempest.api_schema.response.compute.v2_1 import interfaces as schema
ghanshyam274327a2015-03-23 10:29:45 +090019from tempest.api_schema.response.compute.v2_1 import servers as servers_schema
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000020from tempest.common import service_client
Matthew Treinish684d8992014-01-30 16:27:40 +000021
Dan Smith8ad1c472013-02-26 13:03:16 -050022
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000023class InterfacesClient(service_client.ServiceClient):
Dan Smith8ad1c472013-02-26 13:03:16 -050024
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000025 def list_interfaces(self, server_id):
26 resp, body = self.get('servers/%s/os-interface' % server_id)
Dan Smith8ad1c472013-02-26 13:03:16 -050027 body = json.loads(body)
Yuiko Takada9e118bd2014-03-27 10:54:13 +000028 self.validate_response(schema.list_interfaces, resp, body)
ghanshyama2364f12015-08-24 15:45:37 +090029 return service_client.ResponseBody(resp, body)
Dan Smith8ad1c472013-02-26 13:03:16 -050030
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000031 def create_interface(self, server_id, **kwargs):
32 post_body = {'interfaceAttachment': kwargs}
Dan Smith8ad1c472013-02-26 13:03:16 -050033 post_body = json.dumps(post_body)
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000034 resp, body = self.post('servers/%s/os-interface' % server_id,
Dan Smith8ad1c472013-02-26 13:03:16 -050035 body=post_body)
36 body = json.loads(body)
ghanshyamc4559e52015-03-20 11:58:44 +090037 self.validate_response(schema.get_create_interfaces, resp, body)
ghanshyama2364f12015-08-24 15:45:37 +090038 return service_client.ResponseBody(resp, body)
Dan Smith8ad1c472013-02-26 13:03:16 -050039
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000040 def show_interface(self, server_id, port_id):
41 resp, body = self.get('servers/%s/os-interface/%s' % (server_id,
42 port_id))
Dan Smith8ad1c472013-02-26 13:03:16 -050043 body = json.loads(body)
ghanshyamc4559e52015-03-20 11:58:44 +090044 self.validate_response(schema.get_create_interfaces, resp, body)
ghanshyama2364f12015-08-24 15:45:37 +090045 return service_client.ResponseBody(resp, body)
Dan Smith8ad1c472013-02-26 13:03:16 -050046
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000047 def delete_interface(self, server_id, port_id):
48 resp, body = self.delete('servers/%s/os-interface/%s' % (server_id,
Dan Smith8ad1c472013-02-26 13:03:16 -050049 port_id))
ghanshyamc4559e52015-03-20 11:58:44 +090050 self.validate_response(schema.delete_interface, resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050051 return service_client.ResponseBody(resp, body)
Leo Toyodaba9e9092013-04-08 09:02:11 +090052
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000053 def add_fixed_ip(self, server_id, **kwargs):
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090054 """Add a fixed IP to input server instance."""
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000055 post_body = json.dumps({'addFixedIp': kwargs})
Ken'ichi Ohmichicd6e8992015-07-01 06:45:34 +000056 resp, body = self.post('servers/%s/action' % server_id,
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090057 post_body)
Ghanshyam997c9092014-04-03 19:00:20 +090058 self.validate_response(servers_schema.server_actions_common_schema,
59 resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050060 return service_client.ResponseBody(resp, body)
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090061
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000062 def remove_fixed_ip(self, server_id, **kwargs):
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090063 """Remove input fixed IP from input server instance."""
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000064 post_body = json.dumps({'removeFixedIp': kwargs})
Ken'ichi Ohmichicd6e8992015-07-01 06:45:34 +000065 resp, body = self.post('servers/%s/action' % server_id,
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090066 post_body)
Ghanshyam997c9092014-04-03 19:00:20 +090067 self.validate_response(servers_schema.server_actions_common_schema,
68 resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050069 return service_client.ResponseBody(resp, body)