From 24b74c204486931dba34ee2a4a2665984216700a Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 5 Mar 2018 17:39:04 +0100 Subject: [PATCH] OSM descriptor upgrade enhancement. Add position to interfaces, management cp Change-Id: Ibec28555b5b339fea2f27b9ae498e8a0e4116793 Signed-off-by: tierno --- .../tools/upgrade_descriptor_version.py | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/descriptor-packages/tools/upgrade_descriptor_version.py b/descriptor-packages/tools/upgrade_descriptor_version.py index e07aaeea..e33d2345 100755 --- a/descriptor-packages/tools/upgrade_descriptor_version.py +++ b/descriptor-packages/tools/upgrade_descriptor_version.py @@ -165,7 +165,7 @@ if __name__=="__main__": if "vnf-configuration" in vnfd and "service-primitive" in vnfd["vnf-configuration"]: vnfd["vnf-configuration"]["config-primitive"] = vnfd["vnf-configuration"].pop("service-primitive") - #Convert to capital letters vnf-configuration:service-primitive:parameter:data-type + # Convert to capital letters vnf-configuration:service-primitive:parameter:data-type if "vnf-configuration" in vnfd and "config-primitive" in vnfd["vnf-configuration"]: error_position.append("vnf-configuration") error_position.append("config-primitive") @@ -183,6 +183,7 @@ if __name__=="__main__": # Iterate with vdu:interfaces vdu_list = vnfd["vdu"] error_position.append("vdu") + vdu2mgmt_cp = {} # internal dict to indicate management interface for each vdu for vdu in vdu_list: error_position[-1] = "vdu[{}]".format(vdu["id"]) # Change external/internal interface @@ -194,6 +195,10 @@ if __name__=="__main__": external_interface["type"] = "EXTERNAL" external_interface["external-connection-point-ref"] = \ external_interface.pop("vnfd-connection-point-ref") + if external_interface.get("virtual-interface", {}).get("type") == "OM-MGMT": + external_interface["virtual-interface"]["type"] = "VIRTIO" + if vdu["id"] not in vdu2mgmt_cp: + vdu2mgmt_cp[vdu["id"]] = external_interface["external-connection-point-ref"] interface_list.append(external_interface) error_position.pop() internal_interface_list = vdu.pop("internal-interface", ()) @@ -205,20 +210,45 @@ if __name__=="__main__": internal_interface.pop("vdu-internal-connection-point-ref") interface_list.append(internal_interface) error_position.pop() + # order interface alphabetically and set position if interface_list: + interface_list = sorted(interface_list, + key=lambda k: k.get('external-connection-point-ref', + k.get('internal-connection-point-ref'))) + index = 1 + for i in interface_list: + i["position"] = str(index) + index += 1 + vdu["interface"] = interface_list error_position.pop() + # change mgmt-interface + if vnfd.get("mgmt-interface"): + error_position.append("mgmt-interface") + vdu_id = vnfd["mgmt-interface"].pop("vdu-id", None) + if vdu_id: + error_position.append("vdu-id") + vnfd["mgmt-interface"]["cp"] = vdu2mgmt_cp[vdu_id] + error_position.pop() + error_position.pop() error_position = [] elif "nsd:nsd-catalog" in data or "nsd-catalog" in data: remove_prefix(data, "nsd:") error_position.append("nsd-catalog") nsd_descriptor = data["nsd-catalog"] - nsd_list = nsd_descriptor["nsd"] error_position.append("nsd") for nsd in nsd_list: error_position[-1] = "nsd[{}]".format(nsd["id"]) - + # set mgmt-network to true + error_position.append("vld") + vld_list = nsd.get("vld", ()) + for vld in vld_list: + error_position[-1] = "vld[{}]".format(vld["id"]) + if "mgmt" in vld["name"].lower() or "management" in vld["name"].lower(): + vld['mgmt-network'] = 'true' + break + error_position.pop() # Change initial-config-primitive into initial-service-primitive if "initial-config-primitive" in nsd: nsd['initial-service-primitive'] = nsd.pop("initial-config-primitive") -- 2.25.1