adding external port to SDN-Assist when connected to WIM 21/7121/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 23 Jan 2019 10:19:23 +0000 (10:19 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 24 Jan 2019 16:24:38 +0000 (16:24 +0000)
Change-Id: Ic6902950915a8fde50d162cf425c1851e5bc001c
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
openmanod
osm_ro/nfvo.py
osm_ro/openmano_schemas.py
osm_ro/utils.py
osm_ro/vim_thread.py
osm_ro/wim/engine.py

index a4af12f..d6ae60c 100755 (executable)
--- a/openmanod
+++ b/openmanod
@@ -50,7 +50,7 @@ import osm_ro
 
 __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes"
 __date__ = "$26-aug-2014 11:09:29$"
-__version__ = "0.6.04"
+__version__ = "0.6.05"
 version_date = "Jan 2019"
 database_version = 36      # expected database schema version
 
index 4341422..4b7ecc4 100644 (file)
@@ -3205,13 +3205,15 @@ def create_instance(mydb, tenant_id, instance_dict):
 
             # --> WIM
             # TODO: use this information during network creation
-            wim_account_id = None
+            wim_account_id = wim_account_name = None
             if len(involved_datacenters) > 1 and 'uuid' in sce_net:
                 # OBS: sce_net without uuid are used internally to VNFs
                 # and the assumption is that VNFs will not be split among
                 # different datacenters
-                wim_account_id = wim_engine.find_suitable_wim_account(
+                wim_account = wim_engine.find_suitable_wim_account(
                     involved_datacenters, tenant_id)
+                wim_account_id = wim_account['uuid']
+                wim_account_name = wim_account['name']
                 wim_usage[sce_net['uuid']] = wim_account_id
             # <-- WIM
 
@@ -3303,7 +3305,7 @@ def create_instance(mydb, tenant_id, instance_dict):
                 task_extra = {}
                 if create_network:
                     task_action = "CREATE"
-                    task_extra["params"] = (net_vim_name, net_type, sce_net.get('ip_profile', None))
+                    task_extra["params"] = (net_vim_name, net_type, sce_net.get('ip_profile', None), wim_account_name)
                     if lookfor_network:
                         task_extra["find"] = (lookfor_filter,)
                 elif lookfor_network:
@@ -5550,9 +5552,8 @@ def datacenter_sdn_port_mapping_set(mydb, tenant_id, datacenter_id, sdn_port_map
             pci = port.get("pci")
             element["switch_port"] = port.get("switch_port")
             element["switch_mac"] = port.get("switch_mac")
-            if not pci or not (element["switch_port"] or element["switch_mac"]):
-                raise NfvoException ("The mapping must contain the 'pci' and at least one of the elements 'switch_port'"
-                                     " or 'switch_mac'", httperrors.Bad_Request)
+            if not element["switch_port"] and not element["switch_mac"]:
+                raise NfvoException ("The mapping must contain 'switch_port' or 'switch_mac'", httperrors.Bad_Request)
             for pci_expanded in utils.expand_brackets(pci):
                 element["pci"] = pci_expanded
                 maps.append(dict(element))
index b53bbac..80795b5 100644 (file)
@@ -1224,7 +1224,7 @@ sdn_port_mapping_schema  = {
                         "items": {
                             "type": "object",
                             "properties": {
-                                "pci": pci_extended_schema,       # pci_schema,
+                                "pci": {"OneOf": [{"type": "null"}, pci_extended_schema]},       # pci_schema,
                                 "switch_port": nameshort_schema,
                                 "switch_mac": mac_schema
                             },
index 2afbc85..1e3a8ee 100644 (file)
@@ -225,6 +225,8 @@ def expand_brackets(text):
     :param text:
     :return:
     """
+    if text is None:
+        return (None, )
     start = text.find("[")
     end = text.find("]")
     if start < 0 or end < 0:
index f7bc40b..57ced9c 100644 (file)
@@ -160,6 +160,10 @@ class vim_thread(threading.Thread):
             vim_config['datacenter_tenant_id'] = vim.get('datacenter_tenant_id')
             vim_config['datacenter_id'] = vim.get('datacenter_id')
 
+            # get port_mapping
+            vim_config["wim_external_ports"] = self.ovim.get_of_port_mappings(
+                db_filter={"region": vim_config['datacenter_id'], "pci": None})
+
             self.vim = vim_module[vim["type"]].vimconnector(
                 uuid=vim['datacenter_id'], name=vim['datacenter_name'],
                 tenant_id=vim['vim_tenant_id'], tenant_name=vim['vim_tenant_name'],
@@ -995,10 +999,11 @@ class vim_thread(threading.Thread):
             # CREATE
             params = task["params"]
             action_text = "creating VIM"
-            vim_net_id = self.vim.new_network(*params)
+            vim_net_id = self.vim.new_network(*params[0:2])
 
             net_name = params[0]
             net_type = params[1]
+            wim_account_name = params[3]
 
             sdn_controller = self.vim.config.get('sdn-controller')
             if sdn_controller and (net_type == "data" or net_type == "ptp"):
@@ -1013,6 +1018,28 @@ class vim_thread(threading.Thread):
                 action_text = "creating SDN"
                 with self.db_lock:
                     sdn_net_id = self.ovim.new_network(network)
+
+                if wim_account_name and self.vim.config["wim_external_ports"]:
+                    # add external port to connect WIM. Try with compute node __WIM:wim_name and __WIM
+                    action_text = "attaching external port to ovim network"
+                    sdn_port_name = sdn_net_id + "." + task["vim_id"]
+                    sdn_port_name = sdn_port_name[:63]
+                    sdn_port_data = {
+                        "compute_node": "__WIM:" + wim_account_name[0:58],
+                        "pci": None,
+                        "vlan": network["vlan"],
+                        "net_id": sdn_net_id,
+                        "region": self.vim["config"]["datacenter_id"],
+                        "name": sdn_port_name,
+                    }
+                    try:
+                        sdn_external_port_id = self.ovim.new_external_port(sdn_port_data)
+                    except ovimException:
+                        sdn_port_data["compute_node"] = "__WIM"
+                        sdn_external_port_id = self.ovim.new_external_port(sdn_port_data)
+                    self.logger.debug("Added sdn_external_port {} to sdn_network {}".format(sdn_external_port_id,
+                                                                                            sdn_net_id))
+
             task["status"] = "DONE"
             task["extra"]["vim_info"] = {}
             task["extra"]["sdn_net_id"] = sdn_net_id
index 6ff2b4f..39defb1 100644 (file)
@@ -322,11 +322,11 @@ class WimEngine(object):
             tenant (str): UUID of the OSM tenant
 
         Returns:
-            str: UUID of the WIM account that is able to connect all the
+            object with the WIM account that is able to connect all the
                  datacenters.
         """
         wim_id = self.find_common_wim(datacenter_ids, tenant)
-        return self.persist.get_wim_account_by(wim_id, tenant)['uuid']
+        return self.persist.get_wim_account_by(wim_id, tenant)
 
     def derive_wan_link(self,
                         wim_usage,