diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/libraries/python/honeycomb/HcAPIKwInterfaces.py | 68 |
1 files changed, 68 insertions, 0 deletions
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) |