Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 1 | # 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 Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 16 | from oslo_serialization import jsonutils as json |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 17 | |
ghanshyam | aa93b4b | 2015-03-20 11:03:44 +0900 | [diff] [blame] | 18 | from tempest.api_schema.response.compute.v2_1 import interfaces as schema |
ghanshyam | 274327a | 2015-03-23 10:29:45 +0900 | [diff] [blame] | 19 | from tempest.api_schema.response.compute.v2_1 import servers as servers_schema |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 20 | from tempest.common import service_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 21 | |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 22 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 23 | class InterfacesClient(service_client.ServiceClient): |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 24 | |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 25 | def list_interfaces(self, server_id): |
| 26 | resp, body = self.get('servers/%s/os-interface' % server_id) |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 27 | body = json.loads(body) |
Yuiko Takada | 9e118bd | 2014-03-27 10:54:13 +0000 | [diff] [blame] | 28 | self.validate_response(schema.list_interfaces, resp, body) |
ghanshyam | a2364f1 | 2015-08-24 15:45:37 +0900 | [diff] [blame] | 29 | return service_client.ResponseBody(resp, body) |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 30 | |
Ken'ichi Ohmichi | 12e76a1 | 2015-07-17 10:11:23 +0000 | [diff] [blame] | 31 | def create_interface(self, server_id, **kwargs): |
| 32 | post_body = {'interfaceAttachment': kwargs} |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 33 | post_body = json.dumps(post_body) |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 34 | resp, body = self.post('servers/%s/os-interface' % server_id, |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 35 | body=post_body) |
| 36 | body = json.loads(body) |
ghanshyam | c4559e5 | 2015-03-20 11:58:44 +0900 | [diff] [blame] | 37 | self.validate_response(schema.get_create_interfaces, resp, body) |
ghanshyam | a2364f1 | 2015-08-24 15:45:37 +0900 | [diff] [blame] | 38 | return service_client.ResponseBody(resp, body) |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 39 | |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 40 | def show_interface(self, server_id, port_id): |
| 41 | resp, body = self.get('servers/%s/os-interface/%s' % (server_id, |
| 42 | port_id)) |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 43 | body = json.loads(body) |
ghanshyam | c4559e5 | 2015-03-20 11:58:44 +0900 | [diff] [blame] | 44 | self.validate_response(schema.get_create_interfaces, resp, body) |
ghanshyam | a2364f1 | 2015-08-24 15:45:37 +0900 | [diff] [blame] | 45 | return service_client.ResponseBody(resp, body) |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 46 | |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 47 | def delete_interface(self, server_id, port_id): |
| 48 | resp, body = self.delete('servers/%s/os-interface/%s' % (server_id, |
Dan Smith | 8ad1c47 | 2013-02-26 13:03:16 -0500 | [diff] [blame] | 49 | port_id)) |
ghanshyam | c4559e5 | 2015-03-20 11:58:44 +0900 | [diff] [blame] | 50 | self.validate_response(schema.delete_interface, resp, body) |
David Kranz | b2b0c18 | 2015-02-18 13:28:19 -0500 | [diff] [blame] | 51 | return service_client.ResponseBody(resp, body) |
Leo Toyoda | ba9e909 | 2013-04-08 09:02:11 +0900 | [diff] [blame] | 52 | |
Ken'ichi Ohmichi | 12e76a1 | 2015-07-17 10:11:23 +0000 | [diff] [blame] | 53 | def add_fixed_ip(self, server_id, **kwargs): |
Ghanshyam Mann | 6e855d1 | 2014-02-26 13:31:56 +0900 | [diff] [blame] | 54 | """Add a fixed IP to input server instance.""" |
Ken'ichi Ohmichi | 12e76a1 | 2015-07-17 10:11:23 +0000 | [diff] [blame] | 55 | post_body = json.dumps({'addFixedIp': kwargs}) |
Ken'ichi Ohmichi | cd6e899 | 2015-07-01 06:45:34 +0000 | [diff] [blame] | 56 | resp, body = self.post('servers/%s/action' % server_id, |
Ghanshyam Mann | 6e855d1 | 2014-02-26 13:31:56 +0900 | [diff] [blame] | 57 | post_body) |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 58 | self.validate_response(servers_schema.server_actions_common_schema, |
| 59 | resp, body) |
David Kranz | b2b0c18 | 2015-02-18 13:28:19 -0500 | [diff] [blame] | 60 | return service_client.ResponseBody(resp, body) |
Ghanshyam Mann | 6e855d1 | 2014-02-26 13:31:56 +0900 | [diff] [blame] | 61 | |
Ken'ichi Ohmichi | 12e76a1 | 2015-07-17 10:11:23 +0000 | [diff] [blame] | 62 | def remove_fixed_ip(self, server_id, **kwargs): |
Ghanshyam Mann | 6e855d1 | 2014-02-26 13:31:56 +0900 | [diff] [blame] | 63 | """Remove input fixed IP from input server instance.""" |
Ken'ichi Ohmichi | 12e76a1 | 2015-07-17 10:11:23 +0000 | [diff] [blame] | 64 | post_body = json.dumps({'removeFixedIp': kwargs}) |
Ken'ichi Ohmichi | cd6e899 | 2015-07-01 06:45:34 +0000 | [diff] [blame] | 65 | resp, body = self.post('servers/%s/action' % server_id, |
Ghanshyam Mann | 6e855d1 | 2014-02-26 13:31:56 +0900 | [diff] [blame] | 66 | post_body) |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 67 | self.validate_response(servers_schema.server_actions_common_schema, |
| 68 | resp, body) |
David Kranz | b2b0c18 | 2015-02-18 13:28:19 -0500 | [diff] [blame] | 69 | return service_client.ResponseBody(resp, body) |