blob: c437c0870ba67b5ba88635d330b3c73b8a227014 [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)
David Kranzb2b0c182015-02-18 13:28:19 -050029 return service_client.ResponseBodyList(resp,
30 body['interfaceAttachments'])
Dan Smith8ad1c472013-02-26 13:03:16 -050031
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000032 def create_interface(self, server_id, **kwargs):
33 post_body = {'interfaceAttachment': kwargs}
Dan Smith8ad1c472013-02-26 13:03:16 -050034 post_body = json.dumps(post_body)
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000035 resp, body = self.post('servers/%s/os-interface' % server_id,
Dan Smith8ad1c472013-02-26 13:03:16 -050036 body=post_body)
37 body = json.loads(body)
ghanshyamc4559e52015-03-20 11:58:44 +090038 self.validate_response(schema.get_create_interfaces, resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050039 return service_client.ResponseBody(resp, body['interfaceAttachment'])
Dan Smith8ad1c472013-02-26 13:03:16 -050040
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000041 def show_interface(self, server_id, port_id):
42 resp, body = self.get('servers/%s/os-interface/%s' % (server_id,
43 port_id))
Dan Smith8ad1c472013-02-26 13:03:16 -050044 body = json.loads(body)
ghanshyamc4559e52015-03-20 11:58:44 +090045 self.validate_response(schema.get_create_interfaces, resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050046 return service_client.ResponseBody(resp, body['interfaceAttachment'])
Dan Smith8ad1c472013-02-26 13:03:16 -050047
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000048 def delete_interface(self, server_id, port_id):
49 resp, body = self.delete('servers/%s/os-interface/%s' % (server_id,
Dan Smith8ad1c472013-02-26 13:03:16 -050050 port_id))
ghanshyamc4559e52015-03-20 11:58:44 +090051 self.validate_response(schema.delete_interface, resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050052 return service_client.ResponseBody(resp, body)
Leo Toyodaba9e9092013-04-08 09:02:11 +090053
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000054 def add_fixed_ip(self, server_id, **kwargs):
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090055 """Add a fixed IP to input server instance."""
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000056 post_body = json.dumps({'addFixedIp': kwargs})
Ken'ichi Ohmichicd6e8992015-07-01 06:45:34 +000057 resp, body = self.post('servers/%s/action' % server_id,
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090058 post_body)
Ghanshyam997c9092014-04-03 19:00:20 +090059 self.validate_response(servers_schema.server_actions_common_schema,
60 resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050061 return service_client.ResponseBody(resp, body)
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090062
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000063 def remove_fixed_ip(self, server_id, **kwargs):
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090064 """Remove input fixed IP from input server instance."""
Ken'ichi Ohmichi12e76a12015-07-17 10:11:23 +000065 post_body = json.dumps({'removeFixedIp': kwargs})
Ken'ichi Ohmichicd6e8992015-07-01 06:45:34 +000066 resp, body = self.post('servers/%s/action' % server_id,
Ghanshyam Mann6e855d12014-02-26 13:31:56 +090067 post_body)
Ghanshyam997c9092014-04-03 19:00:20 +090068 self.validate_response(servers_schema.server_actions_common_schema,
69 resp, body)
David Kranzb2b0c182015-02-18 13:28:19 -050070 return service_client.ResponseBody(resp, body)