Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Jun 7, 2019
1 parent d2c93d4 commit 35d047b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 10 additions & 2 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ def AddResource(inf_id, radl_data, auth, context=True):
sel_inf.update_radl(radl, [])
InfrastructureManager.logger.warn("Inf ID: " + sel_inf.id + ": without any deploy. Exiting.")
sel_inf.add_cont_msg("Infrastructure without any deploy. Exiting.")
if sel_inf.configured is None:
sel_inf.configured = False
return []
except Exception as ex:
sel_inf.configured = False
Expand Down Expand Up @@ -570,6 +572,8 @@ def AddResource(inf_id, radl_data, auth, context=True):
if not deploy_group:
InfrastructureManager.logger.warning("Inf ID: %s: No VMs to deploy!" % sel_inf.id)
sel_inf.add_cont_msg("No VMs to deploy. Exiting.")
if sel_inf.configured is None:
sel_inf.configured = False
return []

cloud_id = deploys_group_cloud[id(deploy_group)]
Expand Down Expand Up @@ -901,14 +905,15 @@ def GetInfrastructureState(inf_id, auth):

sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth)

vm_list = sel_inf.get_vm_list()
vm_states = {}
for vm in sel_inf.get_vm_list():
for vm in vm_list:
# First try to update the status of the VM
vm.update_status(auth)
vm_states[str(vm.im_id)] = vm.state

state = None
for vm in sel_inf.get_vm_list():
for vm in vm_list:
# First try to update the status of the VM
if vm.state == VirtualMachine.FAILED:
state = VirtualMachine.FAILED
Expand Down Expand Up @@ -937,6 +942,9 @@ def GetInfrastructureState(inf_id, auth):
if state is None:
if sel_inf.configured is False:
state = VirtualMachine.FAILED
elif not vm_list and sel_inf.configured is None:
# if there are no vms we probably are in the vm creation process
state = VirtualMachine.PENDING
else:
state = VirtualMachine.UNKNOWN

Expand Down
15 changes: 8 additions & 7 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,24 +505,25 @@ def update_status(self, auth, force=False):
updated = False
# To avoid to refresh the information too quickly
if force or now - self.last_update > Config.VM_INFO_UPDATE_FREQUENCY:
success = False
try:
(success, new_vm) = self.getCloudConnector().updateVMInfo(self, auth)
if success:
state = new_vm.state
updated = True
self.last_update = now
elif self.creating:
self.log_info("VM is in creation process, set pending state")
state = VirtualMachine.PENDING
else:
self.log_error("Error updating VM status: %s" % new_vm)
except:
except Exception:
self.log_exception("Error updating VM status.")
updated = False

if not success and self.creating:
self.log_info("VM is in creation process, set pending state")
state = VirtualMachine.PENDING

# If we have problems to update the VM info too much time, set to
# unknown
if now - self.last_update > Config.VM_INFO_UPDATE_ERROR_GRACE_PERIOD:
# unknown unless we are still creating the VM
if now - self.last_update > Config.VM_INFO_UPDATE_ERROR_GRACE_PERIOD and not self.creating:
new_state = VirtualMachine.UNKNOWN
self.log_warn("Grace period to update VM info passed. Set state to 'unknown'")
else:
Expand Down

0 comments on commit 35d047b

Please sign in to comment.