def configure_policer(node, policy_name, policer_data=None): """Configure Policer on the specified node. :param node: Honeycomb node. :param policer_data: Dictionary of configurations to apply. \ If it is None then the existing configuration is removed. :type node: dict :type policer_data: dict :returns: Content of response. :rtype: bytearray :raises HoneycombError: If policer could not be configured. """ path = '/' + policy_name if not policer_data: status_code, _ = HcUtil.delete_honeycomb_data( node, 'config_policer', path) else: data = {'policer': policer_data} status_code, _ = HcUtil.put_honeycomb_data(node, 'config_policer', data, path) if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): raise HoneycombError( 'Configuring policer failed. Status code:{0}'\ .format(status_code))
def configure_interface_slaac(node, interface, slaac_data=None): """Configure SLAAC on the specified interfaces. :param node: Honeycomb node. :param interface: Interface to configure SLAAC. :param slaac_data: Dictionary of configurations to apply. \ If it is None then the existing configuration is removed. :type node: dict :type interface: str :type slaac_data: dict of dicts :returns: Content of response. :rtype: bytearray :raises HoneycombError: If RA could not be configured. """ interface = Topology.convert_interface_reference( node, interface, 'name') interface = interface.replace('/', '%2F') path = 'interface/' + interface + '/ipv6/ipv6-router-advertisements' if not slaac_data: status_code, _ = HcUtil.delete_honeycomb_data( node, 'config_slaac', path) else: data = { 'ipv6-router-advertisements': slaac_data } status_code, _ = HcUtil.put_honeycomb_data( node, 'config_slaac', data, path) if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): raise HoneycombError( 'Configuring SLAAC failed. Status code:{0}'.format(status_code))
def set_proxyarp_interface_config(node, interface, state): """Enable or disable the proxyARP feature on the specified interface. :param node: Honeycomb node. :param interface: Name or sw_if_index of an interface on the node. :param state: Desired proxyARP state: enable, disable. :type node: dict :type interface: str :type state: str :raises ValueError: If the state argument is incorrect. :raises HoneycombError: If the status code in response is not 200 = OK or 201 = ACCEPTED. """ interface = Topology.convert_interface_reference( node, interface, "name") interface = interface.replace("/", "%2F") path = "/interface/{0}/proxy-arp".format(interface) if state == "disable": status_code, _ = HcUtil.delete_honeycomb_data( node, "config_vpp_interfaces", path) elif state == "enable": data = {"proxy-arp": {}} status_code, _ = HcUtil.put_honeycomb_data( node, "config_vpp_interfaces", data, path) else: raise ValueError("State argument has to be enable or disable.") if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): raise HoneycombError( "Interface proxyARP configuration on node {0} was not" " successful.".format(node["host"]))
def delete_acl_plugin_classify_chains(node): """Remove all plugin-ACL classify chains. :param node: Honeycomb node. :type node: dict """ status_code, _ = HcUtil.delete_honeycomb_data(node, "config_plugin_acl") if status_code != HTTPCodes.OK: raise HoneycombError("Could not remove plugin-acl chain. " "Status code: {0}.".format(status_code))
def delete_interface_plugin_acls(node, interface): """Remove all plugin-acl assignments from an interface. :param node: Honeycomb node. :param interface: Name of an interface on the node. :type node: dict :type interface: str or int """ interface = Topology.convert_interface_reference( node, interface, "name") interface = interface.replace("/", "%2F") path = "/interface/{0}/interface-acl:acl/".format(interface) status_code, _ = HcUtil.delete_honeycomb_data(node, "config_vpp_interfaces", path) if status_code != HTTPCodes.OK: raise HoneycombError( "Could not remove ACL assignment from interface. " "Status code: {0}.".format(status_code))
def configure_nat_on_interface(node, interface, direction, delete=False): """Configure NAT on the specified interface. :param node: Honeycomb node. :param interface: Name of an interface on the node. :param direction: NAT direction, outbound or inbound. :param delete: Delete an existing interface NAT configuration. :type node: dict :type interface: str :type direction: str :type delete: bool :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the operation fails. """ interface = Topology.convert_interface_reference( node, interface, "name") interface = interface.replace("/", "%2F") path = "/interface/{0}/interface-nat:nat/{1}".format( interface, direction) data = {direction: {}} if delete: status_code, resp = HcUtil.delete_honeycomb_data( node, "config_vpp_interfaces", path) else: status_code, resp = HcUtil.put_honeycomb_data( node, "config_vpp_interfaces", data, path) if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): raise HoneycombError("Could not configure NAT on interface. " "Status code: {0}.".format(status_code)) return resp