X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=models%2Fopenmano%2Fpython%2Frift%2Fopenmano%2Frift2openmano.py;h=178cc1ef5aa8a25d3482a5a0e8927149190def0a;hb=18899fe480173cc3ad1bb5ba36a889cc64af9a6b;hp=5b9faebf5f723293bb198b4d59ee923006f595df;hpb=1db958d9bb3ea59931b613b0d9be18da6ae523ad;p=osm%2FSO.git diff --git a/models/openmano/python/rift/openmano/rift2openmano.py b/models/openmano/python/rift/openmano/rift2openmano.py index 5b9faebf..178cc1ef 100755 --- a/models/openmano/python/rift/openmano/rift2openmano.py +++ b/models/openmano/python/rift/openmano/rift2openmano.py @@ -34,7 +34,7 @@ from gi.repository import ( RwYang, RwVnfdYang, RwNsdYang, - ) +) import rift.package.store import rift.package.cloud_init @@ -230,7 +230,7 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids, rift_vnfd_id=None openmano = {} openmano["name"] = rift_nsd.name if rift_vnfd_id is not None: - openmano["name"] += "scale1" + openmano["name"] += "scale1" openmano["description"] = rift_nsd.description topology = {} openmano["topology"] = topology @@ -247,12 +247,12 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids, rift_vnfd_id=None 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 @@ -272,14 +272,14 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids, rift_vnfd_id=None if True: if vld.name not in topology["nodes"]: topology["nodes"][vld.name] = { - "type": "external_network", - "model": 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"} - ) + {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 @@ -290,14 +290,14 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids, rift_vnfd_id=None if ext_net_name not in topology["nodes"]: topology["nodes"][ext_net_name] = { - "type": "external_network", - "model": ext_net_name_with_seg, - } + "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"} - ) + {ext_net_name: "0"} + ) for vnfd_cp in vld.vnfd_connection_point_ref: @@ -317,56 +317,39 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids, rift_vnfd_id=None ) return openmano -def rift2openmano_vnfd_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids,rift_vnfd_id=None): - +def rift2openmano_vnfd_nsd(rift_nsd, rift_vnfds, rift_vnfd_id): if rift_vnfd_id not in rift_vnfds: - print ("IDS", rift_vnfds) - raise VNFNotFoundError("VNF id %s not provided" % rift_vnfd_id) + print ("IDS", rift_vnfds) + raise VNFNotFoundError("VNF id %s not provided" % rift_vnfd_id) openmano_vnfd_nsd = {} - openmano_vnfd_nsd["name"] = rift_vnfd_id+'__'+'scaling_group' + openmano_vnfd_nsd["name"] = rift_vnfd_id+'-'+'scaling_group' openmano_vnfd_nsd["description"] = "Scaling Group" topology = {} openmano_vnfd_nsd["topology"] = topology + + topology["nodes"] = {} + openmano_vnfd_nsd["topology"] = topology topology["connections"] = {} topology["nodes"] = {} - tst_index = [] - openmano_vnfd_id = openmano_vnfd_ids.get(rift_vnfd_id,None) - logger.debug("CONSTVNF %s", rift_nsd.constituent_vnfds) - 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 - } + topology["nodes"] = { + "type": "VNF", + "vnf_id": rift_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: + if not rit_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 @@ -379,7 +362,6 @@ def rift2openmano_vnfd_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids,rift_vnfd_id= ) 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 @@ -391,7 +373,7 @@ def cloud_init(rift_vnfd_id, vdu): 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 + # 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() @@ -420,9 +402,9 @@ def config_file_init(rift_vnfd_id, vdu, cfg_file): 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) + cfg_file_msg = cloud_init_extractor.read_script(stored_package, filename) except rift.package.cloud_init.CloudInitExtractionError as e: - raise ValueError(e) + raise ValueError(e) logger.debug("Current config file msg is {}".format(cfg_file_msg)) return cfg_file_msg @@ -494,7 +476,7 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): "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) @@ -505,7 +487,7 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): "description": vld.description, "type": "bridge", "elements": [], - } + } # Add the specific VDU connection points for int_cp in vld.internal_connection_point: @@ -513,7 +495,7 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): connection["elements"].append({ "VNFC": vdu.name, "local_iface_name": int_if.name, - }) + }) if "internal-connections" not in vnf: vnf["internal-connections"] = [] @@ -526,7 +508,7 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): "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 @@ -545,9 +527,9 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): 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":[], - }] + "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] @@ -558,9 +540,9 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): 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] - ) + vnfc["numas"][0]["paired-threads-id"].append( + [pair.thread_a, pair.thread_b] + ) else: if vdu.vm_flavor.has_field("vcpu_count"): @@ -595,7 +577,7 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): if vdu.has_field("volumes"): vnfc["devices"] = [] # Sort volumes as device-list is implictly ordered by Openmano - newvollist = sorted(vdu.volumes, key=lambda k: k.name) + newvollist = sorted(vdu.volumes, key=lambda k: k.name) for iter_num, volume in enumerate(newvollist): if iter_num == 0: # Convert the first volume to vnfc.image @@ -610,7 +592,7 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): device = {} device["type"] = volume.device_type device["image"] = volume.image - vnfc["devices"].append(device) + vnfc["devices"].append(device) vnfc_boot_data_init = False if vdu.has_field("cloud_init") or vdu.has_field("cloud_init_file"): @@ -632,14 +614,14 @@ def rift2openmano_vnfd(rift_vnfd, rift_nsd): cfg_source = config_file_init(rift_vnfd.id, vdu, custom_config_file.source) om_cfgfile_list.append({"dest":custom_config_file.dest, "content": cfg_source}) vnfc['boot-data']['config-files'] = om_cfgfile_list - + vnf["VNFC"].append(vnfc) for int_if in list(vdu.internal_interface) + list(vdu.external_interface): intf = { "name": int_if.name, - } + } if int_if.virtual_interface.has_field("vpci"): intf["vpci"] = int_if.virtual_interface.vpci @@ -694,14 +676,14 @@ def parse_args(argv=sys.argv[1:]): '-o', '--outdir', default='-', help="Directory to output converted descriptors. Default is stdout", - ) + ) parser.add_argument( '-n', '--nsd-file-hdl', metavar="nsd_file", type=argparse.FileType('r'), help="Rift NSD Descriptor File", - ) + ) parser.add_argument( '-v', '--vnfd-file-hdls', @@ -709,7 +691,7 @@ def parse_args(argv=sys.argv[1:]): action='append', type=argparse.FileType('r'), help="Rift VNFD Descriptor File", - ) + ) args = parser.parse_args(argv) @@ -744,6 +726,7 @@ def write_yaml_to_file(name, outdir, desc_dict): def main(argv=sys.argv[1:]): args = parse_args(argv) nsd = None + rift_vnfd_id = 'test_vnfd' openmano_vnfr_ids = dict() vnf_dict = None if args.vnfd_file_hdls is not None: @@ -766,4 +749,4 @@ def main(argv=sys.argv[1:]): if __name__ == "__main__": logging.basicConfig(level=logging.WARNING) - main() + main() \ No newline at end of file