for vim in vims:
extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id'),
'datacenter_id': vim.get('datacenter_id'),
- 'vim_type': vim.get('type')}
+ '_vim_type_internal': vim.get('type')}
if vim["config"]:
extra.update(yaml.load(vim["config"]))
if vim.get('dt_config'):
config=extra, persistent_info=persistent_info
)
except Exception as e:
- raise NfvoException("Error at VIM {}; {}: {}".format(vim["type"], type(e).__name__, str(e)), HTTP_Internal_Server_Error)
+ http_code = HTTP_Internal_Server_Error
+ if isinstance(e, vimconn.vimconnException):
+ http_code = e.http_code
+ raise NfvoException("Error at VIM {}; {}: {}".format(vim["type"], type(e).__name__, str(e)), http_code)
return vim_dict
except db_base_Exception as e:
raise NfvoException(str(e) + " at nfvo.get_vim", e.http_code)
db_sce_vnf = {
"uuid": sce_vnf_uuid,
"scenario_id": scenario_uuid,
- "name": existing_vnf[0]["name"][:200] + "." + get_str(vnf, "member-vnf-index", 5),
+ # "name": get_str(vnf, "member-vnf-index", 255),
+ "name": existing_vnf[0]["name"][:200] + "." + get_str(vnf, "member-vnf-index", 50),
"vnf_id": existing_vnf[0]["uuid"],
"member_vnf_index": str(vnf["member-vnf-index"]),
# TODO 'start-by-default': True
str(nsd["id"]), str(vld["id"]), str(vld["ip-profile-ref"])),
HTTP_Bad_Request)
db_ip_profiles[ip_profile_name2db_table_index[ip_profile_name]]["sce_net_id"] = sce_net_uuid
+ elif vld.get("vim-network-name"):
+ db_sce_net["vim_network_name"] = get_str(vld, "vim-network-name", 255)
# table sce_interfaces (vld:vnfd-connection-point-ref)
for iface in vld.get("vnfd-connection-point-ref").itervalues():
for vnf_name, vnf_instance_desc in instance_dict.get("vnfs",{}).iteritems():
found = False
for scenario_vnf in scenarioDict['vnfs']:
- if vnf_name == scenario_vnf['name']:
+ if vnf_name == scenario_vnf['name'] or vnf_name == scenario_vnf['member_vnf_index']:
found = True
break
if not found:
- raise NfvoException("Invalid vnf name '{}' at instance:vnfs".format(vnf_instance_desc), HTTP_Bad_Request)
+ raise NfvoException("Invalid vnf name '{}' at instance:vnfs".format(vnf_name), HTTP_Bad_Request)
if "datacenter" in vnf_instance_desc:
# Add this datacenter to myvims
vnf_instance_desc["datacenter"] = get_datacenter_uuid(mydb, tenant_id, vnf_instance_desc["datacenter"])
# yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False))
# 1. Creating new nets (sce_nets) in the VIM"
+ number_mgmt_networks = 0
db_instance_nets = []
for sce_net in scenarioDict['nets']:
descriptor_net = instance_dict.get("networks", {}).get(sce_net["name"], {})
net_name = "{}.{}".format(instance_name, sce_net["name"])
net_name = net_name[:255] # limit length
+ if sce_net["external"]:
+ number_mgmt_networks += 1
if "netmap-use" in site or "netmap-create" in site:
create_network = False
lookfor_network = False
if "netmap-use" in site:
lookfor_network = True
if utils.check_valid_uuid(site["netmap-use"]):
- filter_text = "scenario id '%s'" % site["netmap-use"]
lookfor_filter["id"] = site["netmap-use"]
else:
- filter_text = "scenario name '%s'" % site["netmap-use"]
lookfor_filter["name"] = site["netmap-use"]
if "netmap-create" in site:
create_network = True
net_vim_name = net_name
if site["netmap-create"]:
net_vim_name = site["netmap-create"]
+ elif sce_net.get("vim_network_name"):
+ create_network = False
+ lookfor_network = True
+ lookfor_filter["name"] = sce_net.get("vim_network_name")
elif sce_net["external"]:
if sce_net['vim_id'] != None:
# there is a netmap at datacenter_nets database # TODO REVISE!!!!
create_network = False
lookfor_network = True
lookfor_filter["id"] = sce_net['vim_id']
- filter_text = "vim_id '{}' datacenter_netmap name '{}'. Try to reload vims with "\
- "datacenter-net-update".format(sce_net['vim_id'], sce_net["name"])
- # look for network at datacenter and return error
+ elif vim["config"].get("management_network_id") or vim["config"].get("management_network_name"):
+ if number_mgmt_networks > 1:
+ raise NfvoException("Found several VLD of type mgmt. "
+ "You must concrete what vim-network must be use for each one",
+ HTTP_Bad_Request)
+ create_network = False
+ lookfor_network = True
+ if vim["config"].get("management_network_id"):
+ lookfor_filter["id"] = vim["config"]["management_network_id"]
+ else:
+ lookfor_filter["name"] = vim["config"]["management_network_name"]
else:
# There is not a netmap, look at datacenter for a net with this name and create if not found
create_network = True
lookfor_network = True
lookfor_filter["name"] = sce_net["name"]
net_vim_name = sce_net["name"]
- filter_text = "scenario name '%s'" % sce_net["name"]
else:
net_vim_name = net_name
create_network = True
image_uuid = vm['image_id']
if vm.get("image_list"):
for alternative_image in vm["image_list"]:
- if alternative_image["vim_type"] == vim["config"]["vim_type"]:
+ if alternative_image["vim_type"] == vim["config"]["_vim_type_internal"]:
image_uuid = alternative_image['image_id']
break
image_dict = mydb.get_table_by_uuid_name("images", image_uuid)
WHERE={'vim_id': flavor_id})
if not extended_flavor_dict:
raise NfvoException("flavor '{}' not found".format(flavor_id), HTTP_Not_Found)
- return
# extended_flavor_dict_yaml = yaml.load(extended_flavor_dict[0])
myVMDict['disks'] = None
input_vnfs = action_dict.pop("vnfs", [])
input_vms = action_dict.pop("vms", [])
- action_over_all = True if len(input_vnfs)==0 and len (input_vms)==0 else False
+ action_over_all = True if not input_vnfs and not input_vms else False
vm_result = {}
vm_error = 0
vm_ok = 0
for sce_vnf in instanceDict['vnfs']:
for vm in sce_vnf['vms']:
- if not action_over_all:
- if sce_vnf['uuid'] not in input_vnfs and sce_vnf['vnf_name'] not in input_vnfs and \
- vm['uuid'] not in input_vms and vm['name'] not in input_vms:
- continue
+ if not action_over_all and sce_vnf['uuid'] not in input_vnfs and sce_vnf['vnf_name'] not in input_vnfs and \
+ sce_vnf['member_vnf_index'] not in input_vnfs and \
+ vm['uuid'] not in input_vms and vm['name'] not in input_vms:
+ continue
try:
if "add_public_key" in action_dict:
mgmt_access = {}
def new_datacenter(mydb, datacenter_descriptor):
+ sdn_port_mapping = None
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
+ sdn_port_mapping = datacenter_descriptor["config"].pop("sdn-port-mapping", None)
+ 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
+ # module_info = None
try:
module = "vimconn_" + datacenter_type
pkg = __import__("osm_ro." + module)
- vim_conn = getattr(pkg, module)
+ # vim_conn = getattr(pkg, module)
# module_info = imp.find_module(module, [__file__[:__file__.rfind("/")]])
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)
+ 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, confidential_data=True)
+ if sdn_port_mapping:
+ try:
+ datacenter_sdn_port_mapping_set(mydb, None, datacenter_id, sdn_port_mapping)
+ except Exception as e:
+ mydb.delete_row_by_id("datacenters", datacenter_id) # Rollback
+ raise e
return datacenter_id
datacenter_id = datacenter['uuid']
where={'uuid': datacenter['uuid']}
remove_port_mapping = False
+ new_sdn_port_mapping = None
if "config" in datacenter_descriptor:
if datacenter_descriptor['config'] != None:
try:
new_config_dict = datacenter_descriptor["config"]
+ if "sdn-port-mapping" in new_config_dict:
+ remove_port_mapping = True
+ new_sdn_port_mapping = new_config_dict.pop("sdn-port-mapping")
#delete null fields
to_delete=[]
for k in new_config_dict:
logger.error("Error deleting datacenter-port-mapping " + str(e))
mydb.update_rows('datacenters', datacenter_descriptor, where)
+ if new_sdn_port_mapping:
+ try:
+ datacenter_sdn_port_mapping_set(mydb, None, datacenter_id, new_sdn_port_mapping)
+ except ovimException as e:
+ logger.error("Error adding datacenter-port-mapping " + str(e))
return datacenter_id
logger.error("Cannot delete datacenter_tenants " + str(e))
pass # the error will be caused because dependencies, vim_tenant can not be deleted
thread_id = tenant_datacenter_item["datacenter_tenant_id"]
- thread = vim_threads["running"][thread_id]
- thread.insert_task("exit")
- vim_threads["deleting"][thread_id] = thread
+ thread = vim_threads["running"].get(thread_id)
+ if thread:
+ thread.insert_task("exit")
+ vim_threads["deleting"][thread_id] = thread
return "datacenter {} detached. {}".format(datacenter_id, warning)