blob: 9244a4a2a6ee310751ee641edf2feab3e3d0edf7 [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
zhufl77618592020-11-17 15:41:20 +080019from tempest.lib.api_schema.response.compute.v2_70 import interfaces as \
20 schemav270
Matthew Treinish9e26ca82016-02-23 11:43:20 -050021from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090022from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050023
24
Ghanshyamee9af302016-02-25 06:12:43 +090025class InterfacesClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050026
zhufl77618592020-11-17 15:41:20 +080027 schema_versions_info = [
28 {'min': None, 'max': '2.69', 'schema': schema},
29 {'min': '2.70', 'max': None, 'schema': schemav270}]
30
Matthew Treinish9e26ca82016-02-23 11:43:20 -050031 def list_interfaces(self, server_id):
32 resp, body = self.get('servers/%s/os-interface' % server_id)
33 body = json.loads(body)
zhufl77618592020-11-17 15:41:20 +080034 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050035 self.validate_response(schema.list_interfaces, resp, body)
36 return rest_client.ResponseBody(resp, body)
37
38 def create_interface(self, server_id, **kwargs):
39 """Create an interface.
40
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090041 For a full list of available parameters, please refer to the official
42 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020043 https://docs.openstack.org/api-ref/compute/#create-interface
Matthew Treinish9e26ca82016-02-23 11:43:20 -050044 """
45 post_body = {'interfaceAttachment': kwargs}
46 post_body = json.dumps(post_body)
47 resp, body = self.post('servers/%s/os-interface' % server_id,
48 body=post_body)
49 body = json.loads(body)
zhufl77618592020-11-17 15:41:20 +080050 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050051 self.validate_response(schema.get_create_interfaces, resp, body)
52 return rest_client.ResponseBody(resp, body)
53
54 def show_interface(self, server_id, port_id):
55 resp, body = self.get('servers/%s/os-interface/%s' % (server_id,
56 port_id))
57 body = json.loads(body)
zhufl77618592020-11-17 15:41:20 +080058 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050059 self.validate_response(schema.get_create_interfaces, resp, body)
60 return rest_client.ResponseBody(resp, body)
61
62 def delete_interface(self, server_id, port_id):
63 resp, body = self.delete('servers/%s/os-interface/%s' % (server_id,
64 port_id))
65 self.validate_response(schema.delete_interface, resp, body)
66 return rest_client.ResponseBody(resp, body)