if "vnfd:vnfd-catalog" in data or "vnfd-catalog" in data:
descriptor = "VNF"
+ #Check if mgmt-interface is defined:
+ remove_prefix(data, "vnfd:")
+ vnfd_descriptor = data["vnfd-catalog"]
+ vnfd_list = vnfd_descriptor["vnfd"]
+ mgmt_iface = False
+ for vnfd in vnfd_list:
+ if vnfd.get("mgmt-interface"):
+ mgmt_iface = True
+ if not mgmt_iface:
+ raise KeyError("'mgmt-iface' is a mandatory field and it is not defined")
myvnfd = vnfd_catalog.vnfd()
pybindJSONDecoder.load_ietf_json(data, None, None, obj=myvnfd)
elif "nsd:nsd-catalog" in data or "nsd-catalog" in data:
error_position.append("external-interface")
for external_interface in external_interface_list:
error_position[-1] = "external-interface[{}]".format(external_interface["name"])
+ if "rw-vnfd:floating-ip-needed" in external_interface:
+ del external_interface["rw-vnfd:floating-ip-needed"]
external_interface["type"] = "EXTERNAL"
external_interface["external-connection-point-ref"] = \
external_interface.pop("vnfd-connection-point-ref")
internal_interface.pop("vdu-internal-connection-point-ref")
interface_list.append(internal_interface)
error_position.pop()
+
+ #Removing "rw-vnfd:floating-ip-needed" items from V3 descriptors
+ interfaces = vdu.pop("interface", ())
+ for iface in interfaces:
+ if "rw-vnfd:floating-ip-needed" in iface:
+ del iface["rw-vnfd:floating-ip-needed"]
+ interface_list.append(iface)
+
# order interface alphabetically and set position
if interface_list:
interface_list = sorted(interface_list,
print(" -i|--input FILE: (same as param FILE) descriptor file to be upgraded")
return
+def remove_prefix(desc, prefix):
+ """
+ Recursively removes prefix from keys
+ :param desc: dictionary or list to change
+ :param prefix: prefix to remove. Must
+ :return: None, param desc is changed
+ """
+ prefix_len = len(prefix)
+ if isinstance(desc, dict):
+ prefixed_list=[]
+ for k,v in desc.items():
+ if isinstance(v, (list, tuple, dict)):
+ remove_prefix(v, prefix)
+ if isinstance(k, str) and k.startswith(prefix) and k != prefix:
+ prefixed_list.append(k)
+ for k in prefixed_list:
+ desc[k[prefix_len:]] = desc.pop(k)
+ elif isinstance(desc, (list, tuple)):
+ for i in desc:
+ if isinstance(desc, (list, tuple, dict)):
+ remove_prefix(i, prefix)
+
if __name__=="__main__":
error_position = []
format_output_yaml = True
if "vnfd:vnfd-catalog" in data or "vnfd-catalog" in data:
descriptor = "VNF"
+ # Check if mgmt-interface is defined:
+ remove_prefix(data, "vnfd:")
+ vnfd_descriptor = data["vnfd-catalog"]
+ vnfd_list = vnfd_descriptor["vnfd"]
+ mgmt_iface = False
+ for vnfd in vnfd_list:
+ if vnfd.get("mgmt-interface"):
+ mgmt_iface = True
+ if not mgmt_iface:
+ raise KeyError("'mgmt-iface' is a mandatory field and it is not defined")
myvnfd = vnfd_catalog.vnfd()
pybindJSONDecoder.load_ietf_json(data, None, None, obj=myvnfd)
elif "nsd:nsd-catalog" in data or "nsd-catalog" in data: