Delete sdn-port-mapping upon datancenter deletion or sdn remove 26/2026/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 11 Jul 2017 11:50:04 +0000 (13:50 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 11 Jul 2017 11:51:31 +0000 (13:51 +0200)
Change-Id: I53da6a67422bf4eccfab1685617ffc8c0b01d2c6
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
openmano
openmanod
osm_ro/nfvo.py

index 1b88373..ec588a9 100755 (executable)
--- a/openmano
+++ b/openmano
@@ -1123,8 +1123,13 @@ def sdn_controller_create(args):
     tenant = _get_tenant()
     headers_req = {'Accept': 'application/json', 'content-type': 'application/json'}
 
-    if not (args.ip and args.port and args.dpid and args.type):
-        raise OpenmanoCLIError("The following arguments are required: ip, port, dpid, type")
+    error_msg=[]
+    if not args.ip: error_msg.append("'ip'")
+    if not args.port: error_msg.append("'port'")
+    if not args.dpid: error_msg.append("'dpid'")
+    if not args.type: error_msg.append("'type'")
+    if error_msg:
+        raise OpenmanoCLIError("The following arguments are required: " + ",".join(error_msg))
 
     controller_dict = {}
     controller_dict['name'] = args.name
index 79f93bd..fbd8e2e 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.16-r525"
+__version__ = "0.5.17-r526"
 version_date = "Jul 2017"
 database_version = 22      #expected database schema version
 
index d45a3c7..f542df6 100644 (file)
@@ -2789,20 +2789,24 @@ def new_datacenter(mydb, datacenter_descriptor):
 
 
 def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor):
-    #obtain data, check that only one exist
+    # obtain data, check that only one exist
     datacenter = mydb.get_table_by_uuid_name('datacenters', datacenter_id_name)
-    #edit data
+
+    # edit data
     datacenter_id = datacenter['uuid']
     where={'uuid': datacenter['uuid']}
+    remove_port_mapping = False
     if "config" in datacenter_descriptor:
-        if datacenter_descriptor['config']!=None:
+        if datacenter_descriptor['config'] != None:
             try:
                 new_config_dict = datacenter_descriptor["config"]
                 #delete null fields
                 to_delete=[]
                 for k in new_config_dict:
-                    if new_config_dict[k]==None:
+                    if new_config_dict[k] == None:
                         to_delete.append(k)
+                        if k == 'sdn-controller':
+                            remove_port_mapping = True
 
                 config_text = datacenter.get("config")
                 if not config_text:
@@ -2814,7 +2818,16 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor):
                     del config_dict[k]
             except Exception as e:
                 raise NfvoException("Bad format at datacenter:config " + str(e), HTTP_Bad_Request)
-        datacenter_descriptor["config"]= yaml.safe_dump(config_dict,default_flow_style=True,width=256) if len(config_dict)>0 else None
+        if config_dict:
+            datacenter_descriptor["config"] = yaml.safe_dump(config_dict, default_flow_style=True, width=256)
+        else:
+            datacenter_descriptor["config"] = None
+        if remove_port_mapping:
+            try:
+                datacenter_sdn_port_mapping_delete(mydb, None, datacenter_id)
+            except ovimException as e:
+                logger.error("Error deleting datacenter-port-mapping " + str(e))
+
     mydb.update_rows('datacenters', datacenter_descriptor, where)
     return datacenter_id
 
@@ -2823,6 +2836,10 @@ def delete_datacenter(mydb, datacenter):
     #get nfvo_tenant info
     datacenter_dict = mydb.get_table_by_uuid_name('datacenters', datacenter, 'datacenter')
     mydb.delete_row_by_id("datacenters", datacenter_dict['uuid'])
+    try:
+        datacenter_sdn_port_mapping_delete(mydb, None, datacenter_dict['uuid'])
+    except ovimException as e:
+        logger.error("Error deleting datacenter-port-mapping " + str(e))
     return datacenter_dict['uuid'] + " " + datacenter_dict['name']