From 8fe7a49a2ebefd5f9cf0454555c52591b525b16d Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 11 Jul 2017 13:50:04 +0200 Subject: [PATCH] Delete sdn-port-mapping upon datancenter deletion or sdn remove Change-Id: I53da6a67422bf4eccfab1685617ffc8c0b01d2c6 Signed-off-by: tierno --- openmano | 9 +++++++-- openmanod | 2 +- osm_ro/nfvo.py | 27 ++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/openmano b/openmano index 1b88373a..ec588a98 100755 --- 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 diff --git a/openmanod b/openmanod index 79f93bd8..fbd8e2e2 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.16-r525" +__version__ = "0.5.17-r526" version_date = "Jul 2017" database_version = 22 #expected database schema version diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index d45a3c79..f542df63 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -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'] -- 2.25.1