From edf3f4ff2f40145915964a7750dae56d6de21479 Mon Sep 17 00:00:00 2001 From: tierno Date: Thu, 17 May 2018 23:02:47 +0200 Subject: [PATCH] Allow sdn-port-mapping insertion at vim creation with config:sdn-port-mapping Change-Id: I9b262e5737543198b388438426c0e6e101512078 Signed-off-by: tierno --- openmanod | 2 +- osm_ro/httpserver.py | 2 +- osm_ro/nfvo.py | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/openmanod b/openmanod index fab9d0a7..14691d32 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.63-r573" +__version__ = "0.5.64-r574" version_date = "May 2018" database_version = 31 # expected database schema version diff --git a/osm_ro/httpserver.py b/osm_ro/httpserver.py index 0497bbac..6c7e720f 100644 --- a/osm_ro/httpserver.py +++ b/osm_ro/httpserver.py @@ -1551,7 +1551,7 @@ def http_get_instance_id(tenant_id, instance_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.warn("nfvo.refresh_instance couldn't refresh the status of the instance: %s" % str(e)) # obtain data with results upated - instance = mydb.get_instance_scenario(instance_id, tenant_id) + instance = mydb.get_instance_scenario(instance_id, tenant_id, verbose=True) # Workaround to SO, convert vnfs:vms:interfaces:ip_address from ";" separated list to report the first value for vnf in instance.get("vnfs", ()): for vm in vnf.get("vms", ()): diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index d8cd9803..7a3e959e 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -4358,21 +4358,31 @@ def delete_tenant(mydb, tenant): def new_datacenter(mydb, datacenter_descriptor): if "config" in datacenter_descriptor: - datacenter_descriptor["config"]=yaml.safe_dump(datacenter_descriptor["config"],default_flow_style=True,width=256) - #Check that datacenter-type is correct + sdn_port_mapping = datacenter_descriptor["config"].pop("sdn-port-mapping", None) + datacenter_descriptor["config"] = yaml.safe_dump(datacenter_descriptor["config"], default_flow_style=True, + width=256) + # Check that datacenter-type is correct datacenter_type = datacenter_descriptor.get("type", "openvim"); - module_info = None + # module_info = None try: module = "vimconn_" + datacenter_type pkg = __import__("osm_ro." + module) - vim_conn = getattr(pkg, module) + # vim_conn = getattr(pkg, module) # module_info = imp.find_module(module, [__file__[:__file__.rfind("/")]]) except (IOError, ImportError): # if module_info and module_info[0]: # file.close(module_info[0]) - raise NfvoException("Incorrect datacenter type '{}'. Plugin '{}.py' not installed".format(datacenter_type, module), HTTP_Bad_Request) + raise NfvoException("Incorrect datacenter type '{}'. Plugin '{}.py' not installed".format(datacenter_type, + module), + HTTP_Bad_Request) datacenter_id = mydb.new_row("datacenters", datacenter_descriptor, add_uuid=True, confidential_data=True) + if sdn_port_mapping: + try: + datacenter_sdn_port_mapping_set(mydb, None, datacenter_id, sdn_port_mapping) + except Exception as e: + mydb.delete_row_by_id("datacenters", datacenter_id) # Rollback + raise e return datacenter_id @@ -4384,10 +4394,14 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor): datacenter_id = datacenter['uuid'] where={'uuid': datacenter['uuid']} remove_port_mapping = False + new_sdn_port_mapping = None if "config" in datacenter_descriptor: if datacenter_descriptor['config'] != None: try: new_config_dict = datacenter_descriptor["config"] + if "sdn-port-mapping" in new_config_dict: + remove_port_mapping = True + new_sdn_port_mapping = new_config_dict.pop("sdn-port-mapping") #delete null fields to_delete=[] for k in new_config_dict: @@ -4417,6 +4431,11 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor): logger.error("Error deleting datacenter-port-mapping " + str(e)) mydb.update_rows('datacenters', datacenter_descriptor, where) + if new_sdn_port_mapping: + try: + datacenter_sdn_port_mapping_set(mydb, None, datacenter_id, new_sdn_port_mapping) + except ovimException as e: + logger.error("Error adding datacenter-port-mapping " + str(e)) return datacenter_id -- 2.25.1