#1.2: Check that VNF are present at database table vnfs. Insert uuid, description and external interfaces
for name,vnf in vnfs.items():
- WHERE_={}
+ where={}
+ where_or={"tenant_id": tenant_id, 'public': "true"}
error_text = ""
error_pos = "'topology':'nodes':'" + name + "'"
if 'vnf_id' in vnf:
error_text += " 'vnf_id' " + vnf['vnf_id']
- WHERE_['uuid'] = vnf['vnf_id']
+ where['uuid'] = vnf['vnf_id']
if 'VNF model' in vnf:
error_text += " 'VNF model' " + vnf['VNF model']
- WHERE_['name'] = vnf['VNF model']
- if len(WHERE_) == 0:
+ where['name'] = vnf['VNF model']
+ if len(where) == 0:
raise NfvoException("Descriptor need a 'vnf_id' or 'VNF model' field at " + error_pos, HTTP_Bad_Request)
- vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), FROM='vnfs', WHERE=WHERE_)
+ vnf_db = mydb.get_rows(SELECT=('uuid','name','description'),
+ FROM='vnfs',
+ WHERE=where,
+ WHERE_OR=where_or,
+ WHERE_AND_OR="AND")
if len(vnf_db)==0:
raise NfvoException("unknown" + error_text + " at " + error_pos, HTTP_Not_Found)
elif len(vnf_db)>1:
#1: Check that VNF are present at database table vnfs and update content into scenario dict
for name,vnf in scenario["vnfs"].iteritems():
- WHERE_={}
+ where={}
+ where_or={"tenant_id": tenant_id, 'public': "true"}
error_text = ""
error_pos = "'topology':'nodes':'" + name + "'"
if 'vnf_id' in vnf:
error_text += " 'vnf_id' " + vnf['vnf_id']
- WHERE_['uuid'] = vnf['vnf_id']
+ where['uuid'] = vnf['vnf_id']
if 'vnf_name' in vnf:
error_text += " 'vnf_name' " + vnf['vnf_name']
- WHERE_['name'] = vnf['vnf_name']
- if len(WHERE_) == 0:
+ where['name'] = vnf['vnf_name']
+ if len(where) == 0:
raise NfvoException("Needed a 'vnf_id' or 'VNF model' at " + error_pos, HTTP_Bad_Request)
- vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), FROM='vnfs', WHERE=WHERE_)
+ vnf_db = mydb.get_rows(SELECT=('uuid','name','description'),
+ FROM='vnfs',
+ WHERE=where,
+ WHERE_OR=where_or,
+ WHERE_AND_OR="AND")
if len(vnf_db)==0:
raise NfvoException("Unknown" + error_text + " at " + error_pos, HTTP_Not_Found)
elif len(vnf_db)>1:
try:
data = myvim.action_vminstance(vm['vim_vm_id'], action_dict)
if "console" in action_dict:
- if data["server"]=="127.0.0.1" or data["server"]=="localhost":
+ if not global_config["http_console_proxy"]:
+ vm_result[ vm['uuid'] ] = {"vim_result": 200,
+ "description": "{protocol}//{ip}:{port}/{suffix}".format(
+ protocol=data["protocol"],
+ ip = data["server"],
+ port = data["port"],
+ suffix = data["suffix"]),
+ "name":vm['name']
+ }
+ vm_ok +=1
+ elif data["server"]=="127.0.0.1" or data["server"]=="localhost":
vm_result[ vm['uuid'] ] = {"vim_result": -HTTP_Unauthorized,
"description": "this console is only reachable by local interface",
"name":vm['name']
}
vm_error+=1
- continue
+ else:
#print "console data", data
- try:
- console_thread = create_or_use_console_proxy_thread(data["server"], data["port"])
- vm_result[ vm['uuid'] ] = {"vim_result": 200,
- "description": "%s//%s:%d/%s" %(data["protocol"], console_thread.host, console_thread.port, data["suffix"]),
- "name":vm['name']
- }
- vm_ok +=1
- except NfvoException as e:
- vm_result[ vm['uuid'] ] = {"vim_result": e.http_code, "name":vm['name'], "description": str(e)}
+ try:
+ console_thread = create_or_use_console_proxy_thread(data["server"], data["port"])
+ vm_result[ vm['uuid'] ] = {"vim_result": 200,
+ "description": "{protocol}//{ip}:{port}/{suffix}".format(
+ protocol=data["protocol"],
+ ip = global_config["http_console_host"],
+ port = console_thread.port,
+ suffix = data["suffix"]),
+ "name":vm['name']
+ }
+ vm_ok +=1
+ except NfvoException as e:
+ vm_result[ vm['uuid'] ] = {"vim_result": e.http_code, "name":vm['name'], "description": str(e)}
+ vm_error+=1
+
else:
vm_result[ vm['uuid'] ] = {"vim_result": 200, "description": "ok", "name":vm['name']}
vm_ok +=1
vm_error+=1
if vm_ok==0: #all goes wrong
- return 1, vm_result
+ return vm_result
else:
- return 1, vm_result
+ return vm_result
def create_or_use_console_proxy_thread(console_server, console_port):
#look for a non-used port
return global_config["console_thread"][console_thread_key]
for port in global_config["console_port_iterator"]():
- print "create_or_use_console_proxy_thread() port:", port
+ #print "create_or_use_console_proxy_thread() port:", port
if port in global_config["console_ports"]:
continue
try: