diff options
author | Tibor Frank <tifrank@cisco.com> | 2016-05-12 14:23:29 +0200 |
---|---|---|
committer | Matej Klotton <mklotton@cisco.com> | 2016-05-13 16:19:20 +0000 |
commit | b4afd218f10c9202b104327c8eff5401c7e73aaf (patch) | |
tree | 6a59ca427e037e9159bbd9db89ca746d37a83d42 /resources/libraries | |
parent | 981bc57e281bc2f6920f7690eccc3106419474d2 (diff) |
Add keyword to manipulate interface TAP parameters
JIRA: CSIT-69
- add a keyword to be able to:
- configure all TAP parameters at once
- configure TAP parameters one by one
- remove a TAP parameter
- remove all TAP parameters at once
- add a keyword which adds a new TAP interface
Change-Id: I5620adc3f777f7a337bbd737e685891b425d4e09
Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/libraries')
-rw-r--r-- | resources/libraries/python/honeycomb/HcAPIKwInterfaces.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index 7bdfa19831..9355f639cc 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -45,6 +45,7 @@ class InterfaceKeywords(object): VXLAN_PARAMS = ("src", "dst", "vni", "encap-vrf-id") L2_PARAMS = ("bridge-domain", "split-horizon-group", "bridged-virtual-interface") + TAP_PARAMS = ("tap-name", "mac", "device-instance") def __init__(self): pass @@ -795,3 +796,69 @@ class InterfaceKeywords(object): param) return InterfaceKeywords._set_interface_properties( node, interface, path, value) + + @staticmethod + def create_tap_interface(node, interface, **kwargs): + """Create a new TAP interface. + + :param node: Honeycomb node. + :param interface: The name of interface. + :param kwargs: Parameters and their values. The accepted parameters are + defined in InterfaceKeywords.TAP_PARAMS. + :type node: dict + :type interface: str + :type kwargs: dict + :return: Content of response. + :rtype: bytearray + :raises HoneycombError: If the parameter is not valid. + """ + + new_tap = { + "name": interface, + "type": "v3po:tap", + "v3po:tap": {} + } + for param, value in kwargs.items(): + if param not in InterfaceKeywords.TAP_PARAMS: + raise HoneycombError("The parameter {0} is invalid.". + format(param)) + new_tap["v3po:tap"][param] = value + + path = ("interfaces", "interface") + new_tap_structure = [new_tap, ] + return InterfaceKeywords._set_interface_properties( + node, interface, path, new_tap_structure) + + @staticmethod + def configure_interface_tap(node, interface, **kwargs): + """Configure TAP on the interface. + + The keyword configures TAP parameters on the given interface. The type + of interface must be set to "v3po:tap". + The new TAP parameters overwrite the current configuration. If a + parameter in new configuration is missing, it is removed from TAP + configuration. + If the dictionary kwargs is empty, TAP configuration is removed. + + :param node: Honeycomb node. + :param interface: The name of interface. + :param kwargs: Parameters and their values. The accepted parameters are + defined in InterfaceKeywords.TAP_PARAMS. + :type node: dict + :type interface: str + :type kwargs: dict + :return: Content of response. + :rtype: bytearray + :raises HoneycombError: If the parameter is not valid. + """ + + tap_structure = dict() + for param, value in kwargs.items(): + if param not in InterfaceKeywords.TAP_PARAMS: + raise HoneycombError("The parameter {0} is invalid.". + format(param)) + tap_structure[param] = value + + path = ("interfaces", ("interface", "name", interface), "v3po:tap") + return InterfaceKeywords._set_interface_properties( + node, interface, path, tap_structure) |