X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fhoneycomb%2FRouting.py;h=495e96e0fd60b94b551e61e8b661ebb0194156fe;hp=c39031d920d2ecfc6f528e7a84bf8b35520abe82;hb=3d279e4d68bbd94024bf739e71c872f18822a65d;hpb=0c4d0080a1488e2aeaa2d0abe9bbcb37c5bfe7c3 diff --git a/resources/libraries/python/honeycomb/Routing.py b/resources/libraries/python/honeycomb/Routing.py index c39031d920..495e96e0fd 100644 --- a/resources/libraries/python/honeycomb/Routing.py +++ b/resources/libraries/python/honeycomb/Routing.py @@ -92,7 +92,7 @@ class RoutingKeywords(object): if special: ip_version = "hc2vpp-ietf-{0}-unicast-routing:{0}".format( ip_version) - protocol = "vpp-routing-ra:vpp-protocol-attributes" + protocol = "vpp-routing:vpp-protocol-attributes" else: ip_version = ip_version protocol = "vpp-protocol-attributes" @@ -273,3 +273,60 @@ class RoutingKeywords(object): return {k: str(v) for k, v in dict_of_str.items()} except (KeyError, TypeError): return {} + + @staticmethod + 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)) + + @staticmethod + def get_policer_oper_data(node, policy_name): + """Get operational data about Policer on the node. + + :param node: Honeycomb node. + :type node: dict + :returns: dict of Policer operational data. + :rtype: dict + :raises HoneycombError: If status code differs from successful. + """ + + path = '/' + policy_name + + status_code, resp = HcUtil.\ + get_honeycomb_data(node, "oper_policer", path) + + if status_code != HTTPCodes.OK: + raise HoneycombError( + "Not possible to get operational information about Policer. " + "Status code: {0}.".format(status_code)) + try: + return resp['policer'] + except (KeyError, TypeError): + return {}