Add possibility to change VxLAN parameters at once
[csit.git] / resources / libraries / python / honeycomb / HcAPIKwInterfaces.py
index 8f6819e..854bc07 100644 (file)
@@ -331,7 +331,7 @@ class InterfaceKeywords(object):
             node, interface, path, value)
 
     @staticmethod
             node, interface, path, value)
 
     @staticmethod
-    def add_first_ipv4_address(node, interface, ip_addr, netmask):
+    def add_first_ipv4_address(node, interface, ip_addr, network):
         """Add the first IPv4 address.
 
         If there are any other addresses configured, they will be removed.
         """Add the first IPv4 address.
 
         If there are any other addresses configured, they will be removed.
@@ -339,39 +339,51 @@ class InterfaceKeywords(object):
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
-        :param netmask: Netmask.
+        :param network: Netmask or length of network prefix.
         :type node: dict
         :type interface: str
         :type ip_addr: str
         :type node: dict
         :type interface: str
         :type ip_addr: str
-        :type netmask: str
+        :type network: str or int
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
-        address = {"address": [{"ip": ip_addr, "netmask": netmask}, ]}
+        if isinstance(network, basestring):
+            address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
+        elif isinstance(network, int) and (0 < network < 33):
+            address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
+        else:
+            raise HoneycombError("Value {0} is not a valid netmask or network "
+                                 "prefix length.".format(network))
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
     @staticmethod
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
     @staticmethod
-    def add_ipv4_address(node, interface, ip_addr, netmask):
+    def add_ipv4_address(node, interface, ip_addr, network):
         """Add IPv4 address.
 
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
         """Add IPv4 address.
 
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
-        :param netmask: Netmask.
+        :param network: Netmask or length of network prefix.
         :type node: dict
         :type interface: str
         :type ip_addr: str
         :type node: dict
         :type interface: str
         :type ip_addr: str
-        :type netmask: str
+        :type network: str or int
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
                 "address")
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
                 "address")
-        address = [{"ip": ip_addr, "prefix-length": netmask}, ]
+        if isinstance(network, basestring):
+            address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
+        elif isinstance(network, int) and (0 < network < 33):
+            address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
+        else:
+            raise HoneycombError("Value {0} is not a valid netmask or network "
+                                 "prefix length.".format(network))
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
@@ -662,30 +674,38 @@ class InterfaceKeywords(object):
             node, interface, path, value)
 
     @staticmethod
             node, interface, path, value)
 
     @staticmethod
-    def configure_interface_vxlan(node, interface, param, value):
-        """Configure the VxLAN parameters of interface.
+    def configure_interface_vxlan(node, interface, **kwargs):
+        """Configure VxLAN on the interface.
+
+        The keyword configures VxLAN parameters on the given interface. The type
+        of interface must be set to "v3po:vxlan-tunnel".
+        The new VxLAN parameters overwrite the current configuration. If a
+        parameter in new configuration is missing, it is removed from VxLAN
+        configuration.
+        If the dictionary kwargs is empty, VxLAN configuration is removed.
 
         :param node: Honeycomb node.
         :param interface: The name of interface.
 
         :param node: Honeycomb node.
         :param interface: The name of interface.
-        :param param: Parameter to configure (set, change, remove)
-        :param value: The value of parameter. If None, the parameter will be
-        removed.
+        :param kwargs: Parameters and their values. The accepted parameters are
+        defined in InterfaceKeywords.VXLAN_PARAMS.
         :type node: dict
         :type interface: str
         :type node: dict
         :type interface: str
-        :type param: str
-        :type value: str
+        :type kwargs: dict
         :return: Content of response.
         :rtype: bytearray
         :raises HoneycombError: If the parameter is not valid.
         """
 
         :return: Content of response.
         :rtype: bytearray
         :raises HoneycombError: If the parameter is not valid.
         """
 
-        if param not in InterfaceKeywords.VXLAN_PARAMS:
-            raise HoneycombError("The parameter {0} is invalid.".format(param))
+        vx_lan_structure = dict()
+        for param, value in kwargs.items():
+            if param not in InterfaceKeywords.VXLAN_PARAMS:
+                raise HoneycombError("The parameter {0} is invalid.".
+                                     format(param))
+            vx_lan_structure[param] = value
 
 
-        path = ("interfaces", ("interface", "name", interface), "v3po:vxlan",
-                param)
+        path = ("interfaces", ("interface", "name", interface), "v3po:vxlan")
         return InterfaceKeywords._set_interface_properties(
         return InterfaceKeywords._set_interface_properties(
-            node, interface, path, value)
+            node, interface, path, vx_lan_structure)
 
     @staticmethod
     def configure_interface_l2(node, interface, param, value):
 
     @staticmethod
     def configure_interface_l2(node, interface, param, value):