Enhance sdn-assist reporting 08/6308/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 28 Jun 2018 13:21:32 +0000 (15:21 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 2 Jul 2018 08:12:12 +0000 (10:12 +0200)
Change-Id: I77d4600bc45f0eb64c849d38a4246df24c276707
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_ro/httpserver.py
osm_ro/nfvo.py
osm_ro/openmano_schemas.py
osm_ro/utils.py

index 6c7e720..381016c 100644 (file)
@@ -1539,19 +1539,15 @@ def http_get_instance_id(tenant_id, instance_id):
     '''get instances details, can use both uuid or name'''
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     try:
+
         #check valid tenant_id
         if tenant_id != "any":
             nfvo.check_tenant(mydb, tenant_id) 
         if tenant_id == "any":
             tenant_id = None
-        #obtain data (first time is only to check that the instance exists)
-        instance_dict = mydb.get_instance_scenario(instance_id, tenant_id, verbose=True)
-        try:
-            nfvo.refresh_instance(mydb, tenant_id, instance_dict)
-        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, verbose=True)
+
+        instance = nfvo.get_instance_id(mydb, tenant_id, instance_id)
+
         # 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 0b0dab3..7c5870c 100644 (file)
@@ -3540,7 +3540,8 @@ def instantiate_vnf(mydb, sce_vnf, params, params_out, rollbackList):
 
     for vm in sce_vnf['vms']:
         myVMDict = {}
-        myVMDict['name'] = "{}.{}.{}".format(instance_name[:64], sce_vnf['name'][:64], vm["name"][:64])
+        sce_vnf_name = sce_vnf['member_vnf_index'] if sce_vnf['member_vnf_index'] else sce_vnf['name']
+        myVMDict['name'] = "{}-{}-{}".format(instance_name[:64], sce_vnf_name[:64], vm["name"][:64])
         myVMDict['description'] = myVMDict['name'][0:99]
         #                if not startvms:
         #                    myVMDict['start'] = "no"
@@ -4024,6 +4025,26 @@ def delete_instance(mydb, tenant_id, instance_id):
     else:
         return "action_id={} instance {} deleted".format(instance_action_id, message)
 
+def get_instance_id(mydb, tenant_id, instance_id):
+    global ovim
+    #check valid tenant_id
+    check_tenant(mydb, tenant_id)
+    #obtain data
+
+    instance_dict = mydb.get_instance_scenario(instance_id, tenant_id, verbose=True)
+    for net in instance_dict["nets"]:
+        if net.get("sdn_net_id"):
+            net_sdn = ovim.show_network(net["sdn_net_id"])
+            net["sdn_info"] = {
+                "admin_state_up": net_sdn.get("admin_state_up"),
+                "flows": net_sdn.get("flows"),
+                "last_error": net_sdn.get("last_error"),
+                "ports": net_sdn.get("ports"),
+                "type": net_sdn.get("type"),
+                "status": net_sdn.get("status"),
+                "vlan": net_sdn.get("vlan"),
+            }
+    return instance_dict
 
 def refresh_instance(mydb, nfvo_tenant, instanceDict, datacenter=None, vim_tenant=None):
     '''Refreshes a scenario instance. It modifies instanceDict'''
@@ -5078,13 +5099,15 @@ def datacenter_sdn_port_mapping_set(mydb, tenant_id, datacenter_id, sdn_port_map
         element = dict()
         element["compute_node"] = compute_node["compute_node"]
         for port in compute_node["ports"]:
-            element["pci"] = port.get("pci")
+            pci = port.get("pci")
             element["switch_port"] = port.get("switch_port")
             element["switch_mac"] = port.get("switch_mac")
-            if not element["pci"] or not (element["switch_port"] or element["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'", HTTP_Bad_Request)
-            maps.append(dict(element))
+            for pci_expanded in utils.expand_brackets(pci):
+                element["pci"] = pci_expanded
+                maps.append(dict(element))
 
     return ovim.set_of_port_mapping(maps, ofc_id=sdn_controller_id, switch_dpid=switch_dpid, region=datacenter_id)
 
index f4cbcc8..dc3c9bf 100644 (file)
@@ -37,6 +37,8 @@ description_schema={"type" : ["string","null"], "maxLength":255, "pattern" : "^[
 id_schema_fake = {"type" : "string", "minLength":2, "maxLength":36 }  #"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
 id_schema = {"type" : "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
 pci_schema={"type":"string", "pattern":"^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
+pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\[\]]$"}
+
 http_schema={"type":"string", "pattern":"^https?://[^'\"=]+$"}
 bandwidth_schema={"type":"string", "pattern" : "^[0-9]+ *([MG]bps)?$"}
 memory_schema={"type":"string", "pattern" : "^[0-9]+ *([MG]i?[Bb])?$"}
@@ -1190,7 +1192,7 @@ sdn_port_mapping_schema  = {
                         "items": {
                             "type": "object",
                             "properties": {
-                                "pci": pci_schema,
+                                "pci": pci_extended_schema,       # pci_schema,
                                 "switch_port": nameshort_schema,
                                 "switch_mac": mac_schema
                             },
index 00f6f2d..c7d966e 100644 (file)
@@ -178,4 +178,21 @@ def check_valid_uuid(uuid):
         except js_e.ValidationError:
             return False
     return False
-    
+
+
+def expand_brackets(text):
+    """
+    Change a text with TEXT[ABC..] into a list with [TEXTA, TEXTB, TEXC, ...
+    if no bracket is used it just return the a list with the single text
+    It uses recursivity to allow several [] in the text
+    :param text:
+    :return:
+    """
+    start = text.find("[")
+    end = text.find("]")
+    if start < 0 or end < 0:
+        return [text]
+    text_list = []
+    for char in text[start+1:end]:
+        text_list += expand_brackets(text[:start] + char + text[end+1:])
+    return text_list