From 7f426e900d00a76c3d583839f299982bbaf4c317 Mon Sep 17 00:00:00 2001 From: tierno Date: Thu, 28 Jun 2018 15:21:32 +0200 Subject: [PATCH] Enhance sdn-assist reporting Change-Id: I77d4600bc45f0eb64c849d38a4246df24c276707 Signed-off-by: tierno --- osm_ro/httpserver.py | 12 ++++-------- osm_ro/nfvo.py | 31 +++++++++++++++++++++++++++---- osm_ro/openmano_schemas.py | 4 +++- osm_ro/utils.py | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/osm_ro/httpserver.py b/osm_ro/httpserver.py index 6c7e720f..381016c6 100644 --- a/osm_ro/httpserver.py +++ b/osm_ro/httpserver.py @@ -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", ()): diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 0b0dab31..7c5870ce 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -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) diff --git a/osm_ro/openmano_schemas.py b/osm_ro/openmano_schemas.py index f4cbcc8e..dc3c9bf1 100644 --- a/osm_ro/openmano_schemas.py +++ b/osm_ro/openmano_schemas.py @@ -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 }, diff --git a/osm_ro/utils.py b/osm_ro/utils.py index 00f6f2d2..c7d966e7 100644 --- a/osm_ro/utils.py +++ b/osm_ro/utils.py @@ -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 -- 2.17.1