Commit 6a54d7e1 by Dudás Ádám

vm: refactor vm_state_changed

parent a6bd2dd0
...@@ -287,14 +287,10 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -287,14 +287,10 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
act.save() act.save()
def vm_state_changed(self, new_state): def vm_state_changed(self, new_state):
# log state change
try: try:
act = InstanceActivity.create( act = InstanceActivity.create(code_suffix='vm_state_changed',
code_suffix='monitor_event_%s' % new_state,
instance=self) instance=self)
if new_state == "STOPPED":
self.vnc_port = None
self.node = None
self.save()
except ActivityInProgressError: except ActivityInProgressError:
pass # discard state change if another activity is in progress. pass # discard state change if another activity is in progress.
else: else:
...@@ -303,6 +299,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -303,6 +299,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
act.succeeded = True act.succeeded = True
act.save() act.save()
if new_state == 'STOPPED':
self.vnc_port = None
self.node = None
self.save()
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
if self.time_of_delete is None: if self.time_of_delete is None:
self._do_renew(which='delete') self._do_renew(which='delete')
......
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