+ net_list.append(net['vim_net_id'])
+ nets_notupdated.append(net["uuid"])
+
+ try:
+ # 1. Getting the status of all VMs
+ vm_dict = myvim.refresh_vms_status(vm_list)
+
+ # 2. Update the status of VMs in the instanceDict, while collects the VMs whose status changed
+ for sce_vnf in instanceDict['vnfs']:
+ for vm in sce_vnf['vms']:
+ vm_id = vm['vim_vm_id']
+ interfaces = vm_dict[vm_id].pop('interfaces', [])
+ #2.0 look if contain manamgement interface, and if not change status from ACTIVE:NoMgmtIP to ACTIVE
+ has_mgmt_iface = False
+ for iface in vm["interfaces"]:
+ if iface["type"]=="mgmt":
+ 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['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')
+ vm['vim_info'] = vm_dict[vm_id].get('vim_info')
+ # 2.1. Update in openmano DB the VMs whose status changed
+ try:
+ updates = mydb.update_rows('instance_vms', UPDATE=vm_dict[vm_id], WHERE={'uuid':vm["uuid"]})
+ vms_notupdated.remove(vm["uuid"])
+ if updates>0:
+ vms_updated.append(vm["uuid"])
+ except db_base_Exception as e:
+ logger.error("nfvo.refresh_instance error database update: %s", str(e))
+ # 2.2. Update in openmano DB the interface VMs
+ for interface in interfaces:
+ #translate from vim_net_id to instance_net_id
+ network_id=None
+ for net in instanceDict['nets']:
+ if net["vim_net_id"] == interface["vim_net_id"]:
+ network_id = net["uuid"]
+ break
+ if not network_id:
+ continue
+ del interface["vim_net_id"]
+ try:
+ mydb.update_rows('instance_interfaces', UPDATE=interface, WHERE={'instance_vm_id':vm["uuid"], "instance_net_id":network_id})
+ except db_base_Exception as e:
+ logger.error( "nfvo.refresh_instance error with vm=%s, interface_net_id=%s", vm["uuid"], network_id)
+
+ # 3. Getting the status of all nets
+ net_dict = myvim.refresh_nets_status(net_list)
+
+ # 4. Update the status of nets in the instanceDict, while collects the nets whose status changed
+ # TODO: update nets inside a vnf
+ for net in instanceDict['nets']:
+ net_id = net['vim_net_id']
+ 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')
+ net['vim_info'] = net_dict[net_id].get('vim_info')
+ # 5.1. Update in openmano DB the nets whose status changed
+ try:
+ updated = mydb.update_rows('instance_nets', UPDATE=net_dict[net_id], WHERE={'uuid':net["uuid"]})
+ nets_notupdated.remove(net["uuid"])
+ if updated>0:
+ nets_updated.append(net["uuid"])
+ except db_base_Exception as e:
+ logger.error("nfvo.refresh_instance error database update: %s", str(e))
+ except vimconn.vimconnException as e:
+ #logger.error("VIM exception %s %s", type(e).__name__, str(e))
+ raise NfvoException(str(e), e.http_code)