Add keyword to manipulate vhost-user parameters 86/1086/5
authorTibor Frank <tifrank@cisco.com>
Thu, 12 May 2016 12:30:39 +0000 (14:30 +0200)
committerTibor Frank <tifrank@cisco.com>
Mon, 16 May 2016 06:02:49 +0000 (08:02 +0200)
JIRA: CSIT-70

- add a keyword to be able to:
  - configure all vhost-user parameters at once
  - configure vhost-user parameters one by one
  - remove a vhost-user parameter
  - remove all vhost-user parameters at once
- add a keyword which adds a new vhost-user interface

Change-Id: I144bc035b959a1e4eb37c6a3d554e6843ddab4a7
Signed-off-by: Tibor Frank <tifrank@cisco.com>
resources/libraries/python/honeycomb/HcAPIKwInterfaces.py

index 9355f63..04800a2 100644 (file)
@@ -46,6 +46,7 @@ class InterfaceKeywords(object):
     L2_PARAMS = ("bridge-domain", "split-horizon-group",
                  "bridged-virtual-interface")
     TAP_PARAMS = ("tap-name", "mac", "device-instance")
+    VHOST_USER_PARAMS = ("socket", "role")
 
     def __init__(self):
         pass
@@ -862,3 +863,70 @@ class InterfaceKeywords(object):
         path = ("interfaces", ("interface", "name", interface), "v3po:tap")
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, tap_structure)
+
+    @staticmethod
+    def configure_interface_vhost_user(node, interface, **kwargs):
+        """Configure vhost-user on the interface.
+
+        The keyword configures vhost-user parameters on the given interface.
+        The type of interface must be set to "v3po:vhost-user".
+        The new vhost-user parameters overwrite the current configuration. If a
+        parameter in new configuration is missing, it is removed from vhost-user
+        configuration.
+        If the dictionary kwargs is empty, vhost-user 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.VHOST_USER_PARAMS.
+        :type node: dict
+        :type interface: str
+        :type kwargs: dict
+        :return: Content of response.
+        :rtype: bytearray
+        :raises HoneycombError: If the parameter is not valid.
+        """
+
+        vhost_structure = dict()
+        for param, value in kwargs.items():
+            if param not in InterfaceKeywords.VHOST_USER_PARAMS:
+                raise HoneycombError("The parameter {0} is invalid.".
+                                     format(param))
+            vhost_structure[param] = value
+
+        path = ("interfaces", ("interface", "name", interface),
+                "v3po:vhost-user")
+        return InterfaceKeywords._set_interface_properties(
+            node, interface, path, vhost_structure)
+
+    @staticmethod
+    def create_vhost_user_interface(node, interface, **kwargs):
+        """Create a new vhost-user interface.
+
+        :param node: Honeycomb node.
+        :param interface: The name of interface.
+        :param kwargs: Parameters and their values. The accepted parameters are
+        defined in InterfaceKeywords.VHOST_USER_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_vhost = {
+            "name": interface,
+            "type": "v3po:vhost-user",
+            "v3po:vhost-user": {}
+        }
+        for param, value in kwargs.items():
+            if param not in InterfaceKeywords.VHOST_USER_PARAMS:
+                raise HoneycombError("The parameter {0} is invalid.".
+                                     format(param))
+            new_vhost["v3po:vhost-user"][param] = value
+
+        path = ("interfaces", "interface")
+        new_vhost_structure = [new_vhost, ]
+        return InterfaceKeywords._set_interface_properties(
+            node, interface, path, new_vhost_structure)

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.