PAPI: Fix PyLint errors
[csit.git] / resources / libraries / python / MacSwap.py
1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """Macswap sample_plugin util library"""
15
16 from resources.libraries.python.topology import NodeType, Topology
17 from resources.libraries.python.VatExecutor import VatExecutor
18
19 class MacSwap(object):
20     """Macswap sample plugin API"""
21
22     @staticmethod
23     def enable_disable_macswap_vat(node, interface):
24         """Enable/Disable macswap on interface.
25
26         Function can be used on a VPP node with macswap plugin.
27
28         :param node: Node where the interface is.
29         :param interface: Interface id.
30         :type node: dict
31         :type interface: str or int
32         :returns: nothing
33         """
34         if node['type'] == NodeType.DUT:
35             sw_if_index = Topology.get_interface_sw_index(node, interface)
36
37             VatExecutor.cmd_from_template(node, 'macswap.vat',
38                                           sw_if_index=sw_if_index)
39         else:
40             raise ValueError('Node {} has not DUT NodeType: "{}"'.
41                              format(node['host'], node['type']))
42
43     @staticmethod
44     def enable_disable_macswap_vat_exec(node, interface_name):
45         """Enable/Disable macswap on interface.
46
47         Function can be used on a VPP node with macswap plugin.
48
49         :param node: Node where the interface is.
50         :param interface_name: Interface name.
51         :type node: dict
52         :type interface_name: str or int
53         :returns: nothing
54         """
55         if node['type'] == NodeType.DUT:
56
57             VatExecutor.cmd_from_template(node, 'macswap_exec.vat',
58                                           if_name=interface_name)
59         else:
60             raise ValueError('Node {} has not DUT NodeType: "{}"'.
61                              format(node['host'], node['type']))