global global_config
global vimconn_imported
+global logger
vimconn_imported={} #dictionary with VIM type as key, loaded module as value
-logger = logging.getLogger('mano.nfvo')
+logger = logging.getLogger('openmano.nfvo')
class NfvoException(Exception):
def __init__(self, message, http_code):
imageList.append(image['image_id'])
return imageList
-def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, vim_tenant=None):
+def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, vim_tenant=None, vim_tenant_name=None, vim_user=None, vim_passwd=None):
'''Obtain a dictionary of VIM (datacenter) classes with some of the input parameters
return dictionary with {datacenter_id: vim_class, ... }. vim_class contain:
'nfvo_tenant_id','datacenter_id','vim_tenant_id','vim_url','vim_url_admin','datacenter_name','type','user','passwd'
# return -HTTP_Bad_Request, "You must provide a valid tenant name or uuid for VIM %s" % ( vim["type"])
vim_dict[ vim['datacenter_id'] ] = vimconn_imported[ vim["type"] ].vimconnector(
uuid=vim['datacenter_id'], name=vim['datacenter_name'],
- tenant_id=vim.get('vim_tenant_id'), tenant_name=vim.get('vim_tenant_name'),
+ tenant_id=vim.get('vim_tenant_id',vim_tenant), tenant_name=vim.get('vim_tenant_name',vim_tenant_name),
url=vim['vim_url'], url_admin=vim['vim_url_admin'],
- user=vim.get('user'), passwd=vim.get('passwd'),
+ user=vim.get('user',vim_user), passwd=vim.get('passwd',vim_passwd),
config=extra
)
except Exception as e:
#1.4 get list of connections
conections = topo['topology']['connections']
conections_list = []
+ conections_list_name = []
for k in conections.keys():
if type(conections[k]['nodes'])==dict: #dict with node:iface pairs
ifaces_list = conections[k]['nodes'].items()
if con_type == "dataplane_net" or con_type == "bridge_net":
other_nets[k]["model"] = con_type
-
+ conections_list_name.append(k)
conections_list.append(set(ifaces_list)) #from list to set to operate as a set (this conversion removes elements that are repeated in a list)
#print set(ifaces_list)
#check valid VNF and iface names
if len(conections_list[index] & conections_list[index2])>0: #common interface, join nets
conections_list[index] |= conections_list[index2]
del conections_list[index2]
+ del conections_list_name[index2]
else:
index2 += 1
conections_list[index] = list(conections_list[index]) # from set to list again
net_type_bridge=False
net_type_data=False
net_target = "__-__net"+str(net_nb)
- net_list[net_target] = {'name': "net-"+str(net_nb), 'description':"net-%s in scenario %s" %(net_nb,topo['name']),
+ net_list[net_target] = {'name': conections_list_name[net_nb], #"net-"+str(net_nb),
+ 'description':"net-%s in scenario %s" %(net_nb,topo['name']),
'external':False}
for iface in con:
vnfs[ iface[0] ]['ifaces'][ iface[1] ]['net_key'] = net_target
where={}
where_or={"tenant_id": tenant_id, 'public': "true"}
error_text = ""
- error_pos = "'topology':'nodes':'" + name + "'"
+ error_pos = "'scenario':'vnfs':'" + name + "'"
if 'vnf_id' in vnf:
error_text += " 'vnf_id' " + vnf['vnf_id']
where['uuid'] = vnf['vnf_id']
error_text += " 'vnf_name' " + vnf['vnf_name']
where['name'] = vnf['vnf_name']
if len(where) == 0:
- raise NfvoException("Needed a 'vnf_id' or 'VNF model' at " + error_pos, HTTP_Bad_Request)
+ raise NfvoException("Needed a 'vnf_id' or 'vnf_name' at " + error_pos, HTTP_Bad_Request)
vnf_db = mydb.get_rows(SELECT=('uuid','name','description'),
FROM='vnfs',
WHERE=where,
where={}
where_or={"tenant_id": tenant_id, 'public': "true"}
error_text = ""
- error_pos = "'topology':'nodes':'" + name + "'"
+ error_pos = "'scenario':'vnfs':'" + name + "'"
if 'vnf_id' in vnf:
error_text += " 'vnf_id' " + vnf['vnf_id']
where['uuid'] = vnf['vnf_id']
error_text += " 'vnf_name' " + vnf['vnf_name']
where['name'] = vnf['vnf_name']
if len(where) == 0:
- raise NfvoException("Needed a 'vnf_id' or 'VNF model' at " + error_pos, HTTP_Bad_Request)
+ raise NfvoException("Needed a 'vnf_id' or 'vnf_name' at " + error_pos, HTTP_Bad_Request)
vnf_db = mydb.get_rows(SELECT=('uuid','name','description'),
FROM='vnfs',
WHERE=where,
def create_instance(mydb, tenant_id, instance_dict):
#print "Checking that nfvo_tenant_id exists and getting the VIM URI and the VIM tenant_id"
- logger.debug("Creating instance...")
+ #logger.debug("Creating instance...")
scenario = instance_dict["scenario"]
#find main datacenter
auxNetDict = {} #Auxiliar dictionary. First key:'scenario' or sce_vnf uuid. Second Key: uuid of the net/sce_net. Value: vim_net_id
auxNetDict['scenario'] = {}
- logger.debug("scenario dict: {}".format(yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False))) #TODO remove
+ 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")
try:
ipprofile['dhcp_count'] = ipprofile['dhcp'].get('count',None)
del ipprofile['dhcp']
update(scenario_net['ip_profile'],ipprofile)
- for interface in net_instance_desc['interfaces']:
+ for interface in net_instance_desc.get('interfaces', () ):
if 'ip_address' in interface:
for vnf in scenarioDict['vnfs']:
if interface['vnf'] == vnf['name']:
if interface['vnf_interface'] == vnf_interface['external_name']:
vnf_interface['ip_address']=interface['ip_address']
- logger.debug("Merged dictionary")
- logger.debug("ScenarioDict:\n{}".format(yaml.safe_dump(scenarioDict,default_flow_style=False, width=256)))
+ #logger.debug("Merged dictionary")
+ logger.debug("Creating instance scenario-dict MERGED:\n%s", yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False))
#1. Creating new nets (sce_nets) in the VIM"
def new_datacenter(mydb, datacenter_descriptor):
if "config" in datacenter_descriptor:
datacenter_descriptor["config"]=yaml.safe_dump(datacenter_descriptor["config"],default_flow_style=True,width=256)
+ #Check that datacenter-type is correct
+ datacenter_type = datacenter_descriptor.get("type", "openvim");
+ module_info = None
+ try:
+ module = "vimconn_" + datacenter_type
+ module_info = imp.find_module(module)
+ except (IOError, ImportError):
+ if module_info and module_info[0]:
+ file.close(module_info[0])
+ raise NfvoException("Incorrect datacenter type '{}'. Plugin '{}'.py not installed".format(datacenter_type, module), HTTP_Bad_Request)
+
datacenter_id = mydb.new_row("datacenters", datacenter_descriptor, add_uuid=True)
return datacenter_id
def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=None, vim_tenant_name=None, vim_username=None, vim_password=None):
#get datacenter info
if utils.check_valid_uuid(datacenter):
- vims = get_vim(mydb, datacenter_id=datacenter)
+ vims = get_vim(mydb, datacenter_id=datacenter, vim_tenant_name=vim_tenant_name, vim_user=vim_username, vim_passwd=vim_password)
else:
- vims = get_vim(mydb, datacenter_name=datacenter)
+ vims = get_vim(mydb, datacenter_name=datacenter, vim_tenant_name=vim_tenant_name, vim_user=vim_username, vim_passwd=vim_password)
if len(vims) == 0:
raise NfvoException("datacenter '{}' not found".format(str(datacenter)), HTTP_Not_Found)
elif len(vims)>1: