'''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", ()):
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"
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'''
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)
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])?$"}
"items": {
"type": "object",
"properties": {
- "pci": pci_schema,
+ "pci": pci_extended_schema, # pci_schema,
"switch_port": nameshort_schema,
"switch_mac": mac_schema
},
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