Commit 3619582b by Dudás Ádám

vm: only destroy node dependent entities when node is available

parent 6487ae94
...@@ -437,7 +437,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -437,7 +437,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
"""Get the remote worker queue name of this instance with the specified """Get the remote worker queue name of this instance with the specified
queue ID. queue ID.
""" """
return self.node.get_remote_queue_name(queue_id) return self.node.get_remote_queue_name(queue_id) if self.node else None
def renew(self, which='both'): def renew(self, which='both'):
"""Renew virtual machine instance leases. """Renew virtual machine instance leases.
...@@ -535,19 +535,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -535,19 +535,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
asynchronously. asynchronously.
:type task_uuid: str :type task_uuid: str
""" """
if self.destroyed:
return # already destroyed, nothing to do here
with instance_activity(code_suffix='destroy', instance=self, with instance_activity(code_suffix='destroy', instance=self,
task_uuid=task_uuid, user=user) as act: task_uuid=task_uuid, user=user) as act:
# Destroy networks if self.node:
with act.sub_activity('destroying_net'): # Destroy networks
for net in self.interface_set.all(): with act.sub_activity('destroying_net'):
net.destroy() for net in self.interface_set.all():
net.destroy()
# Destroy virtual machine
with act.sub_activity('destroying_vm'): # Destroy virtual machine
queue_name = self.get_remote_queue_name('vm') with act.sub_activity('destroying_vm'):
vm_tasks.destroy.apply_async(args=[self.vm_name], queue_name = self.get_remote_queue_name('vm')
queue=queue_name).get() vm_tasks.destroy.apply_async(args=[self.vm_name],
queue=queue_name).get()
# Destroy disks # Destroy disks
with act.sub_activity('destroying_disks'): with act.sub_activity('destroying_disks'):
......
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