From 7fe82640f590cc66a9b11adf0d25abceedf892de Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 26 Nov 2018 14:14:51 +0000 Subject: [PATCH] Allow instance of only networks without scenario Change-Id: I442fba52604a3211d2f07a04fff39ce5d3320325 Signed-off-by: tierno --- openmano | 7 ++++--- openmanod | 2 +- osm_ro/nfvo.py | 30 ++++++++++++++++++++---------- osm_ro/openmano_schemas.py | 26 +++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/openmano b/openmano index 2434f952..357b91ad 100755 --- a/openmano +++ b/openmano @@ -28,8 +28,8 @@ openmano client used to interact with openmano-server (openmanod) """ __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ = "$09-oct-2014 09:09:48$" -__version__ = "0.4.23-r533" -version_date = "May 2018" +__version__ = "0.4.24-r534" +version_date = "Nov 2018" from argcomplete.completers import FilesCompleter import os @@ -693,7 +693,8 @@ def instance_create(args): if not scenario: print "you must provide a scenario in the file descriptor or with --scenario" return -1 - myInstance["instance"]["scenario"] = _get_item_uuid("scenarios", scenario, tenant) + if isinstance(scenario, str): + myInstance["instance"]["scenario"] = _get_item_uuid("scenarios", scenario, tenant) if args.netmap_use: if "networks" not in myInstance["instance"]: myInstance["instance"]["networks"] = {} diff --git a/openmanod b/openmanod index 8dcb0f39..c04d66ac 100755 --- a/openmanod +++ b/openmanod @@ -48,7 +48,7 @@ import osm_ro __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ = "$26-aug-2014 11:09:29$" -__version__ = "0.5.83-r593" +__version__ = "0.5.84-r594" version_date = "Nov 2018" database_version = 33 # expected database schema version diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 01ac0175..0c8cef65 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -2940,8 +2940,12 @@ def create_instance(mydb, tenant_id, instance_dict): rollbackList = [] # print "Checking that the scenario exists and getting the scenario dictionary" - scenarioDict = mydb.get_scenario(scenario, tenant_id, datacenter_vim_id=myvim_threads_id[default_datacenter_id], - datacenter_id=default_datacenter_id) + if isinstance(scenario, str): + scenarioDict = mydb.get_scenario(scenario, tenant_id, datacenter_vim_id=myvim_threads_id[default_datacenter_id], + datacenter_id=default_datacenter_id) + else: + scenarioDict = scenario + scenarioDict["uuid"] = None # logger.debug(">>>>>> Dictionaries before merging") # logger.debug(">>>>>> InstanceDict:\n{}".format(yaml.safe_dump(instance_dict,default_flow_style=False, width=256))) @@ -3112,9 +3116,10 @@ def create_instance(mydb, tenant_id, instance_dict): number_mgmt_networks = 0 db_instance_nets = [] for sce_net in scenarioDict['nets']: + sce_net_uuid = sce_net.get('uuid', sce_net["name"]) # get involved datacenters where this network need to be created involved_datacenters = [] - for sce_vnf in scenarioDict.get("vnfs"): + for sce_vnf in scenarioDict.get("vnfs", ()): vnf_datacenter = sce_vnf.get("datacenter", default_datacenter_id) if vnf_datacenter in involved_datacenters: continue @@ -3130,8 +3135,13 @@ def create_instance(mydb, tenant_id, instance_dict): if instance_dict.get("networks") and instance_dict["networks"].get(sce_net["name"]): descriptor_net = instance_dict["networks"][sce_net["name"]] net_name = descriptor_net.get("vim-network-name") - sce_net2instance[sce_net['uuid']] = {} - net2task_id['scenario'][sce_net['uuid']] = {} + # add datacenters from instantiation parameters + if descriptor_net.get("sites"): + for site in descriptor_net["sites"]: + if site.get("datacenter") and site["datacenter"] not in involved_datacenters: + involved_datacenters.append(site["datacenter"]) + sce_net2instance[sce_net_uuid] = {} + net2task_id['scenario'][sce_net_uuid] = {} if sce_net["external"]: number_mgmt_networks += 1 @@ -3219,13 +3229,13 @@ def create_instance(mydb, tenant_id, instance_dict): # fill database content net_uuid = str(uuid4()) uuid_list.append(net_uuid) - sce_net2instance[sce_net['uuid']][datacenter_id] = net_uuid + sce_net2instance[sce_net_uuid][datacenter_id] = net_uuid db_net = { "uuid": net_uuid, 'vim_net_id': None, "vim_name": net_vim_name, "instance_scenario_id": instance_uuid, - "sce_net_id": sce_net["uuid"], + "sce_net_id": sce_net.get("uuid"), "created": create_network, 'datacenter_id': datacenter_id, 'datacenter_tenant_id': myvim_thread_id, @@ -3242,7 +3252,7 @@ def create_instance(mydb, tenant_id, instance_dict): "item_id": net_uuid, "extra": yaml.safe_dump(task_extra, default_flow_style=True, width=256) } - net2task_id['scenario'][sce_net['uuid']][datacenter_id] = task_index + net2task_id['scenario'][sce_net_uuid][datacenter_id] = task_index task_index += 1 db_vim_actions.append(db_vim_action) @@ -3284,14 +3294,14 @@ def create_instance(mydb, tenant_id, instance_dict): "sce_net2instance": sce_net2instance, } # sce_vnf_list = sorted(scenarioDict['vnfs'], key=lambda k: k['name']) - for sce_vnf in scenarioDict.get('vnfs'): # sce_vnf_list: + for sce_vnf in scenarioDict.get('vnfs', ()): # sce_vnf_list: instantiate_vnf(mydb, sce_vnf, vnf_params, vnf_params_out, rollbackList) task_index = vnf_params_out["task_index"] uuid_list = vnf_params_out["uuid_list"] # Create VNFFGs # task_depends_on = [] - for vnffg in scenarioDict['vnffgs']: + for vnffg in scenarioDict.get('vnffgs', ()): for rsp in vnffg['rsps']: sfs_created = [] for cp in rsp['connection_points']: diff --git a/osm_ro/openmano_schemas.py b/osm_ro/openmano_schemas.py index f717a4a6..4a7d5f59 100644 --- a/osm_ro/openmano_schemas.py +++ b/osm_ro/openmano_schemas.py @@ -963,6 +963,30 @@ scenario_action_schema = { "additionalProperties": False } +instance_scenario_object = { + "title": "scenario object used to create an instance not based on any nsd", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "nets": { + "type": "array", + "minLength": 1, + "items": { + "type": "object", + "properties": { + "name": name_schema, + "external": {"type": "boolean"}, + "type": {"enum": ["bridge", "ptp", "data"]}, # for overlay, underlay E-LINE, underlay E-LAN + }, + "additionalProperties": False, + "required": ["name", "external", "type"] + } + } + }, + "additionalProperties": False, + "required": ["nets"] +} + instance_scenario_create_schema_v01 = { "title": "instance scenario create information schema v0.1", "$schema": "http://json-schema.org/draft-04/schema#", @@ -977,7 +1001,7 @@ instance_scenario_create_schema_v01 = { "name": name_schema, "description":description_schema, "datacenter": name_schema, - "scenario" : name_schema, #can be an UUID or name + "scenario" : {"oneOff": [name_schema, instance_scenario_object]}, # can be an UUID or name or a dict "action":{"enum": ["deploy","reserve","verify" ]}, "connect_mgmt_interfaces": {"oneOf": [{"type":"boolean"}, {"type":"object"}]},# can be true or a dict with datacenter: net_name "cloud-config": cloud_config_schema, #common to all vnfs in the instance scenario -- 2.25.1