'''
if data==None:
return 'Null'
+ elif isinstance(data[1], str):
+ return json.dumps(data)
else:
return json.dumps(str(data))
'''
if data[1]==None:
return str(data[0]) + "=Null"
+ elif isinstance(data[1], str):
+ return str(data[0]) + '=' + json.dumps(data[1])
else:
return str(data[0]) + '=' + json.dumps(str(data[1]))
'''
if data[1]==None:
return str(data[0]) + " is Null"
-
-# if type(data[1]) is tuple: #this can only happen in a WHERE_OR clause
-# text =[]
-# for d in data[1]:
-# if d==None:
-# text.append(str(data[0]) + " is Null")
-# continue
-# out=str(d)
-# if "'" not in out:
-# text.append( str(data[0]) + "='" + out + "'" )
-# elif '"' not in out:
-# text.append( str(data[0]) + '="' + out + '"' )
-# else:
-# text.append( str(data[0]) + '=' + json.dumps(out) )
-# return " OR ".join(text)
-
- out=str(data[1])
- return str(data[0]) + '=' + json.dumps(out)
+ elif isinstance(data[1], str):
+ return str(data[0]) + '=' + json.dumps(data[1])
+ else:
+ return str(data[0]) + '=' + json.dumps(str(data[1]))
def __tuple2db_format_where_not(self, data):
'''Compose the needed text for a SQL WHERE(not). parameter 'data' is a pair tuple (A,B),
'''
if data[1]==None:
return str(data[0]) + " is not Null"
- out=str(data[1])
- return str(data[0]) + '<>' + json.dumps(out)
+ elif isinstance(data[1], str):
+ return str(data[0]) + '<>' + json.dumps(data[1])
+ else:
+ return str(data[0]) + '<>' + json.dumps(str(data[1]))
def __remove_quotes(self, data):
'''remove single quotes ' of any string content of data dictionary'''
import nfvo_db
from threading import Lock
from time import time
-#import openvim.ovim as Ovim
+import ovim as ovim_module
global global_config
global vimconn_imported
vim_persistent_info = {}
logger = logging.getLogger('openmano.nfvo')
task_lock = Lock()
-task_dict = {}
+global_instance_tasks = {}
last_task_id = 0.0
db=None
db_lock=Lock()
return "TASK.{:.6f}".format(task_id)
-def new_task(name, params, store=True, depends=None):
+def new_task(name, params, depends=None):
task_id = get_task_id()
task = {"status": "enqueued", "id": task_id, "name": name, "params": params}
if depends:
task["depends"] = depends
- if store:
- task_dict[task_id] = task
return task
# TODO: Avoid static configuration by adding new parameters to openmanod.cfg
# TODO: review ovim.py to delete not needed configuration
ovim_configuration = {
- 'logger_name': 'openvim',
+ 'logger_name': 'openmano.ovim',
'network_vlan_range_start': 1000,
'network_vlan_range_end': 4096,
- 'log_level_db': 'DEBUG',
- 'db_name': 'mano_vim_db',
- 'db_host': 'localhost',
- 'db_user': 'vim',
- 'db_passwd': 'vimpw',
- 'database_version': '0.15',
+ 'db_name': global_config["db_ovim_name"],
+ 'db_host': global_config["db_ovim_host"],
+ 'db_user': global_config["db_ovim_user"],
+ 'db_passwd': global_config["db_ovim_passwd"],
'bridge_ifaces': {},
'mode': 'normal',
- 'of_controller_nets_with_same_vlan': True,
'network_type': 'bridge',
#TODO: log_level_of should not be needed. To be modified in ovim
'log_level_of': 'DEBUG'
}
- #ovim = Ovim.ovim(ovim_configuration)
- #ovim.start_service()
+ ovim = ovim_module.ovim(ovim_configuration)
+ ovim.start_service()
from_= 'tenants_datacenters as td join datacenters as d on td.datacenter_id=d.uuid join datacenter_tenants as dt on td.datacenter_tenant_id=dt.uuid'
select_ = ('type','d.config as config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name',
try:
vims = mydb.get_rows(FROM=from_, SELECT=select_)
for vim in vims:
- extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id')}
+ extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id'),
+ 'datacenter_id': vim.get('datacenter_id')}
if vim["config"]:
extra.update(yaml.load(vim["config"]))
if vim.get('dt_config'):
raise NfvoException("Unknown vim type '{}'. Can not open file '{}.py'; {}: {}".format(
vim["type"], module, type(e).__name__, str(e)), HTTP_Bad_Request)
- thread_id = vim["datacenter_id"] + "." + vim['nfvo_tenant_id']
+ thread_id = vim['datacenter_tenant_id']
vim_persistent_info[thread_id] = {}
try:
#if not tenant:
raise NfvoException("Error at VIM {}; {}: {}".format(vim["type"], type(e).__name__, str(e)), HTTP_Internal_Server_Error)
thread_name = get_non_used_vim_name(vim['datacenter_name'], vim['vim_tenant_id'], vim['vim_tenant_name'], vim['vim_tenant_id'])
new_thread = vim_thread.vim_thread(myvim, task_lock, thread_name, vim['datacenter_name'],
- vim.get('datacenter_tenant_id'), db=db, db_lock=db_lock, ovim=ovim)
+ vim['datacenter_tenant_id'], db=db, db_lock=db_lock, ovim=ovim)
new_thread.start()
vim_threads["running"][thread_id] = new_thread
except db_base_Exception as e:
raise NfvoException(str(e) + " at nfvo.get_vim", e.http_code)
+
def stop_service():
global ovim, global_config
if ovim:
ovim.stop_service()
for thread_id,thread in vim_threads["running"].items():
- thread.insert_task(new_task("exit", None, store=False))
+ thread.insert_task(new_task("exit", None))
vim_threads["deleting"][thread_id] = thread
vim_threads["running"] = {}
if global_config and global_config.get("console_thread"):
vims = mydb.get_rows(FROM=from_, SELECT=select_, WHERE=WHERE_dict )
vim_dict={}
for vim in vims:
- extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id')}
+ extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id'),
+ 'datacenter_id': vim.get('datacenter_id')}
if vim["config"]:
extra.update(yaml.load(vim["config"]))
if vim.get('dt_config'):
vim["type"], module, type(e).__name__, str(e)), HTTP_Bad_Request)
try:
- if 'nfvo_tenant_id' in vim:
- thread_id = vim["datacenter_id"] + "." + vim['nfvo_tenant_id']
+ if 'datacenter_tenant_id' in vim:
+ thread_id = vim["datacenter_tenant_id"]
if thread_id not in vim_persistent_info:
vim_persistent_info[thread_id] = {}
persistent_info = vim_persistent_info[thread_id]
return new_cloud_config
-def get_vim_thread(tenant_id, datacenter_id_name=None, datacenter_tenant_id=None):
+def get_vim_thread(mydb, tenant_id, datacenter_id_name=None, datacenter_tenant_id=None):
datacenter_id = None
datacenter_name = None
thread = None
- if datacenter_id_name:
- if utils.check_valid_uuid(datacenter_id_name):
- datacenter_id = datacenter_id_name
+ try:
+ if datacenter_tenant_id:
+ thread_id = datacenter_tenant_id
+ thread = vim_threads["running"].get(datacenter_tenant_id)
else:
- datacenter_name = datacenter_id_name
- if datacenter_id:
- thread = vim_threads["running"].get(datacenter_id + "." + tenant_id)
- else:
- for k, v in vim_threads["running"].items():
- datacenter_tenant = k.split(".")
- if datacenter_tenant[0] == datacenter_id and datacenter_tenant[1] == tenant_id:
- if thread:
- raise NfvoException("More than one datacenters found, try to identify with uuid", HTTP_Conflict)
- thread = v
- elif not datacenter_id and datacenter_tenant[1] == tenant_id:
- if thread.datacenter_name == datacenter_name:
- if thread:
- raise NfvoException("More than one datacenters found, try to identify with uuid", HTTP_Conflict)
- thread = v
- if not thread:
- raise NfvoException("datacenter '{}' not found".format(str(datacenter_id_name)), HTTP_Not_Found)
- return thread
-
+ where_={"td.nfvo_tenant_id": tenant_id}
+ if datacenter_id_name:
+ if utils.check_valid_uuid(datacenter_id_name):
+ datacenter_id = datacenter_id_name
+ where_["dt.datacenter_id"] = datacenter_id
+ else:
+ datacenter_name = datacenter_id_name
+ where_["d.name"] = datacenter_name
+ if datacenter_tenant_id:
+ where_["dt.uuid"] = datacenter_tenant_id
+ datacenters = mydb.get_rows(
+ SELECT=("dt.uuid as datacenter_tenant_id",),
+ FROM="datacenter_tenants as dt join tenants_datacenters as td on dt.uuid=td.datacenter_tenant_id "
+ "join datacenters as d on d.uuid=dt.datacenter_id",
+ WHERE=where_)
+ if len(datacenters) > 1:
+ raise NfvoException("More than one datacenters found, try to identify with uuid", HTTP_Conflict)
+ elif datacenters:
+ thread_id = datacenters[0]["datacenter_tenant_id"]
+ thread = vim_threads["running"].get(thread_id)
+ if not thread:
+ raise NfvoException("datacenter '{}' not found".format(str(datacenter_id_name)), HTTP_Not_Found)
+ return thread_id, thread
+ except db_base_Exception as e:
+ raise NfvoException("{} {}".format(type(e).__name__ , str(e)), e.http_code)
def get_datacenter_by_name_uuid(mydb, tenant_id, datacenter_id_name=None, **extra_filter):
datacenter_id = None
#find main datacenter
myvims = {}
- myvim_threads = {}
- datacenter2tenant = {}
+ myvim_threads_id = {}
+ instance_tasks={}
+ tasks_to_launch={}
datacenter = instance_dict.get("datacenter")
default_datacenter_id, vim = get_datacenter_by_name_uuid(mydb, tenant_id, datacenter)
myvims[default_datacenter_id] = vim
- myvim_threads[default_datacenter_id] = get_vim_thread(tenant_id, default_datacenter_id)
- datacenter2tenant[default_datacenter_id] = vim['config']['datacenter_tenant_id']
+ myvim_threads_id[default_datacenter_id], _ = get_vim_thread(mydb, tenant_id, default_datacenter_id)
+ tasks_to_launch[myvim_threads_id[default_datacenter_id]] = []
#myvim_tenant = myvim['tenant_id']
# default_datacenter_name = vim['name']
rollbackList=[]
logger.debug("Creating instance from scenario-dict:\n%s", yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False)) #TODO remove
instance_name = instance_dict["name"]
instance_description = instance_dict.get("description")
- instance_tasks={}
try:
# 0 check correct parameters
for net_name, net_instance_desc in instance_dict.get("networks",{}).iteritems():
#Add this datacenter to myvims
d, v = get_datacenter_by_name_uuid(mydb, tenant_id, site["datacenter"])
myvims[d] = v
- myvim_threads[d] = get_vim_thread(tenant_id, site["datacenter"])
- datacenter2tenant[d] = v['config']['datacenter_tenant_id']
+ myvim_threads_id[d],_ = get_vim_thread(mydb, tenant_id, site["datacenter"])
+ tasks_to_launch[myvim_threads_id[d]] = []
site["datacenter"] = d #change name to id
else:
if site_without_datacenter_field:
if vnf_instance_desc["datacenter"] not in myvims:
d, v = get_datacenter_by_name_uuid(mydb, tenant_id, vnf_instance_desc["datacenter"])
myvims[d] = v
- myvim_threads[d] = get_vim_thread(tenant_id, vnf_instance_desc["datacenter"])
- datacenter2tenant[d] = v['config']['datacenter_tenant_id']
+ myvim_threads_id[d],_ = get_vim_thread(mydb, tenant_id, vnf_instance_desc["datacenter"])
+ tasks_to_launch[myvim_threads_id[d]] = []
scenario_vnf["datacenter"] = vnf_instance_desc["datacenter"]
#0.1 parse cloud-config parameters
if site.get("datacenter"):
vim = myvims[ site["datacenter"] ]
datacenter_id = site["datacenter"]
- myvim_thread = myvim_threads[ site["datacenter"] ]
+ myvim_thread_id = myvim_threads_id[ site["datacenter"] ]
else:
vim = myvims[ default_datacenter_id ]
datacenter_id = default_datacenter_id
- myvim_thread = myvim_threads[default_datacenter_id]
+ myvim_thread_id = myvim_threads_id[default_datacenter_id]
net_type = sce_net['type']
lookfor_filter = {'admin_state_up': True, 'status': 'ACTIVE'} #'shared': True
if sce_net["external"]:
if create_network:
#if network is not external
task = new_task("new-net", (net_vim_name, net_type, sce_net.get('ip_profile',None)))
- task_id = myvim_thread.insert_task(task)
+ task_id = task["id"]
instance_tasks[task_id] = task
+ tasks_to_launch[myvim_thread_id].append(task)
#network_id = vim.new_network(net_vim_name, net_type, sce_net.get('ip_profile',None))
sce_net["vim_id_sites"][datacenter_id] = task_id
auxNetDict['scenario'][sce_net['uuid']][datacenter_id] = task_id
if sce_vnf.get("datacenter"):
vim = myvims[ sce_vnf["datacenter"] ]
datacenter_id = sce_vnf["datacenter"]
- myvim_thread = myvim_threads[ sce_vnf["datacenter"]]
+ myvim_thread_id = myvim_threads_id[ sce_vnf["datacenter"]]
else:
vim = myvims[ default_datacenter_id ]
datacenter_id = default_datacenter_id
- myvim_thread = myvim_threads[default_datacenter_id]
+ myvim_thread_id = myvim_threads_id[default_datacenter_id]
descriptor_net = instance_dict.get("vnfs",{}).get(sce_vnf["name"],{})
net_name = descriptor_net.get("name")
if not net_name:
net_name = net_name[:255] #limit length
net_type = net['type']
task = new_task("new-net", (net_name, net_type, net.get('ip_profile',None)))
- task_id = myvim_thread.insert_task(task)
+ task_id = task["id"]
instance_tasks[task_id] = task
+ tasks_to_launch[myvim_thread_id].append(task)
# network_id = vim.new_network(net_name, net_type, net.get('ip_profile',None))
net['vim_id'] = task_id
if sce_vnf['uuid'] not in auxNetDict:
for sce_vnf in scenarioDict['vnfs']:
if sce_vnf.get("datacenter"):
vim = myvims[ sce_vnf["datacenter"] ]
- myvim_thread = myvim_threads[ sce_vnf["datacenter"] ]
+ myvim_thread_id = myvim_threads_id[ sce_vnf["datacenter"] ]
datacenter_id = sce_vnf["datacenter"]
else:
vim = myvims[ default_datacenter_id ]
- myvim_thread = myvim_threads[ default_datacenter_id ]
+ myvim_thread_id = myvim_threads_id[ default_datacenter_id ]
datacenter_id = default_datacenter_id
sce_vnf["datacenter_id"] = datacenter_id
i = 0
break
else:
netDict['net_id'] = auxNetDict[ sce_vnf['uuid'] ][ iface['net_id'] ]
- if is_task_id(netDict['net_id']):
+ if netDict.get('net_id') and is_task_id(netDict['net_id']):
task_depends[netDict['net_id']] = instance_tasks[netDict['net_id']]
#skip bridge ifaces not connected to any net
#if 'net_id' not in netDict or netDict['net_id']==None:
task = new_task("new-vm", (myVMDict['name'], myVMDict['description'], myVMDict.get('start', None),
myVMDict['imageRef'], myVMDict['flavorRef'], myVMDict['networks'],
cloud_config_vm, myVMDict['disks']), depends=task_depends)
- vm_id = myvim_thread.insert_task(task)
- instance_tasks[vm_id] = task
-
+ instance_tasks[task["id"]] = task
+ tasks_to_launch[myvim_thread_id].append(task)
+ vm_id = task["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]
if net["name"]==iface["internal_name"]:
iface["vim_id"]=net["vim_id"]
break
- scenarioDict["datacenter2tenant"] = datacenter2tenant
+ scenarioDict["datacenter2tenant"] = myvim_threads_id
logger.debug("create_instance Deployment done scenarioDict: %s",
yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False) )
instance_id = mydb.new_instance_scenario_as_a_whole(tenant_id,instance_name, instance_description, scenarioDict)
- # Update database with those ended tasks
- for task in instance_tasks.values():
- if task["status"] == "ok":
- if task["name"] == "new-vm":
- mydb.update_rows("instance_vms", UPDATE={"vim_vm_id": task["result"]},
- WHERE={"vim_vm_id": task["id"]})
- elif task["name"] == "new-net":
- mydb.update_rows("instance_nets", UPDATE={"vim_net_id": task["result"]},
- WHERE={"vim_net_id": task["id"]})
+ for myvim_thread_id,task_list in tasks_to_launch.items():
+ for task in task_list:
+ vim_threads["running"][myvim_thread_id].insert_task(task)
+
+ global_instance_tasks[instance_id] = instance_tasks
+ # Update database with those ended instance_tasks
+ # for task in instance_tasks.values():
+ # if task["status"] == "ok":
+ # if task["name"] == "new-vm":
+ # mydb.update_rows("instance_vms", UPDATE={"vim_vm_id": task["result"]},
+ # WHERE={"vim_vm_id": task["id"]})
+ # elif task["name"] == "new-net":
+ # mydb.update_rows("instance_nets", UPDATE={"vim_net_id": task["result"]},
+ # WHERE={"vim_net_id": task["id"]})
return mydb.get_instance_scenario(instance_id)
except (NfvoException, vimconn.vimconnException,db_base_Exception) as e:
message = rollback(mydb, myvims, rollbackList)
datacenter_key = (sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
if datacenter_key not in myvims:
try:
- myvim_thread = get_vim_thread(tenant_id, sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
+ _,myvim_thread = get_vim_thread(mydb, tenant_id, sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
except NfvoException as e:
logger.error(str(e))
myvim_thread = None
task=None
if is_task_id(vm['vim_vm_id']):
task_id = vm['vim_vm_id']
- old_task = task_dict.get(task_id)
+ old_task = global_instance_tasks[instance_id].get(task_id)
if not old_task:
error_msg += "\n VM was scheduled for create, but task {} is not found".format(task_id)
continue
elif old_task["status"] == "error":
continue
elif old_task["status"] == "processing":
- task = new_task("del-vm", task_id, depends={task_id: old_task})
+ task = new_task("del-vm", (task_id, vm["interfaces"]), depends={task_id: old_task})
else: #ok
- task = new_task("del-vm", old_task["result"])
+ task = new_task("del-vm", (old_task["result"], vm["interfaces"]))
else:
- task = new_task("del-vm", vm['vim_vm_id'], store=False)
+ task = new_task("del-vm", (vm['vim_vm_id'], vm["interfaces"]) )
if task:
myvim_thread.insert_task(task)
except vimconn.vimconnNotFoundException as e:
datacenter_key = (net["datacenter_id"], net["datacenter_tenant_id"])
if datacenter_key not in myvims:
try:
- myvim_thread = get_vim_thread(tenant_id, sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
+ _,myvim_thread = get_vim_thread(mydb, tenant_id, sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
except NfvoException as e:
logger.error(str(e))
myvim_thread = None
task = None
if is_task_id(net['vim_net_id']):
task_id = net['vim_net_id']
- old_task = task_dict.get(task_id)
+ old_task = global_instance_tasks[instance_id].get(task_id)
if not old_task:
error_msg += "\n NET was scheduled for create, but task {} is not found".format(task_id)
continue
else: # ok
task = new_task("del-net", old_task["result"])
else:
- task = new_task("del-net", (net['vim_net_id'], net['sdn_net_id']), store=False)
+ task = new_task("del-net", (net['vim_net_id'], net['sdn_net_id']))
if task:
myvim_thread.insert_task(task)
except vimconn.vimconnNotFoundException as e:
- result: <0 if there is any unexpected error, n>=0 if no errors where n is the number of vms and nets that couldn't be updated in the database
- error_msg
'''
- # Assumption: nfvo_tenant and instance_id were checked before entering into this function
- #print "nfvo.refresh_instance begins"
- #print json.dumps(instanceDict, indent=4)
-
- #print "Getting the VIM URL and the VIM tenant_id"
- myvims={}
-
- # 1. Getting VIM vm and net list
- vms_updated = [] #List of VM instance uuids in openmano that were updated
- vms_notupdated=[]
- vm_list = {}
- for sce_vnf in instanceDict['vnfs']:
- datacenter_key = (sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
- if datacenter_key not in vm_list:
- vm_list[datacenter_key] = []
- if datacenter_key not in myvims:
- vims = get_vim(mydb, nfvo_tenant, datacenter_id=sce_vnf["datacenter_id"],
- datacenter_tenant_id=sce_vnf["datacenter_tenant_id"])
- if len(vims) == 0:
- logger.error("datacenter '{}' with datacenter_tenant_id '{}' not found".format(sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"]))
- myvims[datacenter_key] = None
- else:
- myvims[datacenter_key] = vims.values()[0]
- for vm in sce_vnf['vms']:
- vm_list[datacenter_key].append(vm['vim_vm_id'])
- vms_notupdated.append(vm["uuid"])
-
- nets_updated = [] #List of VM instance uuids in openmano that were updated
- nets_notupdated=[]
- net_list = {}
- for net in instanceDict['nets']:
- datacenter_key = (net["datacenter_id"], net["datacenter_tenant_id"])
- if datacenter_key not in net_list:
- net_list[datacenter_key] = []
- if datacenter_key not in myvims:
- vims = get_vim(mydb, nfvo_tenant, datacenter_id=net["datacenter_id"],
- datacenter_tenant_id=net["datacenter_tenant_id"])
- if len(vims) == 0:
- logger.error("datacenter '{}' with datacenter_tenant_id '{}' not found".format(net["datacenter_id"], net["datacenter_tenant_id"]))
- myvims[datacenter_key] = None
- else:
- myvims[datacenter_key] = vims.values()[0]
-
- net_list[datacenter_key].append(net['vim_net_id'])
- nets_notupdated.append(net["uuid"])
-
- # 1. Getting the status of all VMs
- vm_dict={}
- for datacenter_key in myvims:
- if not vm_list.get(datacenter_key):
- continue
- failed = True
- failed_message=""
- if not myvims[datacenter_key]:
- failed_message = "datacenter '{}' with datacenter_tenant_id '{}' not found".format(net["datacenter_id"], net["datacenter_tenant_id"])
- else:
- try:
- vm_dict.update(myvims[datacenter_key].refresh_vms_status(vm_list[datacenter_key]) )
- failed = False
- except vimconn.vimconnException as e:
- logger.error("VIM exception %s %s", type(e).__name__, str(e))
- failed_message = str(e)
- if failed:
- for vm in vm_list[datacenter_key]:
- vm_dict[vm] = {'status': "VIM_ERROR", 'error_msg': failed_message}
-
- # 2. Update the status of VMs in the instanceDict, while collects the VMs whose status changed
- for sce_vnf in instanceDict['vnfs']:
- for vm in sce_vnf['vms']:
- vm_id = vm['vim_vm_id']
- interfaces = vm_dict[vm_id].pop('interfaces', [])
- #2.0 look if contain manamgement interface, and if not change status from ACTIVE:NoMgmtIP to ACTIVE
- has_mgmt_iface = False
- for iface in vm["interfaces"]:
- if iface["type"]=="mgmt":
- has_mgmt_iface = True
- if vm_dict[vm_id]['status'] == "ACTIVE:NoMgmtIP" and not has_mgmt_iface:
- vm_dict[vm_id]['status'] = "ACTIVE"
- if vm_dict[vm_id].get('error_msg') and len(vm_dict[vm_id]['error_msg']) >= 1024:
- vm_dict[vm_id]['error_msg'] = vm_dict[vm_id]['error_msg'][:516] + " ... " + vm_dict[vm_id]['error_msg'][-500:]
- if vm['status'] != vm_dict[vm_id]['status'] or vm.get('error_msg')!=vm_dict[vm_id].get('error_msg') or vm.get('vim_info')!=vm_dict[vm_id].get('vim_info'):
- vm['status'] = vm_dict[vm_id]['status']
- vm['error_msg'] = vm_dict[vm_id].get('error_msg')
- vm['vim_info'] = vm_dict[vm_id].get('vim_info')
- # 2.1. Update in openmano DB the VMs whose status changed
- try:
- updates = mydb.update_rows('instance_vms', UPDATE=vm_dict[vm_id], WHERE={'uuid':vm["uuid"]})
- vms_notupdated.remove(vm["uuid"])
- if updates>0:
- vms_updated.append(vm["uuid"])
- except db_base_Exception as e:
- logger.error("nfvo.refresh_instance error database update: %s", str(e))
- # 2.2. Update in openmano DB the interface VMs
- for interface in interfaces:
- #translate from vim_net_id to instance_net_id
- network_id_list=[]
- for net in instanceDict['nets']:
- if net["vim_net_id"] == interface["vim_net_id"]:
- network_id_list.append(net["uuid"])
- if not network_id_list:
- continue
- del interface["vim_net_id"]
- try:
- for network_id in network_id_list:
- mydb.update_rows('instance_interfaces', UPDATE=interface, WHERE={'instance_vm_id':vm["uuid"], "instance_net_id":network_id})
- except db_base_Exception as e:
- logger.error( "nfvo.refresh_instance error with vm=%s, interface_net_id=%s", vm["uuid"], network_id)
-
- # 3. Getting the status of all nets
- net_dict = {}
- for datacenter_key in myvims:
- if not net_list.get(datacenter_key):
- continue
- failed = True
- failed_message = ""
- if not myvims[datacenter_key]:
- failed_message = "datacenter '{}' with datacenter_tenant_id '{}' not found".format(net["datacenter_id"], net["datacenter_tenant_id"])
- else:
- try:
- net_dict.update(myvims[datacenter_key].refresh_nets_status(net_list[datacenter_key]) )
- failed = False
- except vimconn.vimconnException as e:
- logger.error("VIM exception %s %s", type(e).__name__, str(e))
- failed_message = str(e)
- if failed:
- for net in net_list[datacenter_key]:
- net_dict[net] = {'status': "VIM_ERROR", 'error_msg': failed_message}
-
- # 4. Update the status of nets in the instanceDict, while collects the nets whose status changed
- # TODO: update nets inside a vnf
- for net in instanceDict['nets']:
- net_id = net['vim_net_id']
- if net_dict[net_id].get('error_msg') and len(net_dict[net_id]['error_msg']) >= 1024:
- net_dict[net_id]['error_msg'] = net_dict[net_id]['error_msg'][:516] + " ... " + net_dict[vm_id]['error_msg'][-500:]
- if net['status'] != net_dict[net_id]['status'] or net.get('error_msg')!=net_dict[net_id].get('error_msg') or net.get('vim_info')!=net_dict[net_id].get('vim_info'):
- net['status'] = net_dict[net_id]['status']
- net['error_msg'] = net_dict[net_id].get('error_msg')
- net['vim_info'] = net_dict[net_id].get('vim_info')
- # 5.1. Update in openmano DB the nets whose status changed
- try:
- updated = mydb.update_rows('instance_nets', UPDATE=net_dict[net_id], WHERE={'uuid':net["uuid"]})
- nets_notupdated.remove(net["uuid"])
- if updated>0:
- nets_updated.append(net["uuid"])
- except db_base_Exception as e:
- logger.error("nfvo.refresh_instance error database update: %s", str(e))
-
- # Returns appropriate output
- #print "nfvo.refresh_instance finishes"
- logger.debug("VMs updated in the database: %s; nets updated in the database %s; VMs not updated: %s; nets not updated: %s",
- str(vms_updated), str(nets_updated), str(vms_notupdated), str(nets_notupdated))
+ # # Assumption: nfvo_tenant and instance_id were checked before entering into this function
+ # #print "nfvo.refresh_instance begins"
+ # #print json.dumps(instanceDict, indent=4)
+ #
+ # #print "Getting the VIM URL and the VIM tenant_id"
+ # myvims={}
+ #
+ # # 1. Getting VIM vm and net list
+ # vms_updated = [] #List of VM instance uuids in openmano that were updated
+ # vms_notupdated=[]
+ # vm_list = {}
+ # for sce_vnf in instanceDict['vnfs']:
+ # datacenter_key = (sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"])
+ # if datacenter_key not in vm_list:
+ # vm_list[datacenter_key] = []
+ # if datacenter_key not in myvims:
+ # vims = get_vim(mydb, nfvo_tenant, datacenter_id=sce_vnf["datacenter_id"],
+ # datacenter_tenant_id=sce_vnf["datacenter_tenant_id"])
+ # if len(vims) == 0:
+ # logger.error("datacenter '{}' with datacenter_tenant_id '{}' not found".format(sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"]))
+ # myvims[datacenter_key] = None
+ # else:
+ # myvims[datacenter_key] = vims.values()[0]
+ # for vm in sce_vnf['vms']:
+ # vm_list[datacenter_key].append(vm['vim_vm_id'])
+ # vms_notupdated.append(vm["uuid"])
+ #
+ # nets_updated = [] #List of VM instance uuids in openmano that were updated
+ # nets_notupdated=[]
+ # net_list = {}
+ # for net in instanceDict['nets']:
+ # datacenter_key = (net["datacenter_id"], net["datacenter_tenant_id"])
+ # if datacenter_key not in net_list:
+ # net_list[datacenter_key] = []
+ # if datacenter_key not in myvims:
+ # vims = get_vim(mydb, nfvo_tenant, datacenter_id=net["datacenter_id"],
+ # datacenter_tenant_id=net["datacenter_tenant_id"])
+ # if len(vims) == 0:
+ # logger.error("datacenter '{}' with datacenter_tenant_id '{}' not found".format(net["datacenter_id"], net["datacenter_tenant_id"]))
+ # myvims[datacenter_key] = None
+ # else:
+ # myvims[datacenter_key] = vims.values()[0]
+ #
+ # net_list[datacenter_key].append(net['vim_net_id'])
+ # nets_notupdated.append(net["uuid"])
+ #
+ # # 1. Getting the status of all VMs
+ # vm_dict={}
+ # for datacenter_key in myvims:
+ # if not vm_list.get(datacenter_key):
+ # continue
+ # failed = True
+ # failed_message=""
+ # if not myvims[datacenter_key]:
+ # failed_message = "datacenter '{}' with datacenter_tenant_id '{}' not found".format(net["datacenter_id"], net["datacenter_tenant_id"])
+ # else:
+ # try:
+ # vm_dict.update(myvims[datacenter_key].refresh_vms_status(vm_list[datacenter_key]) )
+ # failed = False
+ # except vimconn.vimconnException as e:
+ # logger.error("VIM exception %s %s", type(e).__name__, str(e))
+ # failed_message = str(e)
+ # if failed:
+ # for vm in vm_list[datacenter_key]:
+ # vm_dict[vm] = {'status': "VIM_ERROR", 'error_msg': failed_message}
+ #
+ # # 2. Update the status of VMs in the instanceDict, while collects the VMs whose status changed
+ # for sce_vnf in instanceDict['vnfs']:
+ # for vm in sce_vnf['vms']:
+ # vm_id = vm['vim_vm_id']
+ # interfaces = vm_dict[vm_id].pop('interfaces', [])
+ # #2.0 look if contain manamgement interface, and if not change status from ACTIVE:NoMgmtIP to ACTIVE
+ # has_mgmt_iface = False
+ # for iface in vm["interfaces"]:
+ # if iface["type"]=="mgmt":
+ # has_mgmt_iface = True
+ # if vm_dict[vm_id]['status'] == "ACTIVE:NoMgmtIP" and not has_mgmt_iface:
+ # vm_dict[vm_id]['status'] = "ACTIVE"
+ # if vm_dict[vm_id].get('error_msg') and len(vm_dict[vm_id]['error_msg']) >= 1024:
+ # vm_dict[vm_id]['error_msg'] = vm_dict[vm_id]['error_msg'][:516] + " ... " + vm_dict[vm_id]['error_msg'][-500:]
+ # if vm['status'] != vm_dict[vm_id]['status'] or vm.get('error_msg')!=vm_dict[vm_id].get('error_msg') or vm.get('vim_info')!=vm_dict[vm_id].get('vim_info'):
+ # vm['status'] = vm_dict[vm_id]['status']
+ # vm['error_msg'] = vm_dict[vm_id].get('error_msg')
+ # vm['vim_info'] = vm_dict[vm_id].get('vim_info')
+ # # 2.1. Update in openmano DB the VMs whose status changed
+ # try:
+ # updates = mydb.update_rows('instance_vms', UPDATE=vm_dict[vm_id], WHERE={'uuid':vm["uuid"]})
+ # vms_notupdated.remove(vm["uuid"])
+ # if updates>0:
+ # vms_updated.append(vm["uuid"])
+ # except db_base_Exception as e:
+ # logger.error("nfvo.refresh_instance error database update: %s", str(e))
+ # # 2.2. Update in openmano DB the interface VMs
+ # for interface in interfaces:
+ # #translate from vim_net_id to instance_net_id
+ # network_id_list=[]
+ # for net in instanceDict['nets']:
+ # if net["vim_net_id"] == interface["vim_net_id"]:
+ # network_id_list.append(net["uuid"])
+ # if not network_id_list:
+ # continue
+ # del interface["vim_net_id"]
+ # try:
+ # for network_id in network_id_list:
+ # mydb.update_rows('instance_interfaces', UPDATE=interface, WHERE={'instance_vm_id':vm["uuid"], "instance_net_id":network_id})
+ # except db_base_Exception as e:
+ # logger.error( "nfvo.refresh_instance error with vm=%s, interface_net_id=%s", vm["uuid"], network_id)
+ #
+ # # 3. Getting the status of all nets
+ # net_dict = {}
+ # for datacenter_key in myvims:
+ # if not net_list.get(datacenter_key):
+ # continue
+ # failed = True
+ # failed_message = ""
+ # if not myvims[datacenter_key]:
+ # failed_message = "datacenter '{}' with datacenter_tenant_id '{}' not found".format(net["datacenter_id"], net["datacenter_tenant_id"])
+ # else:
+ # try:
+ # net_dict.update(myvims[datacenter_key].refresh_nets_status(net_list[datacenter_key]) )
+ # failed = False
+ # except vimconn.vimconnException as e:
+ # logger.error("VIM exception %s %s", type(e).__name__, str(e))
+ # failed_message = str(e)
+ # if failed:
+ # for net in net_list[datacenter_key]:
+ # net_dict[net] = {'status': "VIM_ERROR", 'error_msg': failed_message}
+ #
+ # # 4. Update the status of nets in the instanceDict, while collects the nets whose status changed
+ # # TODO: update nets inside a vnf
+ # for net in instanceDict['nets']:
+ # net_id = net['vim_net_id']
+ # if net_dict[net_id].get('error_msg') and len(net_dict[net_id]['error_msg']) >= 1024:
+ # net_dict[net_id]['error_msg'] = net_dict[net_id]['error_msg'][:516] + " ... " + net_dict[vm_id]['error_msg'][-500:]
+ # if net['status'] != net_dict[net_id]['status'] or net.get('error_msg')!=net_dict[net_id].get('error_msg') or net.get('vim_info')!=net_dict[net_id].get('vim_info'):
+ # net['status'] = net_dict[net_id]['status']
+ # net['error_msg'] = net_dict[net_id].get('error_msg')
+ # net['vim_info'] = net_dict[net_id].get('vim_info')
+ # # 5.1. Update in openmano DB the nets whose status changed
+ # try:
+ # updated = mydb.update_rows('instance_nets', UPDATE=net_dict[net_id], WHERE={'uuid':net["uuid"]})
+ # nets_notupdated.remove(net["uuid"])
+ # if updated>0:
+ # nets_updated.append(net["uuid"])
+ # except db_base_Exception as e:
+ # logger.error("nfvo.refresh_instance error database update: %s", str(e))
+ #
+ # # Returns appropriate output
+ # #print "nfvo.refresh_instance finishes"
+ # logger.debug("VMs updated in the database: %s; nets updated in the database %s; VMs not updated: %s; nets not updated: %s",
+ # str(vms_updated), str(nets_updated), str(vms_notupdated), str(nets_notupdated))
instance_id = instanceDict['uuid']
- if len(vms_notupdated)+len(nets_notupdated)>0:
- error_msg = "VMs not updated: " + str(vms_notupdated) + "; nets not updated: " + str(nets_notupdated)
- return len(vms_notupdated)+len(nets_notupdated), 'Scenario instance ' + instance_id + ' refreshed but some elements could not be updated in the database: ' + error_msg
+ # if len(vms_notupdated)+len(nets_notupdated)>0:
+ # error_msg = "VMs not updated: " + str(vms_notupdated) + "; nets not updated: " + str(nets_notupdated)
+ # return len(vms_notupdated)+len(nets_notupdated), 'Scenario instance ' + instance_id + ' refreshed but some elements could not be updated in the database: ' + error_msg
return 0, 'Scenario instance ' + instance_id + ' refreshed.'
thread_name = get_non_used_vim_name(datacenter_name, datacenter_id, tenant_dict['name'], tenant_dict['uuid'])
new_thread = vim_thread.vim_thread(myvim, task_lock, thread_name, datacenter_name, db=db, db_lock=db_lock, ovim=ovim)
new_thread.start()
- thread_id = datacenter_id + "." + tenant_dict['uuid']
+ thread_id = datacenter_tenants_dict["uuid"]
vim_threads["running"][thread_id] = new_thread
return datacenter_id
except db_base_Exception as e:
logger.error("Cannot delete datacenter_tenants " + str(e))
pass # the error will be caused because dependencies, vim_tenant can not be deleted
- thread_id = datacenter_id + "." + tenant_datacenter_item["nfvo_tenant_id"]
+ thread_id = tenant_datacenter_item["datacenter_tenant_id"]
thread = vim_threads["running"][thread_id]
- thread.insert_task(new_task("exit", None, store=False))
+ thread.insert_task(new_task("exit", None))
vim_threads["deleting"][thread_id] = thread
return "datacenter {} detached. {}".format(datacenter_id, warning)
return vim_action_get(mydb, tenant_id, datacenter, item, content)
def sdn_controller_create(mydb, tenant_id, sdn_controller):
- #data = ovim.new_of_controller(sdn_controller)
- data = []
+ data = ovim.new_of_controller(sdn_controller)
logger.debug('New SDN controller created with uuid {}'.format(data))
return data
def sdn_controller_update(mydb, tenant_id, controller_id, sdn_controller):
- #data = ovim.edit_of_controller(controller_id, sdn_controller)
- data = []
+ data = ovim.edit_of_controller(controller_id, sdn_controller)
msg = 'SDN controller {} updated'.format(data)
logger.debug(msg)
return msg
def sdn_controller_list(mydb, tenant_id, controller_id=None):
if controller_id == None:
- #data = ovim.get_of_controllers()
- data = []
+ data = ovim.get_of_controllers()
else:
- #data = ovim.show_of_controller(controller_id)
- data = {'dpid': None}
+ data = ovim.show_of_controller(controller_id)
+
msg = 'SDN controller list:\n {}'.format(data)
logger.debug(msg)
return data
if 'sdn-controller' in config and config['sdn-controller'] == controller_id:
raise NfvoException("SDN controller {} is in use by datacenter {}".format(controller_id, datacenter['uuid']), HTTP_Conflict)
- #data = ovim.delete_of_controller(controller_id)
- data = 0
+ data = ovim.delete_of_controller(controller_id)
msg = 'SDN controller {} deleted'.format(data)
logger.debug(msg)
return msg
except:
raise NfvoException("The datacenter {} has not an SDN controller associated".format(datacenter_id), HTTP_Bad_Request)
- #sdn_controller = ovim.show_of_controller(sdn_controller_id)
- #switch_dpid = sdn_controller["dpid"]
+ sdn_controller = ovim.show_of_controller(sdn_controller_id)
+ switch_dpid = sdn_controller["dpid"]
maps = list()
for compute_node in sdn_port_mapping:
" or 'switch_mac'", HTTP_Bad_Request)
maps.append(dict(element))
- #return ovim.set_of_port_mapping(maps, ofc_id=sdn_controller_id, switch_dpid=switch_dpid, region=datacenter_id)
- return []
+ return ovim.set_of_port_mapping(maps, ofc_id=sdn_controller_id, switch_dpid=switch_dpid, region=datacenter_id)
def datacenter_sdn_port_mapping_list(mydb, tenant_id, datacenter_id):
- #maps = ovim.get_of_port_mappings(db_filter={"region": datacenter_id})
- maps = []
+ maps = ovim.get_of_port_mappings(db_filter={"region": datacenter_id})
result = {
"sdn-controller": None,
result["sdn-controller"] = controller_id
result["dpid"] = sdn_controller["dpid"]
- # if result["sdn-controller"] == None or result["dpid"] == None:
- # raise NfvoException("Not all SDN controller information for datacenter {} could be found: {}".format(datacenter_id, result),
- # HTTP_Internal_Server_Error)
+ if result["sdn-controller"] == None or result["dpid"] == None:
+ raise NfvoException("Not all SDN controller information for datacenter {} could be found: {}".format(datacenter_id, result),
+ HTTP_Internal_Server_Error)
if len(maps) == 0:
return result
return result
def datacenter_sdn_port_mapping_delete(mydb, tenant_id, datacenter_id):
- #return ovim.clear_of_port_mapping(db_filter={"region":datacenter_id})
- return 0
+ return ovim.clear_of_port_mapping(db_filter={"region":datacenter_id})
INSERT_={'vim_net_id': vim_id, 'created': net.get('created', False), 'instance_scenario_id':instance_uuid } #, 'type': net['type']
INSERT_['datacenter_id'] = datacenter_site_id
INSERT_['datacenter_tenant_id'] = scenarioDict["datacenter2tenant"][datacenter_site_id]
+ if not net.get('created', False):
+ INSERT_['status'] = "ACTIVE"
if sce_net_id:
INSERT_['sce_net_id'] = sce_net_id
created_time += 0.00001
vm_manage_iface_list=[]
#instance_interfaces
cmd = "SELECT vim_interface_id, instance_net_id, internal_name,external_name, mac_address,"\
- " ii.ip_address as ip_address, vim_info, i.type as type"\
+ " ii.ip_address as ip_address, vim_info, i.type as type, sdn_port_id"\
" FROM instance_interfaces as ii join interfaces as i on ii.interface_id=i.uuid"\
" WHERE instance_vm_id='{}' ORDER BY created_at".format(vm['uuid'])
self.logger.debug(cmd)
if args.ip != None:
controller_dict['ip'] = args.ip
if args.port != None:
- controller_dict['port'] = args.port
+ controller_dict['port'] = int(args.port)
if args.dpid != None:
controller_dict['dpid'] = args.dpid
if args.type != None:
"db_user": nameshort_schema,
"db_passwd": {"type":"string"},
"db_name": nameshort_schema,
+ "db_ovim_host": nameshort_schema,
+ "db_ovim_user": nameshort_schema,
+ "db_ovim_passwd": {"type":"string"},
+ "db_ovim_name": nameshort_schema,
# Next fields will disappear once the MANO API includes appropriate primitives
"vim_url": http_schema,
"vim_url_admin": http_schema,
"log_level_nfvo": log_level_schema,
"log_level_http": log_level_schema,
"log_level_console": log_level_schema,
+ "log_level_ovim": log_level_schema,
"log_file_db": path_schema,
"log_file_vim": path_schema,
"log_file_nfvo": path_schema,
"log_file_http": path_schema,
"log_file_console": path_schema,
+ "log_file_ovim": path_schema,
"log_socket_host": nameshort_schema,
"log_socket_port": port_schema,
"log_file": path_schema,
},
- "required": ['db_host', 'db_user', 'db_passwd', 'db_name'],
+ "required": ['db_user', 'db_passwd', 'db_name'],
"additionalProperties": False
}
db_user: mano # DB user
db_passwd: manopw # DB password
db_name: mano_db # Name of the MANO DB
+# Database ovim parameters
+db_ovim_host: localhost # by default localhost
+db_ovim_user: mano # DB user
+db_ovim_passwd: manopw # DB password
+db_ovim_name: mano_vim_db # Name of the OVIM MANO DB
+
#other MANO parameters
# Folder where the VNF descriptors will be stored
#log_file_http: /opt/openmano/logs/openmano_http.log
#log_level_console: DEBUG #proxy console log levels
#log_file_console: /opt/openmano/logs/openmano_console.log
+#log_level_ovim: DEBUG #ovim library log levels
+#log_file_ovim: /opt/openmano/logs/openmano_ovim.log
#Uncomment to send logs via IP to an external host
#log_socket_host: localhost
pass
def load_configuration(configuration_file):
- default_tokens ={'http_port':9090,
- 'http_host':'localhost',
- 'http_console_proxy': True,
- 'http_console_host': None,
- 'log_level': 'DEBUG',
- 'log_socket_port': 9022,
- 'auto_push_VNF_to_VIMs': True
- }
+ default_tokens = {'http_port':9090,
+ 'http_host':'localhost',
+ 'http_console_proxy': True,
+ 'http_console_host': None,
+ 'log_level': 'DEBUG',
+ 'log_socket_port': 9022,
+ 'auto_push_VNF_to_VIMs': True,
+ 'db_host': 'localhost',
+ 'db_ovim_host': 'localhost'
+ }
try:
#Check config file exists
with open(configuration_file, 'r') as f:
logger.critical("Starting openmano server version: '%s %s' command: '%s'",
__version__, version_date, " ".join(sys.argv))
- for log_module in ("nfvo", "http", "vim", "db", "console"):
+ for log_module in ("nfvo", "http", "vim", "db", "console", "ovim"):
log_level_module = "log_level_" + log_module
log_file_module = "log_file_" + log_module
logger_module = logging.getLogger('openmano.' + log_module)
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+schema_version: 2
+scenario:
+ name: p2p_passthrough
+ description: Network scenario consisting of two machines with a sr-iov interconnected between them
+ vnfs:
+ passthrough1: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ passthrough2: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ networks:
+ mgmt: # provide a name for this net or connection
+ external: true
+ interfaces:
+ - passthrough1: eth0 # Node and its interface
+ - passthrough2: eth0 # Node and its interface
+ dataplane: # provide a name for this net or connection
+ interfaces:
+ - passthrough1: xe0 # Node and its interface
+ - passthrough2: xe0 # Node and its interface
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: passthrough
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: passthrough-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: passthrough-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: passthrough-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "yes" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+schema_version: 2
+scenario:
+ name: p2p_passthrough
+ description: Network scenario consisting of 4 machines with a passthrough interconnected between them
+ vnfs:
+ passthrough1: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ passthrough2: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ passthrough3: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ passthrough4: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+
+ networks:
+ mgmt: # provide a name for this net or connection
+ external: true
+ interfaces:
+ - passthrough1: eth0 # Node and its interface
+ - passthrough2: eth0 # Node and its interface
+ - passthrough3: eth0 # Node and its interface
+ - passthrough4: eth0 # Node and its interface
+ dataplane: # provide a name for this net or connection
+ interfaces:
+ - passthrough1: xe0 # Node and its interface
+ - passthrough2: xe0 # Node and its interface
+ - passthrough3: xe0 # Node and its interface
+ - passthrough4: xe0 # Node and its interface
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: passthrough
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: passthrough-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: passthrough-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: passthrough-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "yes" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+schema_version: 2
+scenario:
+ name: p2p_sriov
+ description: Network scenario consisting of four machines with a sr-iov interconnected between them
+ vnfs:
+ sriov1: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+ sriov2: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+ sriov3: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+ sriov4: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+
+ networks:
+ mgmt: # provide a name for this net or connection
+ external: true
+ interfaces:
+ - sriov1: eth0 # Node and its interface
+ - sriov2: eth0 # Node and its interface
+ - sriov3: eth0 # Node and its interface
+ - sriov4: eth0 # Node and its interface
+ dataplane: # provide a name for this net or connection
+ interfaces:
+ - sriov1: xe0 # Node and its interface
+ - sriov2: xe0 # Node and its interface
+ - sriov3: xe0 # Node and its interface
+ - sriov4: xe0 # Node and its interface
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: sriov
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: sriov-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: sriov-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: sriov-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "no" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+schema_version: 2
+scenario:
+ name: p2p_sriov_passthrough
+ description: Network scenario consisting of two machines with a sr-iov interconnected between them
+ vnfs:
+ sriov1: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+ passthrough1: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ sriov2: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+ passthrough2: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+
+ networks:
+ mgmt: # provide a name for this net or connection
+ external: true
+ interfaces:
+ - sriov1: eth0 # Node and its interface
+ - passthrough1: eth0 # Node and its interface
+ - sriov2: eth0 # Node and its interface
+ - passthrough2: eth0 # Node and its interface
+ dataplane: # provide a name for this net or connection
+ interfaces:
+ - sriov1: xe0 # Node and its interface
+ - passthrough1: xe0 # Node and its interface
+ - sriov2: xe0 # Node and its interface
+ - passthrough2: xe0 # Node and its interface
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: passthrough
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: passthrough-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: passthrough-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: passthrough-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "yes" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: sriov
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: sriov-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: sriov-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: sriov-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "no" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+schema_version: 2
+scenario:
+ name: simple
+ description: Simple network scenario consisting of two VNF connected to an external network
+ vnfs:
+ linux1: # vnf/net name in the scenario
+ vnf_name: linux # VNF name as introduced in OPENMANO DB
+ linux2: # vnf/net name in the scenario
+ vnf_name: linux # VNF name as introduced in OPENMANO DB
+ networks:
+ mgmt: # provide a name for this net or connection
+ external: true
+ interfaces:
+ - linux1: eth0 # Node and its interface
+ - linux2: eth0 # Node and its interface
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: linux
+ description: Single-VM VNF with a traditional cloud VM based on generic Linux OS
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: linux-VM
+ local_iface_name: eth0
+ description: General purpose interface
+ VNFC:
+ - name: linux-VM
+ description: Generic Linux Virtual Machine
+ #Copy the image to a compute path and edit this path
+ image name: image_name.qcow2
+ vcpus: 1 # Only for traditional cloud VMs. Number of virtual CPUs (oversubscription is allowed).
+ ram: 1024 # Only for traditional cloud VMs. Memory in MBytes (not from hugepages, oversubscription is allowed)
+ disk: 10
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:11.0"
+ numas: []
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+schema_version: 2
+scenario:
+ name: p2p_sriov_passthrough
+ description: Network scenario consisting of two machines with a sr-iov interconnected between them
+ vnfs:
+ sriov: # vnf/net name in the scenario
+ vnf_name: sriov # VNF name as introduced in OPENMANO DB
+ passthrough: # vnf/net name in the scenario
+ vnf_name: passthrough # VNF name as introduced in OPENMANO DB
+ networks:
+ mgmt: # provide a name for this net or connection
+ external: true
+ interfaces:
+ - sriov: eth0 # Node and its interface
+ - passthrough: eth0 # Node and its interface
+ dataplane: # provide a name for this net or connection
+ interfaces:
+ - sriov: xe0 # Node and its interface
+ - passthrough: xe0 # Node and its interface
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: passthrough
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: passthrough-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: passthrough-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: passthrough-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "yes" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
--- /dev/null
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+---
+vnf:
+ name: sriov
+ description: Machine with EPA and a SR-IOV interface
+ external-connections:
+ - name: eth0
+ type: bridge
+ VNFC: sriov-VM
+ local_iface_name: eth0
+ description: management interface
+ - name: xe0
+ type: data
+ VNFC: sriov-VM
+ local_iface_name: xe0
+ description: Dataplane interface
+ VNFC:
+ - name: sriov-VM
+ description: Machine with EPA and a SR-IOV interface
+ image name: centos
+ disk: 20
+ numas:
+ - threads: 1 # "cores", "paired-threads", "threads"
+ memory: 1 # GBytes
+ interfaces:
+ - name: xe0
+ vpci: "0000:00:11.0"
+ dedicated: "no" # "yes"(passthrough), "no"(sriov with vlan tags), "yes:sriov"(sriovi, but exclusive and without vlan tag)
+ bandwidth: 1 Gbps
+
+ bridge-ifaces:
+ - name: eth0
+ vpci: "0000:00:0a.0"
+
global scenario_test_folder
global test_image_name
global management_network
+global manual
+
+def check_instance_scenario_active(uuid):
+ instance = client.get_instance(uuid=uuid)
+
+ for net in instance['nets']:
+ status = net['status']
+ if status != 'ACTIVE':
+ return (False, status)
+
+ for vnf in instance['vnfs']:
+ for vm in vnf['vms']:
+ status = vm['status']
+ if status != 'ACTIVE':
+ return (False, status)
+
+ return (True, None)
'''
IMPORTANT NOTE
self.__class__.test_index += 1
instance = client.create_instance(scenario_id=self.__class__.scenario_uuid, name=self.__class__.test_text)
+ self.__class__.instance_scenario_uuid = instance['uuid']
logger.debug(instance)
self.__class__.to_delete_list.insert(0, {"item": "instance", "function": client.delete_instance,
"params": {"uuid": instance['uuid']}})
- def test_020_clean_deployment(self):
+ def test_020_check_deployent(self):
+ self.__class__.test_text = "{}.{}. TEST {} {}".format(test_number, self.__class__.test_index,
+ inspect.currentframe().f_code.co_name,
+ scenario_test_folder)
+ self.__class__.test_index += 1
+
+ if manual:
+ raw_input('Scenario has been deployed. Perform manual check and press any key to resume')
+ return
+
+ keep_waiting = 50
+ instance_active = False
+ while(keep_waiting):
+ result = check_instance_scenario_active(self.__class__.instance_scenario_uuid)
+ if result[0]:
+ break
+ elif 'ERROR' in result[1]:
+ msg = 'Got error while waiting for the instance to get active: '+result[1]
+ logging.error(msg)
+ raise Exception(msg)
+
+ keep_waiting -= 1
+ time.sleep(5)
+
+ if keep_waiting == 0:
+ msg = 'Timeout reached while waiting instance scenario to get active'
+ logging.error(msg)
+ raise Exception(msg)
+
+ def test_030_clean_deployment(self):
self.__class__.test_text = "{}.{}. TEST {} {}".format(test_number, self.__class__.test_index,
inspect.currentframe().f_code.co_name,
scenario_test_folder)
default=default_logger_file)
parser.add_option('--list-tests', help='List all available tests', dest='list-tests', action="store_true",
default=False)
+ parser.add_option('-m', '--manual-check', help='Pause execution once deployed to allow manual checking of the deployed instance scenario', dest='manual', action="store_true", default=False)
parser.add_option('--test', '--tests', help='Specify the tests to run', dest='tests', default=None)
#Mandatory arguments
# set test image name and management network
test_image_name = options.__dict__['image-name']
management_network = options.__dict__['mgmt-net']
+ manual = options.__dict__['manual']
#Create the list of tests to be run
descriptor_based_tests = []
import logging
import vimconn
from db_base import db_base_Exception
-#from openvim.ovim import ovimException
+from ovim import ovimException
# from logging import Logger
self.task_lock = task_lock
self.task_queue = Queue.Queue(2000)
+ self.refresh_list = []
+ """Contains time ordered task list for refreshing the status of VIM VMs and nets"""
+
+ def _refres_elements(self):
+ """Call VIM to get VMs and networks status until 10 elements"""
+ now = time.time()
+ vm_to_refresh_list = []
+ net_to_refresh_list = []
+ vm_to_refresh_dict = {}
+ net_to_refresh_dict = {}
+ items_to_refresh = 0
+ while self.refresh_list:
+ task = self.refresh_list[0]
+ with self.task_lock:
+ if task['status'] == 'deleted':
+ self.refresh_list.pop(0)
+ continue
+ if task['time'] > now:
+ break
+ task["status"] = "processing"
+ self.refresh_list.pop(0)
+ if task["name"] == 'get-vm':
+ vm_to_refresh_list.append(task["vim_id"])
+ vm_to_refresh_dict[task["vim_id"]] = task
+ elif task["name"] == 'get-net':
+ net_to_refresh_list.append(task["vim_id"])
+ net_to_refresh_dict[task["vim_id"]] = task
+ else:
+ error_text = "unknown task {}".format(task["name"])
+ self.logger.error(error_text)
+ items_to_refresh += 1
+ if items_to_refresh == 10:
+ break
+
+ if vm_to_refresh_list:
+ try:
+ vim_dict = self.vim.refresh_vms_status(vm_to_refresh_list)
+ for vim_id, vim_info in vim_dict.items():
+ #look for task
+ task = vm_to_refresh_dict[vim_id]
+ self.logger.debug("get-vm vm_id=%s result=%s", task["vim_id"], str(vim_info))
+
+ # update database
+ if vim_info.get("error_msg"):
+ vim_info["error_msg"] = self._format_vim_error_msg(vim_info["error_msg"])
+ if task["vim_info"].get("status") != vim_info["status"] or \
+ task["vim_info"].get("error_msg") != vim_info.get("error_msg") or \
+ task["vim_info"].get("vim_info") != vim_info["vim_info"]:
+ with self.db_lock:
+ temp_dict = {"status": vim_info["status"],
+ "error_msg": vim_info.get("error_msg"),
+ "vim_info": vim_info["vim_info"]}
+ self.db.update_rows('instance_vms', UPDATE=temp_dict, WHERE={"vim_vm_id": vim_id})
+ for interface in vim_info["interfaces"]:
+ for task_interface in task["vim_info"]["interfaces"]:
+ if task_interface["vim_net_id"] == interface["vim_net_id"]:
+ break
+ else:
+ task_interface = {"vim_net_id": interface["vim_net_id"]}
+ task["vim_info"]["interfaces"].append(task_interface)
+ if task_interface != interface:
+ #delete old port
+ if task_interface.get("sdn_port_id"):
+ try:
+ self.ovim.delete_port(task_interface["sdn_port_id"])
+ task_interface["sdn_port_id"] = None
+ except ovimException as e:
+ self.logger.error("ovimException deleting external_port={} ".format(
+ task_interface["sdn_port_id"]) + str(e), exc_info=True)
+ # TODO Set error_msg at instance_nets
+ vim_net_id = interface.pop("vim_net_id")
+ sdn_net_id = None
+ sdn_port_name = None
+ with self.db_lock:
+ where_= {'iv.vim_vm_id': vim_id, "ine.vim_net_id": vim_net_id,
+ 'ine.datacenter_tenant_id': self.datacenter_tenant_id}
+ # TODO check why vim_interface_id is not present at database
+ # if interface.get("vim_interface_id"):
+ # where_["vim_interface_id"] = interface["vim_interface_id"]
+ db_ifaces = self.db.get_rows(
+ FROM="instance_interfaces as ii left join instance_nets as ine on "
+ "ii.instance_net_id=ine.uuid left join instance_vms as iv on "
+ "ii.instance_vm_id=iv.uuid",
+ SELECT=("ii.uuid as iface_id", "ine.uuid as net_id", "iv.uuid as vm_id", "sdn_net_id"),
+ WHERE=where_)
+ if len(db_ifaces)>1:
+ self.logger.critical("Refresing interfaces. "
+ "Found more than one interface at database for '{}'".format(where_))
+ elif len(db_ifaces)==0:
+ self.logger.critical("Refresing interfaces. "
+ "Not found any interface at database for '{}'".format(where_))
+ continue
+ else:
+ db_iface = db_ifaces[0]
+ if db_iface.get("sdn_net_id") and interface.get("compute_node") and interface.get("pci"):
+ sdn_net_id = db_iface["sdn_net_id"]
+ sdn_port_name = sdn_net_id + "." + db_iface["vm_id"]
+ sdn_port_name = sdn_port_name[:63]
+ try:
+ sdn_port_id = self.ovim.new_external_port(
+ {"compute_node": interface["compute_node"],
+ "pci": interface["pci"],
+ "vlan": interface.get("vlan"),
+ "net_id": sdn_net_id,
+ "region": self.vim["config"]["datacenter_id"],
+ "name": sdn_port_name,
+ "mac": interface.get("mac_address")})
+ interface["sdn_port_id"] = sdn_port_id
+ except (ovimException, Exception) as e:
+ self.logger.error(
+ "ovimException creating new_external_port compute_node={} " \
+ "pci={} vlan={} ".format(
+ interface["compute_node"],
+ interface["pci"],
+ interface.get("vlan")) + str(e),
+ exc_info=True)
+ # TODO Set error_msg at instance_nets
+ with self.db_lock:
+ self.db.update_rows('instance_interfaces', UPDATE=interface,
+ WHERE={'uuid': db_iface["iface_id"]})
+ # TODO insert instance_id
+ interface["vim_net_id"] = vim_net_id
+
+ task["vim_info"] = vim_info
+ if task["vim_info"]["status"] == "BUILD":
+ self._insert_refresh(task, now+5) # 5seconds
+ else:
+ self._insert_refresh(task, now+300) # 5minutes
+ except vimconn.vimconnException as e:
+ self.logger.error("vimconnException Exception when trying to refresh vms " + str(e))
+ self._insert_refresh(task, now + 300) # 5minutes
+
+ if net_to_refresh_list:
+ try:
+ vim_dict = self.vim.refresh_nets_status(net_to_refresh_list)
+ for vim_id, vim_info in vim_dict.items():
+ #look for task
+ task = net_to_refresh_dict[vim_id]
+ self.logger.debug("get-net net_id=%s result=%s", task["vim_id"], str(vim_info))
+
+ #get database info
+ where_ = {"vim_net_id": vim_id, 'datacenter_tenant_id': self.datacenter_tenant_id}
+ with self.db_lock:
+ db_nets = self.db.get_rows(
+ FROM="instance_nets",
+ SELECT=("uuid as net_id", "sdn_net_id"),
+ WHERE=where_)
+ if len(db_nets) > 1:
+ self.logger.critical("Refresing networks. "
+ "Found more than one instance-networks at database for '{}'".format(where_))
+ elif len(db_nets) == 0:
+ self.logger.critical("Refresing networks. "
+ "Not found any instance-network at database for '{}'".format(where_))
+ continue
+ else:
+ db_net = db_nets[0]
+ if db_net.get("sdn_net_id"):
+ # get ovim status
+ try:
+ sdn_net = self.ovim.show_network(db_net["sdn_net_id"])
+ if sdn_net["status"] == "ERROR":
+ if not vim_info.get("error_msg"):
+ vim_info["error_msg"] = sdn_net["error_msg"]
+ else:
+ vim_info["error_msg"] = "VIM_ERROR: {} && SDN_ERROR: {}".format(
+ self._format_vim_error_msg(vim_info["error_msg"], 1024//2-14),
+ self._format_vim_error_msg(sdn_net["error_msg"], 1024//2-14))
+ if vim_info["status"] == "VIM_ERROR":
+ vim_info["status"] = "VIM_SDN_ERROR"
+ else:
+ vim_info["status"] = "SDN_ERROR"
+
+ except (ovimException, Exception) as e:
+ self.logger.error(
+ "ovimException getting network infor snd_net_id={}".format(db_net["sdn_net_id"]),
+ exc_info=True)
+ # TODO Set error_msg at instance_nets
+
+ # update database
+ if vim_info.get("error_msg"):
+ vim_info["error_msg"] = self._format_vim_error_msg(vim_info["error_msg"])
+ if task["vim_info"].get("status") != vim_info["status"] or \
+ task["vim_info"].get("error_msg") != vim_info.get("error_msg") or \
+ task["vim_info"].get("vim_info") != vim_info["vim_info"]:
+ with self.db_lock:
+ temp_dict = {"status": vim_info["status"],
+ "error_msg": vim_info.get("error_msg"),
+ "vim_info": vim_info["vim_info"]}
+ self.db.update_rows('instance_nets', UPDATE=temp_dict, WHERE={"vim_net_id": vim_id})
+
+ task["vim_info"] = vim_info
+ if task["vim_info"]["status"] == "BUILD":
+ self._insert_refresh(task, now+5) # 5seconds
+ else:
+ self._insert_refresh(task, now+300) # 5minutes
+ except vimconn.vimconnException as e:
+ self.logger.error("vimconnException Exception when trying to refresh nets " + str(e))
+ self._insert_refresh(task, now + 300) # 5minutes
+
+ if not items_to_refresh:
+ time.sleep(1)
+
+ def _insert_refresh(self, task, threshold_time):
+ """Insert a task at list of refreshing elements. The refreshing list is ordered by threshold_time (task['time']
+ It is assumed that this is called inside this thread
+ """
+ task["time"] = threshold_time
+ for index in range(0, len(self.refresh_list)):
+ if self.refresh_list[index]["time"] > threshold_time:
+ self.refresh_list.insert(index, task)
+ break
+ else:
+ index = len(self.refresh_list)
+ self.refresh_list.append(task)
+ self.logger.debug("new refresh task={} name={}, time={} index={}".format(
+ task["id"], task["name"], task["time"], index))
+
+ def _remove_refresh(self, task_name, vim_id):
+ """Remove a task with this name and vim_id from the list of refreshing elements.
+ It is assumed that this is called inside this thread outside _refres_elements method
+ Return True if self.refresh_list is modified, task is found
+ Return False if not found
+ """
+ index_to_delete = None
+ for index in range(0, len(self.refresh_list)):
+ if self.refresh_list[index]["name"] == task_name and self.refresh_list[index]["vim_id"] == vim_id:
+ index_to_delete = index
+ break
+ else:
+ return False
+ if index_to_delete != None:
+ del self.refresh_list[index_to_delete]
+ return True
def insert_task(self, task):
try:
while True:
#TODO reload service
while True:
- if not self.task_queue.empty():
- task = self.task_queue.get()
- self.task_lock.acquire()
- if task["status"] == "deleted":
+ try:
+ if not self.task_queue.empty():
+ task = self.task_queue.get()
+ self.task_lock.acquire()
+ if task["status"] == "deleted":
+ self.task_lock.release()
+ continue
+ task["status"] = "processing"
self.task_lock.release()
+ else:
+ self._refres_elements()
continue
- task["status"] == "processing"
- self.task_lock.release()
- else:
- now=time.time()
- time.sleep(1)
- continue
- self.logger.debug("processing task id={} name={} params={}".format(task["id"], task["name"],
- str(task["params"])))
- if task["name"] == 'exit' or task["name"] == 'reload':
- result, content = self.terminate(task)
- elif task["name"] == 'new-vm':
- result, content = self.new_vm(task)
- elif task["name"] == 'del-vm':
- result, content = self.del_vm(task)
- elif task["name"] == 'new-net':
- result, content = self.new_net(task)
- elif task["name"] == 'del-net':
- result, content = self.del_net(task)
- else:
- error_text = "unknown task {}".format(task["name"])
- self.logger.error(error_text)
- result = False
- content = error_text
+ self.logger.debug("processing task id={} name={} params={}".format(task["id"], task["name"],
+ str(task["params"])))
+ if task["name"] == 'exit' or task["name"] == 'reload':
+ result, content = self.terminate(task)
+ elif task["name"] == 'new-vm':
+ result, content = self.new_vm(task)
+ elif task["name"] == 'del-vm':
+ result, content = self.del_vm(task)
+ elif task["name"] == 'new-net':
+ result, content = self.new_net(task)
+ elif task["name"] == 'del-net':
+ result, content = self.del_net(task)
+ else:
+ error_text = "unknown task {}".format(task["name"])
+ self.logger.error(error_text)
+ result = False
+ content = error_text
+ self.logger.debug("task id={} name={} result={}:{} params={}".format(task["id"], task["name"],
+ result, content,
+ str(task["params"])))
- with self.task_lock:
- task["status"] = "done" if result else "error"
- task["result"] = content
- self.task_queue.task_done()
+ with self.task_lock:
+ task["status"] = "done" if result else "error"
+ task["result"] = content
+ self.task_queue.task_done()
- if task["name"] == 'exit':
- return 0
- elif task["name"] == 'reload':
- break
+ if task["name"] == 'exit':
+ return 0
+ elif task["name"] == 'reload':
+ break
+ except Exception as e:
+ self.logger.critical("Unexpected exception at run: " + str(e), exc_info=True)
self.logger.debug("Finishing")
def terminate(self, task):
return True, None
- def _format_vim_error_msg(self, error_text):
- if len(error_text) >= 1024:
- return error_text[:516] + " ... " + error_text[-500:]
+ def _format_vim_error_msg(self, error_text, max_length=1024):
+ if error_text and len(error_text) >= max_length:
+ return error_text[:max_length//2-3] + " ... " + error_text[-max_length//2+3:]
return error_text
def new_net(self, task):
net_type = params[1]
network = None
- #sdn_controller = self.vim.config.get('sdn-controller')
- sdn_controller = None
+ sdn_net_id = None
+ sdn_controller = self.vim.config.get('sdn-controller')
if sdn_controller and (net_type == "data" or net_type == "ptp"):
network = {"name": net_name, "type": net_type}
vim_net = self.vim.get_network(net_id)
if vim_net.get('encapsulation') != 'vlan':
- raise vimconn.vimconnException(net_name + "defined as type " + net_type + " but the created network in vim is " + vim_net['encapsulation'])
-
+ raise vimconn.vimconnException(
+ "net '{}' defined as type '{}' has not vlan encapsulation '{}'".format(
+ net_name, net_type, vim_net['encapsulation']))
network["vlan"] = vim_net.get('segmentation_id')
-
- sdn_net_id = None
- with self.db_lock:
- if network:
+ try:
sdn_net_id = self.ovim.new_network(network)
- self.db.update_rows("instance_nets", UPDATE={"vim_net_id": net_id, "sdn_net_id": sdn_net_id}, WHERE={"vim_net_id": task_id})
-
+ except (ovimException, Exception) as e:
+ self.logger.error("task=%s cannot create SDN network vim_net_id=%s input='%s' ovimException='%s'",
+ str(task_id), net_id, str(network), str(e))
+ with self.db_lock:
+ self.db.update_rows("instance_nets", UPDATE={"vim_net_id": net_id, "sdn_net_id": sdn_net_id},
+ WHERE={"vim_net_id": task_id})
+ new_refresh_task = {"status": "enqueued",
+ "id": task_id,
+ "name": "get-net",
+ "vim_id": net_id,
+ "vim_info": {} }
+ self._insert_refresh(new_refresh_task, time.time())
return True, net_id
except db_base_Exception as e:
self.logger.error("Error updating database %s", str(e))
except db_base_Exception as e:
self.logger.error("Error updating database %s", str(e))
return False, str(e)
- # except ovimException as e:
- # self.logger.error("Error creating NET in ovim, task=%s: %s", str(task_id), str(e))
- # return False, str(e)
+ #except ovimException as e:
+ # self.logger.error("Error creating NET in ovim, task=%s: %s", str(task_id), str(e))
+ # return False, str(e)
def new_vm(self, task):
try:
task_id = task["id"]
depends = task.get("depends")
net_list = params[5]
+ error_text = ""
for net in net_list:
- if is_task_id(net["net_id"]): # change task_id into network_id
+ if "net_id" in net and is_task_id(net["net_id"]): # change task_id into network_id
try:
task_net = depends[net["net_id"]]
with self.task_lock:
if task_net["status"] == "error":
- return False, "Cannot create VM because depends on a network that cannot be created: " + \
+ error_text = "Cannot create VM because depends on a network that cannot be created: " +\
str(task_net["result"])
+ break
elif task_net["status"] == "enqueued" or task_net["status"] == "processing":
- return False, "Cannot create VM because depends on a network still not created"
+ error_text = "Cannot create VM because depends on a network still not created"
+ break
network_id = task_net["result"]
net["net_id"] = network_id
except Exception as e:
- return False, "Error trying to map from task_id={} to task result: {}".format(net["net_id"],
- str(e))
- vm_id = self.vim.new_vminstance(*params)
+ error_text = "Error trying to map from task_id={} to task result: {}".format(
+ net["net_id"],str(e))
+ break
+ if not error_text:
+ vm_id = self.vim.new_vminstance(*params)
try:
with self.db_lock:
- self.db.update_rows("instance_vms", UPDATE={"vim_vm_id": vm_id}, WHERE={"vim_vm_id": task_id})
+ if error_text:
+ update = self.db.update_rows("instance_vms",
+ UPDATE={"status": "VIM_ERROR", "error_msg": error_text},
+ WHERE={"vim_vm_id": task_id})
+ else:
+ update = self.db.update_rows("instance_vms", UPDATE={"vim_vm_id": vm_id}, WHERE={"vim_vm_id": task_id})
+ if not update:
+ self.logger.error("task id={} name={} database not updated vim_vm_id={}".format(
+ task["id"], task["name"], vm_id))
except db_base_Exception as e:
self.logger.error("Error updating database %s", str(e))
+ if error_text:
+ return False, error_text
+ new_refresh_task = {"status": "enqueued",
+ "id": task_id,
+ "name": "get-vm",
+ "vim_id": vm_id,
+ "vim_info": {"interfaces":[]} }
+ self._insert_refresh(new_refresh_task, time.time())
return True, vm_id
except vimconn.vimconnException as e:
self.logger.error("Error creating VM, task=%s: %s", str(task_id), str(e))
self.db.update_rows("instance_vms",
UPDATE={"error_msg": self._format_vim_error_msg(str(e)), "status": "VIM_ERROR"},
WHERE={"vim_vm_id": task_id})
- except db_base_Exception as e:
- self.logger.error("Error updating database %s", str(e))
+ except db_base_Exception as edb:
+ self.logger.error("Error updating database %s", str(edb))
return False, str(e)
def del_vm(self, task):
- vm_id = task["params"]
+ vm_id = task["params"][0]
+ interfaces = task["params"][1]
if is_task_id(vm_id):
try:
task_create = task["depends"][vm_id]
if task_create["status"] == "error":
return True, "VM was not created. It has error: " + str(task_create["result"])
elif task_create["status"] == "enqueued" or task_create["status"] == "processing":
- return False, "Cannot delete VM because still creating"
+ return False, "Cannot delete VM vim_id={} because still creating".format(vm_id)
vm_id = task_create["result"]
except Exception as e:
return False, "Error trying to get task_id='{}':".format(vm_id, str(e))
try:
+ self._remove_refresh("get-vm", vm_id)
+ for iface in interfaces:
+ if iface.get("sdn_port_id"):
+ try:
+ self.ovim.delete_port(iface["sdn_port_id"])
+ except ovimException as e:
+ self.logger.error("ovimException deleting external_port={} at VM vim_id={} deletion ".format(
+ iface["sdn_port_id"], vm_id) + str(e), exc_info=True)
+ # TODO Set error_msg at instance_nets
+
return True, self.vim.delete_vminstance(vm_id)
except vimconn.vimconnException as e:
return False, str(e)
def del_net(self, task):
net_id = task["params"][0]
- #sdn_net_id = task["params"][1]
- sdn_net_id = None
+ sdn_net_id = task["params"][1]
if is_task_id(net_id):
try:
task_create = task["depends"][net_id]
except Exception as e:
return False, "Error trying to get task_id='{}':".format(net_id, str(e))
try:
+ self._remove_refresh("get-net", net_id)
result = self.vim.delete_network(net_id)
if sdn_net_id:
with self.db_lock:
return True, result
except vimconn.vimconnException as e:
return False, str(e)
- # except ovimException as e:
- # logging.error("Error deleting network from ovim. net_id: {}, sdn_net_id: {}".format(net_id, sdn_net_id))
- # return False, str(e)
+ except ovimException as e:
+ logging.error("Error deleting network from ovim. net_id: {}, sdn_net_id: {}".format(net_id, sdn_net_id))
+ return False, str(e)
+
vim_net_id: #network id where this interface is connected, if provided at creation
vim_interface_id: #interface/port VIM id
ip_address: #null, or text with IPv4, IPv6 address
- physical_compute: #identification of compute node where PF,VF interface is allocated
- physical_pci: #PCI address of the NIC that hosts the PF,VF
- physical_vlan: #physical VLAN used for VF
+ compute_node: #identification of compute node where PF,VF interface is allocated
+ pci: #PCI address of the NIC that hosts the PF,VF
+ vlan: #physical VLAN used for VF
"""
raise vimconnNotImplemented( "Should have implemented this" )
elif 'threads' in numa:
vcpus = numa['threads']
numa_properties["hw:cpu_policy"] = "isolated"
- for interface in numa.get("interfaces",() ):
- if interface["dedicated"]=="yes":
- raise vimconn.vimconnException("Passthrough interfaces are not supported for the openstack connector", http_code=vimconn.HTTP_Service_Unavailable)
- #TODO, add the key 'pci_passthrough:alias"="<label at config>:<number ifaces>"' when a way to connect it is available
+ # for interface in numa.get("interfaces",() ):
+ # if interface["dedicated"]=="yes":
+ # raise vimconn.vimconnException("Passthrough interfaces are not supported for the openstack connector", http_code=vimconn.HTTP_Service_Unavailable)
+ # #TODO, add the key 'pci_passthrough:alias"="<label at config>:<number ifaces>"' when a way to connect it is available
#create flavor
new_flavor=self.nova.flavors.create(name,
for net in net_list:
if not net.get("net_id"): #skip non connected iface
continue
- if net["type"]=="virtual" or net["type"]=="VF":
- port_dict={
- "network_id": net["net_id"],
- "name": net.get("name"),
- "admin_state_up": True
- }
- if net["type"]=="virtual":
- if "vpci" in net:
- metadata_vpci[ net["net_id"] ] = [[ net["vpci"], "" ]]
- else: # for VF
- if "vpci" in net:
- if "VF" not in metadata_vpci:
- metadata_vpci["VF"]=[]
- metadata_vpci["VF"].append([ net["vpci"], "" ])
- port_dict["binding:vnic_type"]="direct"
- if not port_dict["name"]:
- port_dict["name"]=name
- if net.get("mac_address"):
- port_dict["mac_address"]=net["mac_address"]
- if net.get("port_security") == False:
- port_dict["port_security_enabled"]=net["port_security"]
- new_port = self.neutron.create_port({"port": port_dict })
- net["mac_adress"] = new_port["port"]["mac_address"]
- net["vim_id"] = new_port["port"]["id"]
- net["ip"] = new_port["port"].get("fixed_ips", [{}])[0].get("ip_address")
- net_list_vim.append({"port-id": new_port["port"]["id"]})
- else: # for PF
- self.logger.warn("new_vminstance: Warning, can not connect a passthrough interface ")
- #TODO insert this when openstack consider passthrough ports as openstack neutron ports
+
+ port_dict={
+ "network_id": net["net_id"],
+ "name": net.get("name"),
+ "admin_state_up": True
+ }
+ if net["type"]=="virtual":
+ if "vpci" in net:
+ metadata_vpci[ net["net_id"] ] = [[ net["vpci"], "" ]]
+ elif net["type"]=="VF": # for VF
+ if "vpci" in net:
+ if "VF" not in metadata_vpci:
+ metadata_vpci["VF"]=[]
+ metadata_vpci["VF"].append([ net["vpci"], "" ])
+ port_dict["binding:vnic_type"]="direct"
+ else: #For PT
+ if "vpci" in net:
+ if "PF" not in metadata_vpci:
+ metadata_vpci["PF"]=[]
+ metadata_vpci["PF"].append([ net["vpci"], "" ])
+ port_dict["binding:vnic_type"]="direct-physical"
+ if not port_dict["name"]:
+ port_dict["name"]=name
+ if net.get("mac_address"):
+ port_dict["mac_address"]=net["mac_address"]
+ if net.get("port_security") == False:
+ port_dict["port_security_enabled"]=net["port_security"]
+ new_port = self.neutron.create_port({"port": port_dict })
+ net["mac_adress"] = new_port["port"]["mac_address"]
+ net["vim_id"] = new_port["port"]["id"]
+ net["ip"] = new_port["port"].get("fixed_ips", [{}])[0].get("ip_address")
+ net_list_vim.append({"port-id": new_port["port"]["id"]})
+
if net.get('floating_ip', False):
net['exit_on_floating_ip_error'] = True
external_network.append(net)
vim_net_id: #network id where this interface is connected
vim_interface_id: #interface/port VIM id
ip_address: #null, or text with IPv4, IPv6 address
- physical_compute: #identification of compute node where PF,VF interface is allocated
- physical_pci: #PCI address of the NIC that hosts the PF,VF
- physical_vlan: #physical VLAN used for VF
+ compute_node: #identification of compute node where PF,VF interface is allocated
+ pci: #PCI address of the NIC that hosts the PF,VF
+ vlan: #physical VLAN used for VF
'''
vm_dict={}
self.logger.debug("refresh_vms status: Getting tenant VM instance information from VIM")
interface["mac_address"] = port.get("mac_address")
interface["vim_net_id"] = port["network_id"]
interface["vim_interface_id"] = port["id"]
- interface["physical_compute"] = vm_vim['OS-EXT-SRV-ATTR:host']
- interface["physical_pci"] = None
- # TODO: At the moment sr-iov pci addresses are converted to PF pci addresses by setting the slot to 0x00
- # TODO: This is just a workaround valid for niantinc. Find a better way to do so
- if 'pci_slot' in port['binding:profile']:
- pci = list(port['binding:profile']['pci_slot'])
- pci[-4] = '0'
- pci[-3] = '0'
- interface["physical_pci"] = ''.join(pci)
- interface["physical_vlan"] = None
+ interface["compute_node"] = vm_vim['OS-EXT-SRV-ATTR:host']
+ interface["pci"] = None
+ if port['binding:profile'].get('pci_slot'):
+ # TODO: At the moment sr-iov pci addresses are converted to PF pci addresses by setting the slot to 0x00
+ # TODO: This is just a workaround valid for niantinc. Find a better way to do so
+ # CHANGE DDDD:BB:SS.F to DDDD:BB:00.(F%2) assuming there are 2 ports per nic
+ pci = port['binding:profile']['pci_slot']
+ # interface["pci"] = pci[:-4] + "00." + str(int(pci[-1]) % 2)
+ interface["pci"] = pci
+ interface["vlan"] = None
+ #if network is of type vlan and port is of type direct (sr-iov) then set vlan id
network = self.neutron.show_network(port["network_id"])
- if network['network'].get('provider:network_type') == 'vlan':
- interface["physical_vlan"] = network['network'].get('provider:segmentation_id')
+ if network['network'].get('provider:network_type') == 'vlan' and \
+ port.get("binding:vnic_type") == "direct":
+ interface["vlan"] = network['network'].get('provider:segmentation_id')
ips=[]
#look for floating ip address
floating_ip_dict = self.neutron.list_floatingips(port_id=port["id"])