X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fhoneycomb%2FHcAPIKwInterfaces.py;h=b4746e2118e97b2b711070e7d47c368bce03f7bb;hb=refs%2Fchanges%2F88%2F5688%2F10;hp=1e0883db2784de2d5f1ad694f7465e5f3333f643;hpb=1813672eb9f6988046bc65167235ae37b088298c;p=csit.git diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index 1e0883db27..b4746e2118 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2017 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -44,7 +44,7 @@ class InterfaceKeywords(object): "temporary-valid-lifetime", "temporary-preferred-lifetime") ETH_PARAMS = ("mtu", ) - ROUTING_PARAMS = ("vrf-id", ) + ROUTING_PARAMS = ("ipv4-vrf-id", "ipv6-vrf-id") VXLAN_PARAMS = ("src", "dst", "vni", "encap-vrf-id") L2_PARAMS = ("bridge-domain", "split-horizon-group", "bridged-virtual-interface") @@ -513,9 +513,9 @@ class InterfaceKeywords(object): path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4", "address") if isinstance(network, basestring): - address = {"address": [{"ip": ip_addr, "netmask": network}, ]} + address = [{"ip": ip_addr, "netmask": network}] elif isinstance(network, int) and (0 < network < 33): - address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]} + address = [{"ip": ip_addr, "prefix-length": network}] else: raise HoneycombError("Value {0} is not a valid netmask or network " "prefix length.".format(network)) @@ -555,6 +555,9 @@ class InterfaceKeywords(object): :rtype: bytearray """ + interface = Topology.convert_interface_reference( + node, interface, "name") + path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4", "neighbor") neighbor = [{"ip": ip_addr, "link-layer-address": link_layer_address}, ] @@ -626,6 +629,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}, ]} return InterfaceKeywords._set_interface_properties( @@ -686,6 +692,9 @@ class InterfaceKeywords(object): :rtype: bytearray """ + interface = Topology.convert_interface_reference( + node, interface, "name") + path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6", "neighbor") neighbor = [{"ip": ip_addr, "link-layer-address": link_layer_address}, ] @@ -752,6 +761,9 @@ class InterfaceKeywords(object): :raises HoneycombError: If the parameter is not valid. """ + interface = Topology.convert_interface_reference( + node, interface, "name") + if param not in InterfaceKeywords.ROUTING_PARAMS: raise HoneycombError("The parameter {0} is invalid.".format(param)) @@ -1143,7 +1155,7 @@ class InterfaceKeywords(object): path = ("interfaces", ("interface", "name", super_interface), "vpp-vlan:sub-interfaces", - ("sub-interface", "identifier", identifier), + ("sub-interface", "identifier", int(identifier)), "enabled") return InterfaceKeywords._set_interface_properties( @@ -1248,8 +1260,8 @@ class InterfaceKeywords(object): "information about the tag-rewrite.") @staticmethod - def add_ipv4_address_to_sub_interface(node, super_interface, identifier, - ip_addr, network): + def add_ip_address_to_sub_interface(node, super_interface, identifier, + ip_addr, network, ip_version): """Add an ipv4 address to the specified sub-interface, with the provided netmask or network prefix length. Any existing ipv4 addresses on the sub-interface will be replaced. @@ -1259,11 +1271,13 @@ class InterfaceKeywords(object): :param identifier: The ID of sub-interface. :param ip_addr: IPv4 address to be set. :param network: Network mask or network prefix length. + :param ip_version: ipv4 or ipv6 :type node: dict :type super_interface: str :type identifier: int :type ip_addr: str :type network: str or int + :type ip_version: string :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the provided netmask or prefix is not valid. @@ -1273,9 +1287,9 @@ class InterfaceKeywords(object): ("interface", "name", super_interface), "vpp-vlan:sub-interfaces", ("sub-interface", "identifier", int(identifier)), - "ipv4") + ip_version.lower()) - if isinstance(network, basestring): + if isinstance(network, basestring) and ip_version.lower() == "ipv4": address = {"address": [{"ip": ip_addr, "netmask": network}, ]} elif isinstance(network, int) and 0 < network < 33: @@ -1289,16 +1303,18 @@ class InterfaceKeywords(object): node, super_interface, path, address) @staticmethod - def remove_all_ipv4_addresses_from_sub_interface(node, super_interface, - identifier): + def remove_all_ip_addresses_from_sub_interface(node, super_interface, + identifier, ip_version): """Remove all ipv4 addresses from the specified sub-interface. :param node: Honeycomb node. :param super_interface: Super interface. :param identifier: The ID of sub-interface. + :param ip_version: ipv4 or ipv6 :type node: dict :type super_interface: str :type identifier: int + :type ip_version: string :returns: Content of response. :rtype: bytearray """ @@ -1307,7 +1323,7 @@ class InterfaceKeywords(object): ("interface", "name", super_interface), "vpp-vlan:sub-interfaces", ("sub-interface", "identifier", int(identifier)), - "ipv4", "address") + str(ip_version), "address") return InterfaceKeywords._set_interface_properties( node, super_interface, path, None) @@ -1375,10 +1391,11 @@ class InterfaceKeywords(object): else: raise HoneycombError( - "Unexpected data type {data_type}, reference type is" - " {ref_type}. Must be list or dictionary.".format( + "Unexpected data type {data_type} in path {path}, reference" + " type is {ref_type}. Must be list or dictionary.".format( data_type=type(data), - ref_type=type(ref))) + ref_type=type(ref), + path=_path)) @staticmethod def compare_interface_lists(list1, list2): @@ -1459,7 +1476,7 @@ class InterfaceKeywords(object): interface = interface.replace("/", "%2F") data = { - "v3po:acl": { + "vpp-interface-acl:acl": { "ingress": { "ip4-acl": { "classify-table": table_name @@ -1471,7 +1488,7 @@ class InterfaceKeywords(object): } } - path = "/interface/" + interface + "/v3po:acl" + path = "/interface/" + interface + "/vpp-interface-acl:acl" status_code, resp = HcUtil.\ put_honeycomb_data(node, "config_vpp_interfaces", data, path, data_representation=DataRepresentation.JSON) @@ -1497,7 +1514,7 @@ class InterfaceKeywords(object): interface = interface.replace("/", "%2F") - path = "/interface/" + interface + "/v3po:acl" + path = "/interface/" + interface + "/vpp-interface-acl:acl" status_code, resp = HcUtil.\ delete_honeycomb_data(node, "config_vpp_interfaces", path) @@ -1527,7 +1544,7 @@ class InterfaceKeywords(object): """ interface = intf.replace("/", "%2F") - path = "/interface/{0}/pbb-rewrite/".format(interface) + path = "/interface/{0}/pbb-rewrite".format(interface) status_code, resp = HcUtil. \ put_honeycomb_data(node, "config_vpp_interfaces", params, path, data_representation=DataRepresentation.JSON)