Feature 5649 Alternative images for VIM specific
[osm/RO.git] / osm_ro / nfvo_db.py
index 87e3f1e..71ccfbf 100644 (file)
@@ -598,15 +598,15 @@ class nfvo_db(db_base.db_base):
                             vnf['mgmt_access'] = yaml.load(mgmt_access_dict[0]['mgmt_access'])
                         else:
                             vnf['mgmt_access'] = None
-                        #sce_interfaces
+                        # sce_interfaces
                         cmd = "SELECT scei.uuid,scei.sce_net_id,scei.interface_id,i.external_name,scei.ip_address"\
                               " FROM sce_interfaces as scei join interfaces as i on scei.interface_id=i.uuid"\
                               " WHERE scei.sce_vnf_id='{}' ORDER BY scei.created_at".format(vnf['uuid'])
                         self.logger.debug(cmd)
                         self.cur.execute(cmd)
                         vnf['interfaces'] = self.cur.fetchall()
-                        #vms
-                        cmd = "SELECT vms.uuid as uuid, flavor_id, image_id, vms.name as name," \
+                        # vms
+                        cmd = "SELECT vms.uuid as uuid, flavor_id, image_id, image_list, vms.name as name," \
                               " vms.description as description, vms.boot_data as boot_data, count," \
                               " vms.availability_zone as availability_zone" \
                               " FROM vnfs join vms on vnfs.uuid=vms.vnf_id" \
@@ -620,6 +620,10 @@ class nfvo_db(db_base.db_base):
                                 vm["boot_data"] = yaml.safe_load(vm["boot_data"])
                             else:
                                 del vm["boot_data"]
+                            if vm["image_list"]:
+                                vm["image_list"] = yaml.safe_load(vm["image_list"])
+                            else:
+                                del vm["image_list"]
                             if datacenter_vim_id!=None:
                                 cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND datacenter_vim_id='{}'".format(vm['image_id'],datacenter_vim_id)
                                 self.logger.debug(cmd)
@@ -643,9 +647,14 @@ class nfvo_db(db_base.db_base):
                             self.logger.debug(cmd)
                             self.cur.execute(cmd)
                             vm['interfaces'] = self.cur.fetchall()
-                            for index in range(0,len(vm['interfaces'])):
-                                vm['interfaces'][index]['port-security'] = vm['interfaces'][index].pop("port_security")
-                                vm['interfaces'][index]['floating-ip'] = vm['interfaces'][index].pop("floating_ip")
+                            for iface in vm['interfaces']:
+                                iface['port-security'] = iface.pop("port_security")
+                                iface['floating-ip'] = iface.pop("floating_ip")
+                                for sce_interface in vnf["interfaces"]:
+                                    if sce_interface["interface_id"] == iface["uuid"]:
+                                        if sce_interface["ip_address"]:
+                                            iface["ip_address"] = sce_interface["ip_address"]
+                                        break
                         #nets    every net of a vms
                         cmd = "SELECT uuid,name,type,description FROM nets WHERE vnf_id='{}'".format(vnf['vnf_id'])  
                         self.logger.debug(cmd)
@@ -949,7 +958,7 @@ class nfvo_db(db_base.db_base):
                     cmd = "SELECT inst.uuid as uuid, inst.name as name, inst.scenario_id as scenario_id, datacenter_id"\
                                 " ,datacenter_tenant_id, s.name as scenario_name,inst.tenant_id as tenant_id" \
                                 " ,inst.description as description, inst.created_at as created_at" \
-                                " ,inst.cloud_config as cloud_config" \
+                                " ,inst.cloud_config as cloud_config, s.osm_id as nsd_osm_id" \
                             " FROM instance_scenarios as inst left join scenarios as s on inst.scenario_id=s.uuid" \
                             " WHERE " + where_text
                     self.logger.debug(cmd)
@@ -968,7 +977,7 @@ class nfvo_db(db_base.db_base):
                     
                     # instance_vnfs
                     cmd = "SELECT iv.uuid as uuid, iv.vnf_id as vnf_id, sv.name as vnf_name, sce_vnf_id, datacenter_id"\
-                                " ,datacenter_tenant_id, v.mgmt_access, sv.member_vnf_index "\
+                                " ,datacenter_tenant_id, v.mgmt_access, sv.member_vnf_index, v.osm_id as vnfd_osm_id "\
                             " FROM instance_vnfs as iv left join sce_vnfs as sv "\
                                 "on iv.sce_vnf_id=sv.uuid join vnfs as v on iv.vnf_id=v.uuid" \
                             " WHERE iv.instance_scenario_id='{}'" \
@@ -979,7 +988,8 @@ class nfvo_db(db_base.db_base):
                     for vnf in instance_dict['vnfs']:
                         vnf_manage_iface_list=[]
                         #instance vms
-                        cmd = "SELECT iv.uuid as uuid, vim_vm_id, status, error_msg, vim_info, iv.created_at as created_at, name"\
+                        cmd = "SELECT iv.uuid as uuid, vim_vm_id, status, error_msg, vim_info, iv.created_at as "\
+                               "created_at, name, vms.osm_id as vdu_osm_id"\
                                 " FROM instance_vms as iv join vms on iv.vm_id=vms.uuid "\
                                 " WHERE instance_vnf_id='{}' ORDER BY iv.created_at".format(vnf['uuid'])
                         self.logger.debug(cmd)