Allow sdn-port-mapping insertion at vim creation with config:sdn-port-mapping 70/6170/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 17 May 2018 21:02:47 +0000 (23:02 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 18 May 2018 13:15:14 +0000 (15:15 +0200)
Change-Id: I9b262e5737543198b388438426c0e6e101512078
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
openmanod
osm_ro/httpserver.py
osm_ro/nfvo.py

index fab9d0a..14691d3 100755 (executable)
--- 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
 
index 0497bba..6c7e720 100644 (file)
@@ -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", ()):
index d8cd980..7a3e959 100644 (file)
@@ -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