X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fhoneycomb%2FHcAPIKwACL.py;h=82a953e128fef25f541029a285c117412862bf4d;hp=1042adc8722af1dcde98fdd0c3663b6f85107c1d;hb=21921596d22a72cc4e4f7dee172ff17d1e5853cd;hpb=233683de57527f477bf7e8d042a5f3d1f08c7744;ds=sidebyside diff --git a/resources/libraries/python/honeycomb/HcAPIKwACL.py b/resources/libraries/python/honeycomb/HcAPIKwACL.py index 1042adc872..82a953e128 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwACL.py +++ b/resources/libraries/python/honeycomb/HcAPIKwACL.py @@ -281,14 +281,19 @@ class ACLKeywords(object): :rtype: bytearray :raises HoneycombError: If the operation fails. """ - if layer.lower() == "l2": - suffix = "eth" - elif layer.lower() in ("l3_ip4", "l3_ip6", "l4"): + layer = layer.lower() + suffix_dict = {"l2": "eth", + "l3_ip4": "ipv4", + "l3_ip6": "ipv6" + } + if layer == "l4": raise NotImplementedError - else: + try: + suffix = suffix_dict[layer] + except KeyError: raise ValueError("Unexpected value of layer argument {0}." - "Valid options are: L2, L3_IP4, L3_IP6, L4." - .format(layer)) + "Valid options are: {1}" + .format(layer, suffix_dict.keys())) path = "/acl/ietf-access-control-list:{0}-acl/{1}".format( suffix, list_name) @@ -328,6 +333,7 @@ class ACLKeywords(object): :raises HoneycombError: If the operation fails. """ + layer = layer.lower() interface = Topology.convert_interface_reference( node, interface, "name") @@ -341,30 +347,33 @@ class ACLKeywords(object): path = "/interface/{0}/ietf-acl/{1}/access-lists".format( interface, direction) - data = { - "access-lists": { - "acl": [{ - "type": None, - "name": list_name - }], - "default-action": default_action, - "mode": None - } - } - - acl_type = "ietf-access-control-list:{suffix}-acl" - - if layer.lower() == "l2": - data["access-lists"]["mode"] = "l2" - data["access-lists"]["acl"][0]["type"] = \ - acl_type.format(suffix="eth") + layers = { + "l2": {"mode": "l2", "suffix": "eth"}, + "l3_ip4": {"mode": "l3", "suffix": "ipv4"}, + "l3_ip6": {"mode": "l3", "suffix": "ipv6"} + } - elif layer.lower() in ("l3_ip4", "l3_ip6", "L4"): + if layer == "L4": raise NotImplementedError else: - raise ValueError("Unknown network layer {0}. " - "Valid options are: " - "L2, L3_IP4, L3_IP6, L4.".format(layer)) + try: + data = { + "access-lists": { + "acl": [ + { + "type": "ietf-access-control-list:{0}-acl" + .format(layers[layer]['suffix']), + "name": list_name + } + ], + "default-action": default_action, + "mode": layers[layer]['mode'] + } + } + except KeyError: + raise ValueError("Unknown network layer {0}. " + "Valid options are: {1}".format( + layer, layers.keys())) status_code, resp = HcUtil.put_honeycomb_data( node, "config_vpp_interfaces", data, path)