X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fhoneycomb%2FHcAPIKwInterfaces.py;h=e78696cd1516b9344de59111c66d22c392709292;hp=b4746e2118e97b2b711070e7d47c368bce03f7bb;hb=fa14d9f454a7248a71135375bfb0758cdb532ca7;hpb=4f4eaa1d52f3bdbe3caecdc1d6a024c369a2834a diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index b4746e2118..e78696cd15 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -201,6 +201,16 @@ class InterfaceKeywords(object): :rtype: dict """ + try: + interface = Topology.convert_interface_reference( + node, interface, "name") + except RuntimeError: + if isinstance(interface, basestring): + # Probably name of a custom interface (TAP, VxLAN, Vhost, ...) + pass + else: + raise + intfs = InterfaceKeywords.get_all_interfaces_oper_data(node) for intf in intfs: if intf["name"] == interface: @@ -653,6 +663,9 @@ class InterfaceKeywords(object): :rtype: bytearray """ + interface = Topology.convert_interface_reference( + node, interface, "name") + path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6", "address") address = [{"ip": ip_addr, "prefix-length": prefix_len}, ] @@ -1149,6 +1162,9 @@ class InterfaceKeywords(object): :rtype: bytearray """ + super_interface = Topology.convert_interface_reference( + node, super_interface, "name") + intf_state = {"up": "true", "down": "false"} @@ -1498,6 +1514,69 @@ class InterfaceKeywords(object): "Status code: {1}.".format(interface, status_code)) return resp + @staticmethod + def enable_policer_on_interface(node, interface, table_name): + """Enable Policer on the given interface. + + :param node: Honeycomb node. + :param interface: The interface where policer will be enabled. + :param table_name: Name of the classify table. + :type node: dict + :type interface: str + :type table_name: str + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the configuration of interface is not + successful. + """ + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + data = { + "interface-policer:policer": { + "ip4-table": table_name + } + } + + path = "/interface/" + interface + "/interface-policer:policer" + status_code, resp = HcUtil.\ + put_honeycomb_data(node, "config_vpp_interfaces", data, path, + data_representation=DataRepresentation.JSON) + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "The configuration of interface '{0}' was not successful. " + "Status code: {1}.".format(interface, status_code)) + return resp + + @staticmethod + def disable_policer_on_interface(node, interface): + """Disable Policer on the given interface. + + :param node: Honeycomb node. + :param interface: The interface where policer will be disabled. + :param table_name: Name of the classify table. + :type node: dict + :type interface: str + :type table_name: str + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the configuration of interface is not + successful. + """ + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + path = "/interface/" + interface + "/interface-policer:policer" + status_code, resp = HcUtil.\ + delete_honeycomb_data(node, "config_vpp_interfaces", path) + if status_code != HTTPCodes.OK: + raise HoneycombError( + "The configuration of interface '{0}' was not successful. " + "Status code: {1}.".format(interface, status_code)) + return resp + @staticmethod def disable_acl_on_interface(node, interface): """Disable ACL on the given interface. @@ -1622,7 +1701,7 @@ class InterfaceKeywords(object): " of disabled interfaces.".format(interface)) @staticmethod - def configure_interface_span(node, dst_interface, *src_interfaces): + def configure_interface_span(node, dst_interface, src_interfaces=None): """Configure SPAN port mirroring on the specified interfaces. If no source interface is provided, SPAN will be disabled. @@ -1630,30 +1709,88 @@ class InterfaceKeywords(object): :param dst_interface: Interface to mirror packets to. :param src_interfaces: List of interfaces to mirror packets from. :type node: dict - :type dst_interface: str - :type src_interfaces: list of str + :type dst_interface: str or int + :type src_interfaces: list of dict :returns: Content of response. :rtype: bytearray :raises HoneycombError: If SPAN could not be configured. """ - interface = dst_interface.replace("/", "%2F") + interface = Topology.convert_interface_reference( + node, dst_interface, "name") + interface = interface.replace("/", "%2F") path = "/interface/" + interface + "/span" if not src_interfaces: status_code, _ = HcUtil.delete_honeycomb_data( node, "config_vpp_interfaces", path) + else: + for src_interface in src_interfaces: + src_interface["iface-ref"] = Topology.\ + convert_interface_reference( + node, src_interface["iface-ref"], "name") + data = { + "span": { + "mirrored-interfaces": { + "mirrored-interface": src_interfaces + } + } + } - data = { - "span": { - "mirrored-interfaces": { - "mirrored-interface": src_interfaces + status_code, _ = HcUtil.put_honeycomb_data( + node, "config_vpp_interfaces", data, path) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "Configuring SPAN failed. Status code:{0}".format(status_code)) + + @staticmethod + def configure_sub_interface_span(node, super_interface, dst_interface_index, + src_interfaces=None): + """Configure SPAN port mirroring on the specified sub-interface. If no + source interface is provided, SPAN will be disabled. + + Note: Does not support source sub-interfaces, only destination. + + :param node: Honeycomb node. + :param super_interface: Name, link name or sw_if_index + of the destination interface's super-interface. + :param dst_interface_index: Index of sub-interface to mirror packets to. + :param src_interfaces: List of interfaces to mirror packets from. + :type node: dict + :type super_interface: str or int + :type dst_interface_index: int + :type src_interfaces: list of dict + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If SPAN could not be configured. + """ + + super_interface = Topology.convert_interface_reference( + node, super_interface, "name") + super_interface = super_interface.replace("/", "%2F") + + path = "/interface/{0}/vpp-vlan:sub-interfaces/sub-interface/{1}/span"\ + .format(super_interface, dst_interface_index) + + if not src_interfaces: + status_code, _ = HcUtil.delete_honeycomb_data( + node, "config_vpp_interfaces", path) + else: + for src_interface in src_interfaces: + src_interface["iface-ref"] = Topology. \ + convert_interface_reference( + node, src_interface["iface-ref"], "name") + data = { + "span": { + "mirrored-interfaces": { + "mirrored-interface": src_interfaces + } } } - } - status_code, _ = HcUtil.put_honeycomb_data( - node, "config_vpp_interfaces", data, path) + status_code, _ = HcUtil.put_honeycomb_data( + node, "config_vpp_interfaces", data, path) if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): raise HoneycombError(