def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, datacenter_tenant_id=None,
- vim_tenant=None, vim_tenant_name=None, vim_user=None, vim_passwd=None):
+ vim_tenant=None, vim_tenant_name=None, vim_user=None, vim_passwd=None, ignore_errors=False):
'''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'
except (IOError, ImportError) as e:
# if module_info and module_info[0]:
# file.close(module_info[0])
+ if ignore_errors:
+ logger.error("Unknown vim type '{}'. Can not open file '{}.py'; {}: {}".format(
+ vim["type"], module, type(e).__name__, str(e)))
+ continue
raise NfvoException("Unknown vim type '{}'. Can not open file '{}.py'; {}: {}".format(
vim["type"], module, type(e).__name__, str(e)), HTTP_Bad_Request)
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)
+ if ignore_errors:
+ logger.error("Error at VIM {}; {}: {}".format(vim["type"], type(e).__name__, str(e)))
+ continue
+ 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)
vnf_descriptor['vnf']['tenant_id'] = tenant_id
# Step 3. Get the URL of the VIM from the nfvo_tenant and the datacenter
if global_config["auto_push_VNF_to_VIMs"]:
- vims = get_vim(mydb, tenant_id)
+ vims = get_vim(mydb, tenant_id, ignore_errors=True)
# Step 4. Review the descriptor and add missing fields
#print vnf_descriptor
vnf_descriptor['vnf']['tenant_id'] = tenant_id
# Step 3. Get the URL of the VIM from the nfvo_tenant and the datacenter
if global_config["auto_push_VNF_to_VIMs"]:
- vims = get_vim(mydb, tenant_id)
+ vims = get_vim(mydb, tenant_id, ignore_errors=True)
# Step 4. Review the descriptor and add missing fields
#print vnf_descriptor
if tenant_id != "any":
check_tenant(mydb, tenant_id)
# Get the URL of the VIM from the nfvo_tenant and the datacenter
- vims = get_vim(mydb, tenant_id)
+ vims = get_vim(mydb, tenant_id, ignore_errors=True)
else:
vims={}
"created": create_network,
'datacenter_id': datacenter_id,
'datacenter_tenant_id': myvim_thread_id,
- 'status': 'BUILD' if create_network else "ACTIVE"
+ 'status': 'BUILD' # if create_network else "ACTIVE"
}
db_instance_nets.append(db_net)
db_vim_action = {
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)