+def rift2openmano_vnfd_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids,rift_vnfd_id=None):
+
+ if rift_vnfd_id not in rift_vnfds:
+ raise VNFNotFoundError("VNF id %s not provided" % rift_vnfd_id)
+
+ openmano_vnfd_nsd = {}
+ for groups in rift_nsd.scaling_group_descriptor:
+ openmano_vnfd_nsd["name"] = rift_vnfd_id+'__'+'scaling_group'+'__'+groups.name
+ openmano_vnfd_nsd["description"] = "Scaling Group"
+ topology = {}
+ openmano_vnfd_nsd["topology"] = topology
+ topology["connections"] = {}
+ topology["nodes"] = {}
+ tst_index = []
+ openmano_vnfd_id = openmano_vnfd_ids.get(rift_vnfd_id,None)
+ for rvnfd_id in rift_nsd.constituent_vnfds:
+ if rvnfd_id.vnfd_id_ref == rift_vnfd_id:
+ topology["nodes"][rift_vnfd_id+'__'+str(rvnfd_id.member_vnf_index)] = {
+ "type": "VNF",
+ "vnf_id": openmano_vnfd_id
+ }
+
+ for vld in rift_nsd.vlds:
+
+ # Create a connections entry for each external VLD
+ topology["connections"][vld.name] = {}
+ topology["connections"][vld.name]["nodes"] = []
+ if True:
+ if vld.name not in topology["nodes"]:
+ topology["nodes"][vld.name] = {
+ "type": "external_network",
+ "model": vld.name,
+ }
+ topology["connections"][vld.name]["nodes"].append(
+ {vld.name: "0"}
+ )
+
+
+
+ for vnfd_cp in vld.vnfd_connection_point_ref:
+ if not rift_vnfd_id in vnfd_cp.vnfd_id_ref:
+ continue
+ if rift_vnfd_id in vnfd_cp.vnfd_id_ref:
+
+ # Get the RIFT VNF for this external VLD connection point
+ vnfd = rift_vnfds[vnfd_cp.vnfd_id_ref]
+
+
+ # For each VNF in this connection, use the same interface name
+ topology["connections"][vld.name]["type"] = "link"
+ # Vnf ref is the vnf name with the member_vnf_idx appended
+ member_idx = vnfd_cp.member_vnf_index_ref
+ vnf_ref = rift_vnfd_id + "__" + str(member_idx)
+ topology["connections"][vld.name]["nodes"].append(
+ {
+ vnf_ref: vnfd_cp.vnfd_connection_point_ref
+ }
+ )
+ return openmano_vnfd_nsd
+
+
+def cloud_init(rift_vnfd_id, vdu):
+ """ Populate cloud_init with script from
+ either the inline contents or from the file provided
+ """
+ vnfd_package_store = rift.package.store.VnfdPackageFilesystemStore(logger)
+
+ cloud_init_msg = None
+ if vdu.cloud_init is not None:
+ logger.debug("cloud_init script provided inline %s", vdu.cloud_init)
+ cloud_init_msg = vdu.cloud_init
+ elif vdu.cloud_init_file is not None:
+ # Get cloud-init script contents from the file provided in the cloud_init_file param
+ logger.debug("cloud_init script provided in file %s", vdu.cloud_init_file)
+ filename = vdu.cloud_init_file
+ vnfd_package_store.refresh()
+ stored_package = vnfd_package_store.get_package(rift_vnfd_id)
+ cloud_init_extractor = rift.package.cloud_init.PackageCloudInitExtractor(logger)
+ try:
+ cloud_init_msg = cloud_init_extractor.read_script(stored_package, filename)
+ except rift.package.cloud_init.CloudInitExtractionError as e:
+ raise ValueError(e)
+ else:
+ logger.debug("VDU translation: cloud-init script not provided")
+ return
+
+ logger.debug("Current cloud init msg is {}".format(cloud_init_msg))
+ return cloud_init_msg
+
+def config_file_init(rift_vnfd_id, vdu, cfg_file):
+ """ Populate config file init with file provided
+ """
+ vnfd_package_store = rift.package.store.VnfdPackageFilesystemStore(logger)
+
+ # Get script contents from the file provided in the cloud_init directory
+ logger.debug("config file script provided in file {}".format(cfg_file))
+ filename = cfg_file
+ vnfd_package_store.refresh()
+ stored_package = vnfd_package_store.get_package(rift_vnfd_id)
+ cloud_init_extractor = rift.package.cloud_init.PackageCloudInitExtractor(logger)
+ try:
+ cfg_file_msg = cloud_init_extractor.read_script(stored_package, filename)
+ except rift.package.cloud_init.CloudInitExtractionError as e:
+ raise ValueError(e)