installation script enhancement. Allow test/basictest install openvim in test mode
[osm/RO.git] / nfvo.py
diff --git a/nfvo.py b/nfvo.py
index 005e065..d4935bf 100644 (file)
--- a/nfvo.py
+++ b/nfvo.py
@@ -108,9 +108,9 @@ def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, da
     if vim_tenant_name is not None:  WHERE_dict['vim_tenant_name']  = vim_tenant_name
     if nfvo_tenant or vim_tenant or vim_tenant_name or datacenter_tenant_id:
         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','config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name',
+        select_ = ('type','d.config as config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name',
                    'dt.uuid as datacenter_tenant_id','dt.vim_tenant_name as vim_tenant_name','dt.vim_tenant_id as vim_tenant_id',
-                   'user','passwd')
+                   'user','passwd', 'dt.config as dt_config')
     else:
         from_ = 'datacenters as d'
         select_ = ('type','config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name')
@@ -119,8 +119,10 @@ def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, da
         vim_dict={}
         for vim in vims:
             extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id')}
-            if vim["config"] != None:
+            if vim["config"]:
                 extra.update(yaml.load(vim["config"]))
+            if vim.get('dt_config'):
+                extra.update(yaml.load(vim["dt_config"]))
             if vim["type"] not in vimconn_imported:
                 module_info=None
                 try:
@@ -354,7 +356,7 @@ def create_or_use_flavor(mydb, vims, flavor_dict, rollback_list, only_create_at_
             if 'extended' in flavor_dict and flavor_dict['extended']!=None:
                 dev_nb=0
                 for device in flavor_dict['extended'].get('devices',[]):
-                    if "image" not in device or "image name" not in device:
+                    if "image" not in device and "image name" not in device:
                         continue
                     image_dict={}
                     image_dict['name']=device.get('image name',flavor_dict['name']+str(dev_nb)+"-img")
@@ -1403,7 +1405,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc
                 i += 1
                 myVMDict = {}
                 #myVMDict['name'] = "%s-%s-%s" % (scenarioDict['name'],sce_vnf['name'], vm['name'])
-                myVMDict['name'] = "%s.%s.%d" % (instance_scenario_name,sce_vnf['name'],i)
+                myVMDict['name'] = "{}.{}.{}".format(instance_scenario_name,sce_vnf['name'],chr(96+i))
                 #myVMDict['description'] = vm['description']
                 myVMDict['description'] = myVMDict['name'][0:99]
                 if not startvms:
@@ -1905,7 +1907,7 @@ def create_instance(mydb, tenant_id, instance_dict):
             for vm in sce_vnf['vms']:
                 i += 1
                 myVMDict = {}
-                myVMDict['name'] = "%s.%s.%d" % (instance_name,sce_vnf['name'],i)
+                myVMDict['name'] = "{}.{}.{}".format(instance_name,sce_vnf['name'],chr(96+i))
                 myVMDict['description'] = myVMDict['name'][0:99]
 #                if not startvms:
 #                    myVMDict['start'] = "no"
@@ -2169,6 +2171,8 @@ def refresh_instance(mydb, nfvo_tenant, instanceDict, datacenter=None, vim_tenan
                     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')
@@ -2221,6 +2225,8 @@ def refresh_instance(mydb, nfvo_tenant, instanceDict, datacenter=None, vim_tenan
     # 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')
@@ -2409,7 +2415,7 @@ def delete_datacenter(mydb, datacenter):
     mydb.delete_row_by_id("datacenters", datacenter_dict['uuid'])
     return datacenter_dict['uuid'] + " " + datacenter_dict['name']
 
-def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=None, vim_tenant_name=None, vim_username=None, vim_password=None):
+def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=None, vim_tenant_name=None, vim_username=None, vim_password=None, config=None):
     #get datacenter info
     datacenter_id, myvim  = get_datacenter_by_name_uuid(mydb, None, datacenter)
     datacenter_name=myvim["name"]
@@ -2459,6 +2465,8 @@ def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=
         datacenter_tenants_dict["user"]            = vim_username
         datacenter_tenants_dict["passwd"]          = vim_password
         datacenter_tenants_dict["datacenter_id"]   = datacenter_id
+        if config:
+            datacenter_tenants_dict["config"] = yaml.safe_dump(config, default_flow_style=True, width=256)
         id_ = mydb.new_row('datacenter_tenants', datacenter_tenants_dict, add_uuid=True)
         datacenter_tenants_dict["uuid"] = id_