blob: 80192a1e02f2dbf213ec3ca4e50f6017b64d5cef [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -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
16from oslo_serialization import jsonutils as json
17
18from tempest.lib.api_schema.response.compute.v2_1 import interfaces as schema
19from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090020from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050021
22
Ghanshyamee9af302016-02-25 06:12:43 +090023class InterfacesClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050024
25 def list_interfaces(self, server_id):
26 resp, body = self.get('servers/%s/os-interface' % server_id)
27 body = json.loads(body)
28 self.validate_response(schema.list_interfaces, resp, body)
29 return rest_client.ResponseBody(resp, body)
30
31 def create_interface(self, server_id, **kwargs):
32 """Create an interface.
33
34 Available params: see http://developer.openstack.org/
35 api-ref-compute-v2.1.html#createAttachInterface
36 """
37 post_body = {'interfaceAttachment': kwargs}
38 post_body = json.dumps(post_body)
39 resp, body = self.post('servers/%s/os-interface' % server_id,
40 body=post_body)
41 body = json.loads(body)
42 self.validate_response(schema.get_create_interfaces, resp, body)
43 return rest_client.ResponseBody(resp, body)
44
45 def show_interface(self, server_id, port_id):
46 resp, body = self.get('servers/%s/os-interface/%s' % (server_id,
47 port_id))
48 body = json.loads(body)
49 self.validate_response(schema.get_create_interfaces, resp, body)
50 return rest_client.ResponseBody(resp, body)
51
52 def delete_interface(self, server_id, port_id):
53 resp, body = self.delete('servers/%s/os-interface/%s' % (server_id,
54 port_id))
55 self.validate_response(schema.delete_interface, resp, body)
56 return rest_client.ResponseBody(resp, body)