-def rift2openmano_nsd(rift_nsd, rift_vnfds,openmano_vnfd_ids):
- for vnfd_id in rift_nsd.vnfd_ids:
- if vnfd_id not in rift_vnfds:
- raise VNFNotFoundError("VNF id %s not provided" % vnfd_id)
-
- openmano = {}
- openmano["name"] = rift_nsd.name
- openmano["description"] = rift_nsd.description
- topology = {}
- openmano["topology"] = topology
-
- topology["nodes"] = {}
- for vnfd in rift_nsd.constituent_vnfds:
- vnfd_id = vnfd.vnfd_id_ref
- rift_vnfd = rift_vnfds[vnfd_id]
- member_idx = vnfd.member_vnf_index
- openmano_vnfd_id = openmano_vnfd_ids.get(vnfd_id,None)
- if openmano_vnfd_id:
- topology["nodes"][rift_vnfd.name + "__" + str(member_idx)] = {
- "type": "VNF",
- "vnf_id": openmano_vnfd_id
- }
- else:
- topology["nodes"][rift_vnfd.name + "__" + str(member_idx)] = {
- "type": "VNF",
- "VNF model": rift_vnfd.name
- }
-
- for vld in rift_nsd.vlds:
- # Openmano has both bridge_net and dataplane_net models for network types
- # For now, since we are using openmano in developer mode lets just hardcode
- # to bridge_net since it won't matter anyways.
- # topology["nodes"][vld.name] = {"type": "network", "model": "bridge_net"}
- pass
-
- topology["connections"] = {}
- for vld in rift_nsd.vlds:
-
- # Create a connections entry for each external VLD
- topology["connections"][vld.name] = {}
- topology["connections"][vld.name]["nodes"] = []
-
- #if vld.vim_network_name:
- if True:
- if vld.name not in topology["nodes"]:
- topology["nodes"][vld.name] = {
- "type": "external_network",
- "model": vld.name,
- }
-
- # Add the external network to the list of connection points
- topology["connections"][vld.name]["nodes"].append(
- {vld.name: "0"}
- )
- elif vld.provider_network.has_field("physical_network"):
- # Add the external datacenter network to the topology
- # node list if it isn't already added
- ext_net_name = vld.provider_network.physical_network
- ext_net_name_with_seg = ext_net_name
- if vld.provider_network.has_field("segmentation_id"):
- ext_net_name_with_seg += ":{}".format(vld.provider_network.segmentation_id)
-
- if ext_net_name not in topology["nodes"]:
- topology["nodes"][ext_net_name] = {
- "type": "external_network",
- "model": ext_net_name_with_seg,
- }
-
- # Add the external network to the list of connection points
- topology["connections"][vld.name]["nodes"].append(
- {ext_net_name: "0"}
- )
-
-
- for vnfd_cp in vld.vnfd_connection_point_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 = vnfd.name + "__" + str(member_idx)
- topology["connections"][vld.name]["nodes"].append(
- {
- vnf_ref: vnfd_cp.vnfd_connection_point_ref
- }
- )
-
- return openmano
-
-
-def rift2openmano_vnfd(rift_vnfd):
- 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(rift_type):
- 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.virtual_interface.type_yang),
- "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": "data",
- "elements": [],
- }
-
- # Add the specific VDU connection points
- for int_cp_ref in vld.internal_connection_point_ref:
- vdu, int_if = find_vdu_and_int_if_by_cp_ref(int_cp_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,
- "numas": [{
- "memory": max(int(vdu.vm_flavor.memory_mb/1024), 1),
- "interfaces":[],
- }],
- "bridge-ifaces": [],
- }
-
- 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
-
- 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)
-
- if vdu.has_field("hypervisor_epa"):
- vnfc["hypervisor"] = {}
- if vdu.hypervisor_epa.has_field("type"):
- if vdu.hypervisor_epa.type_yang == "REQUIRE_KVM":
- vnfc["hypervisor"]["type"] = "QEMU-kvm"
-
- if vdu.hypervisor_epa.has_field("version"):
- vnfc["hypervisor"]["version"] = vdu.hypervisor_epa.version
-
- if vdu.has_field("host_epa"):
- vnfc["processor"] = {}
- if vdu.host_epa.has_field("om_cpu_model_string"):
- vnfc["processor"]["model"] = vdu.host_epa.om_cpu_model_string
- if vdu.host_epa.has_field("om_cpu_feature"):
- vnfc["processor"]["features"] = []
- for feature in vdu.host_epa.om_cpu_feature:
- vnfc["processor"]["features"].append(feature)
-