Commit 5c42499f by Őry Máté

vm: discover machines on wrong nodes

parent 64e19ee1
......@@ -447,18 +447,23 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
super(Instance, self).clean(*args, **kwargs)
def vm_state_changed(self, new_state):
def vm_state_changed(self, new_state, new_node=False):
if new_node is False: # None would be a valid value
new_node = self.node
# log state change
try:
act = InstanceActivity.create(
code_suffix='vm_state_changed',
readable_name=create_readable(
ugettext_noop("vm state changed to %(state)s"),
state=new_state),
ugettext_noop("vm state changed to %(state)s on %(node)s"),
state=new_state, node=new_node),
instance=self)
except ActivityInProgressError:
pass # discard state change if another activity is in progress.
else:
if self.node != new_node:
self.node = new_node
self.save()
act.finished = act.started
act.resultant_state = new_state
act.succeeded = True
......
......@@ -354,7 +354,8 @@ class Node(OperatedMixin, TimeStampedModel):
logger.info('Node %s update: instance %s missing from '
'libvirt', self, i['id'])
# Set state to STOPPED when instance is missing
self.instance_set.get(id=i['id']).vm_state_changed('STOPPED')
self.instance_set.get(id=i['id']).vm_state_changed(
'STOPPED', None)
else:
if d != i['state']:
logger.info('Node %s update: instance %s state changed '
......@@ -363,9 +364,11 @@ class Node(OperatedMixin, TimeStampedModel):
self.instance_set.get(id=i['id']).vm_state_changed(d)
del domains[i['id']]
for i in domains.keys():
for i in domains.values():
from .instance import Instance
logger.info('Node %s update: domain %s in libvirt but not in db.',
self, i)
self, i['id'])
Instance.objects.get(id=i['id']).vm_state_changed(i['state'], self)
@classmethod
def get_state_count(cls, online, enabled):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment