- #create flavor at vim in case it not exist
- res, flavor_dict = mydb.get_table_by_uuid_name("flavors", vm['flavor_id'])
- if res<0:
- print "start_scenario error getting flavor", flavor_dict
- return res, flavor_dict
- if flavor_dict['extended']!=None:
- flavor_dict['extended']= yaml.load(flavor_dict['extended'])
- res, flavor_id = create_or_use_flavor(mydb, vims, flavor_dict, [], True)
- if res < 0:
- print "start_scenario error adding flavor to VIM", flavor_dict
- return res, flavor_id
- vm['vim_flavor_id'] = flavor_id
-
-
- myVMDict['imageRef'] = vm['vim_image_id']
- myVMDict['flavorRef'] = vm['vim_flavor_id']
- myVMDict['networks'] = []
- for iface in vm['interfaces']:
- netDict = {}
- if iface['type']=="data":
- netDict['type'] = iface['model']
- elif "model" in iface and iface["model"]!=None:
- netDict['model']=iface['model']
- #TODO in future, remove this because mac_address will not be set, and the type of PV,VF is obtained from iterface table model
- #discover type of interface looking at flavor
- for numa in flavor_dict.get('extended',{}).get('numas',[]):
- for flavor_iface in numa.get('interfaces',[]):
- if flavor_iface.get('name') == iface['internal_name']:
- if flavor_iface['dedicated'] == 'yes':
- netDict['type']="PF" #passthrough
- elif flavor_iface['dedicated'] == 'no':
- netDict['type']="VF" #siov
- elif flavor_iface['dedicated'] == 'yes:sriov':
- netDict['type']="VFnotShared" #sriov but only one sriov on the PF
- netDict["mac_address"] = flavor_iface.get("mac_address")
- break;
- netDict["use"]=iface['type']
- if netDict["use"]=="data" and not netDict.get("type"):
- #print "netDict", netDict
- #print "iface", iface
- e_text = "Cannot determine the interface type PF or VF of VNF '%s' VM '%s' iface '%s'" %(sce_vnf['name'], vm['name'], iface['internal_name'])
- if flavor_dict.get('extended')==None:
- return -HTTP_Conflict, e_text + "After database migration some information is not available. \
- Try to delete and create the scenarios and VNFs again"
- else:
- return -HTTP_Internal_Server_Error, e_text
- if netDict["use"]=="mgmt" or netDict["use"]=="bridge":
- netDict["type"]="virtual"
- if "vpci" in iface and iface["vpci"] is not None:
- netDict['vpci'] = iface['vpci']
- if "mac" in iface and iface["mac"] is not None:
- netDict['mac_address'] = iface['mac']
- netDict['name'] = iface['internal_name']
- if iface['net_id'] is None:
- for vnf_iface in sce_vnf["interfaces"]:
- print iface
- print vnf_iface
- if vnf_iface['interface_id']==iface['uuid']:
- netDict['net_id'] = auxNetDict['scenario'][ vnf_iface['sce_net_id'] ]
- break
- else:
- netDict['net_id'] = auxNetDict[ sce_vnf['uuid'] ][ iface['net_id'] ]
- #skip bridge ifaces not connected to any net
- #if 'net_id' not in netDict or netDict['net_id']==None:
- # continue
- myVMDict['networks'].append(netDict)
- print ">>>>>>>>>>>>>>>>>>>>>>>>>>>"
- print myVMDict['name']
- print "networks", yaml.safe_dump(myVMDict['networks'], indent=4, default_flow_style=False)
- print "interfaces", yaml.safe_dump(vm['interfaces'], indent=4, default_flow_style=False)
- print ">>>>>>>>>>>>>>>>>>>>>>>>>>>"
- result, vm_id = myvim.new_tenant_vminstance(myVMDict['name'],myVMDict['description'],myVMDict.get('start', None),
- myVMDict['imageRef'],myVMDict['flavorRef'],myVMDict['networks'])
- if result < 0:
- error_text = "Error creating vm instance: %s." % vm_id
- _, message = rollback(mydb, vims, rollbackList)
- error_text += message
- print "start_scenario: " + error_text
- return result, error_text
- print "VIM vm instance id (server id) for scenario %s: %s" % (scenarioDict['name'],vm_id)
- vm['vim_id'] = vm_id
- rollbackList.append({'what':'vm','where':'vim','vim_id':datacenter_id,'uuid':vm_id})
- #put interface uuid back to scenario[vnfs][vms[[interfaces]
- for net in myVMDict['networks']:
- if "vim_id" in net:
- for iface in vm['interfaces']:
- if net["name"]==iface["internal_name"]:
- iface["vim_id"]=net["vim_id"]
- break
+ #create image at vim in case it not exist
+ res, image_dict = mydb.get_table_by_uuid_name("images", vm['image_id'])
+ if res<0:
+ logger.error("start_scenario error getting image %s", str(image_dict))
+ return res, image_dict
+ res, image_id = create_or_use_image(mydb, vims, image_dict, [], True)
+ if res < 0:
+ logger.error("start_scenario error adding image to VIM: %s", str(image_dict))
+ return res, image_id
+ vm['vim_image_id'] = image_id
+
+ #create flavor at vim in case it not exist
+ res, flavor_dict = mydb.get_table_by_uuid_name("flavors", vm['flavor_id'])
+ if res<0:
+ logger.error("start_scenario error getting flavor: %s", str(flavor_dict))
+ return res, flavor_dict
+ if flavor_dict['extended']!=None:
+ flavor_dict['extended']= yaml.load(flavor_dict['extended'])
+ res, flavor_id = create_or_use_flavor(mydb, vims, flavor_dict, [], True)
+ if res < 0:
+ logger.error("start_scenario error adding flavor to VIM: ", str(flavor_dict))
+ return res, flavor_id
+ vm['vim_flavor_id'] = flavor_id