From 8b4fad4fe84e123f4ffad7d2c5f96b7780c1bfaf Mon Sep 17 00:00:00 2001 From: Tibor Frank Date: Thu, 12 May 2016 14:30:39 +0200 Subject: Add keyword to manipulate vhost-user parameters 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 --- .../python/honeycomb/HcAPIKwInterfaces.py | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'resources/libraries') diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index 9355f639cc..04800a24b5 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -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) -- cgit 1.2.3-korg