-def rift2openmano_vnfd(rift_vnfd, rift_nsd):
- openmano_vnf = {"vnf":{}}
- vnf = openmano_vnf["vnf"]
-
- vnf["name"] = rift_vnfd.name
- vnf["description"] = rift_vnfd.description
-
- vnf["external-connections"] = []
-
- def find_vdu_and_ext_if_by_cp_ref(cp_ref_name):
- for vdu in rift_vnfd.vdus:
- for ext_if in vdu.external_interface:
- if ext_if.vnfd_connection_point_ref == cp_ref_name:
- return vdu, ext_if
-
- raise ValueError("External connection point reference %s not found" % cp_ref_name)
-
- def find_vdu_and_int_if_by_cp_ref(cp_ref_id):
- for vdu in rift_vnfd.vdus:
- for int_if in vdu.internal_interface:
- if int_if.vdu_internal_connection_point_ref == cp_ref_id:
- return vdu, int_if
-
- raise ValueError("Internal connection point reference %s not found" % cp_ref_id)
-
- def rift2openmano_if_type(ext_if):
-
- cp_ref_name = ext_if.vnfd_connection_point_ref
- for vld in rift_nsd.vlds:
-
- # if it is an explicit mgmt_network then check if the given
- # cp_ref is a part of it
- if not vld.mgmt_network:
- continue
-
- for vld_cp in vld.vnfd_connection_point_ref:
- if vld_cp.vnfd_connection_point_ref == cp_ref_name:
- return "mgmt"
-
-
- rift_type = ext_if.virtual_interface.type_yang
- # Retaining it for backward compatibility!
- if rift_type == "OM_MGMT":
- return "mgmt"
- elif rift_type == "VIRTIO" or rift_type == "E1000":
- return "bridge"
- else:
- return "data"
-
- def rift2openmano_vif(rift_type):
- if rift_type == "VIRTIO":
- return "virtio"
- elif rift_type == "E1000":
- return "e1000"
- else:
- raise ValueError("VDU Virtual Interface type {} not supported".format(rift_type))
-
- # Add all external connections
- for cp in rift_vnfd.cps:
- # Find the VDU and and external interface for this connection point
- vdu, ext_if = find_vdu_and_ext_if_by_cp_ref(cp.name)
- connection = {
- "name": cp.name,
- "type": rift2openmano_if_type(ext_if),
- "VNFC": vdu.name,
- "local_iface_name": ext_if.name,
- "description": "%s iface on VDU %s" % (ext_if.name, vdu.name),
- }
-
- vnf["external-connections"].append(connection)
-
- # Add all internal networks
- for vld in rift_vnfd.internal_vlds:
- connection = {
- "name": vld.name,
- "description": vld.description,
- "type": "bridge",
- "elements": [],
- }
-
- # Add the specific VDU connection points
- for int_cp in vld.internal_connection_point:
- vdu, int_if = find_vdu_and_int_if_by_cp_ref(int_cp.id_ref)
- connection["elements"].append({
- "VNFC": vdu.name,
- "local_iface_name": int_if.name,
- })
- if "internal-connections" not in vnf:
- vnf["internal-connections"] = []
-
- vnf["internal-connections"].append(connection)
-
- # Add VDU's
- vnf["VNFC"] = []
- for vdu in rift_vnfd.vdus:
- vnfc = {
- "name": vdu.name,
- "description": vdu.name,
- "bridge-ifaces": [],
- }
-
- if vdu.vm_flavor.has_field("storage_gb") and vdu.vm_flavor.storage_gb:
- vnfc["disk"] = vdu.vm_flavor.storage_gb
-
- if vdu.has_field("image"):
- if os.path.isabs(vdu.image):
- vnfc["VNFC image"] = vdu.image
- else:
- vnfc["image name"] = vdu.image
- if vdu.has_field("image_checksum"):
- vnfc["image checksum"] = vdu.image_checksum
-
- dedicated_int = False
- for intf in list(vdu.internal_interface) + list(vdu.external_interface):
- if intf.virtual_interface.type_yang in ["SR_IOV", "PCI_PASSTHROUGH"]:
- dedicated_int = True
- if vdu.guest_epa.has_field("numa_node_policy") or dedicated_int:
- vnfc["numas"] = [{
- "memory": max(int(vdu.vm_flavor.memory_mb/1024), 1),
- "interfaces":[],
- }]
- numa_node_policy = vdu.guest_epa.numa_node_policy
- if numa_node_policy.has_field("node"):
- numa_node = numa_node_policy.node[0]
-
- if numa_node.has_field("paired_threads"):
- if numa_node.paired_threads.has_field("num_paired_threads"):
- vnfc["numas"][0]["paired-threads"] = numa_node.paired_threads.num_paired_threads
- if len(numa_node.paired_threads.paired_thread_ids) > 0:
- vnfc["numas"][0]["paired-threads-id"] = []
- for pair in numa_node.paired_threads.paired_thread_ids:
- vnfc["numas"][0]["paired-threads-id"].append(
- [pair.thread_a, pair.thread_b]
- )
-
- else:
- if vdu.vm_flavor.has_field("vcpu_count"):
- vnfc["numas"][0]["cores"] = max(vdu.vm_flavor.vcpu_count, 1)
+def rift2openmano_vnfd(rift_vnfd, rift_nsd, http_api, project):
+ try:
+ openmano_vnfd_im_body = json.loads(rift_vnfd.from_dict())
+
+ # All type_yang leafs renamed to type
+
+ vnfd_dict = openmano_vnfd_im_body['vnfd-catalog']['vnfd'][0]
+
+ if 'vdu' in vnfd_dict:
+ for vdu in vnfd_dict['vdu']:
+ if 'cloud-init-file' in vdu:
+ # Replacing the leaf with the actual contents of the file.
+ # The RO does not have the ability to read files yet.
+ vdu['cloud-init-file'] = cloud_init(vnfd_dict['id'], vdu, project)
+ elif 'cloud-init' in vdu:
+ vdu['cloud-init'] = cloud_init(vnfd_dict['id'], vdu, project)
+
+ if 'supplemental-boot-data' in vdu:
+ if 'config-file' in vdu['supplemental-boot-data']:
+ for config_file in vdu['supplemental-boot-data']['config-file']:
+ # Replacing the leaf with the actual contents of the file.
+ # The RO does not have the ability to read files yet.
+ config_file['source'] = config_file_init(vnfd_dict['id'], vdu, config_file['source'], project)
+
+ openmano_vnfd_api_format = {
+ "vnfd:vnfd-catalog": {
+ "vnfd": [vnfd_dict]
+ }
+ }
+ openmano_vnfd = http_api.post_vnfd_v3(openmano_vnfd_api_format)
+
+ return openmano_vnfd
+
+ except Exception as e:
+ logger.error(e)
+ raise e