Commit 1981fc01 by Őry Máté

one: fix host deletion problems

parent 35b6c89e
...@@ -365,8 +365,7 @@ class Instance(models.Model): ...@@ -365,8 +365,7 @@ class Instance(models.Model):
if not self.one_id: if not self.one_id:
return return
proc = subprocess.Popen(["/opt/occi.sh", proc = subprocess.Popen(["/opt/occi.sh", "compute", "show",
"compute", "show",
"%d"%self.one_id], stdout=subprocess.PIPE) "%d"%self.one_id], stdout=subprocess.PIPE)
(out, err) = proc.communicate() (out, err) = proc.communicate()
x = None x = None
...@@ -379,6 +378,8 @@ class Instance(models.Model): ...@@ -379,6 +378,8 @@ class Instance(models.Model):
except: except:
self.state = 'UNKNOWN' self.state = 'UNKNOWN'
self.save() self.save()
if self.template.state == 'SAVING':
self.check_if_is_save_as_done()
return x return x
""" """
...@@ -471,7 +472,13 @@ class Instance(models.Model): ...@@ -471,7 +472,13 @@ class Instance(models.Model):
host.ipv4 = inst.ip host.ipv4 = inst.ip
host.pub_ipv4 = Vlan.objects.get(name=template.network.name).snat_ip host.pub_ipv4 = Vlan.objects.get(name=template.network.name).snat_ip
host.ipv6 = "auto" host.ipv6 = "auto"
host.save() try:
host.save()
except:
for i in Host.objects.filter(ipv4=host.ipv4).all():
logger.warning('Delete orphan fw host (%s) of %s.' % (i, inst))
i.delete()
host.save()
host.enable_net() host.enable_net()
host.add_port("tcp", inst.get_port(), {"rdp": 3389, "nx": 22, "ssh": 22}[inst.template.access_type]) host.add_port("tcp", inst.get_port(), {"rdp": 3389, "nx": 22, "ssh": 22}[inst.template.access_type])
inst.firewall_host=host inst.firewall_host=host
...@@ -486,8 +493,14 @@ class Instance(models.Model): ...@@ -486,8 +493,14 @@ class Instance(models.Model):
proc = subprocess.Popen(["/opt/occi.sh", "compute", proc = subprocess.Popen(["/opt/occi.sh", "compute",
"delete", "%d"%self.one_id], stdout=subprocess.PIPE) "delete", "%d"%self.one_id], stdout=subprocess.PIPE)
(out, err) = proc.communicate() (out, err) = proc.communicate()
self.firewall_host_delete()
def firewall_host_delete(self):
if self.firewall_host: if self.firewall_host:
self.firewall_host.delete() h = self.firewall_host
self.firewall_host = None
self.save()
h.delete()
reload_firewall_lock() reload_firewall_lock()
def _update_vm(self, template): def _update_vm(self, template):
...@@ -535,7 +548,6 @@ class Instance(models.Model): ...@@ -535,7 +548,6 @@ class Instance(models.Model):
t.state = 'SAVING' t.state = 'SAVING'
t.save() t.save()
def check_if_is_save_as_done(self): def check_if_is_save_as_done(self):
self.update_state()
if self.state != 'DONE': if self.state != 'DONE':
return False return False
Disk.update() Disk.update()
...@@ -546,7 +558,7 @@ class Instance(models.Model): ...@@ -546,7 +558,7 @@ class Instance(models.Model):
self.template.disk_id = disks[0].id self.template.disk_id = disks[0].id
self.template.state = 'READY' self.template.state = 'READY'
self.template.save() self.template.save()
self.firewall_host.delete() self.firewall_host_delete()
return True return True
...@@ -558,7 +570,7 @@ def delete_instance(sender, instance, using, **kwargs): ...@@ -558,7 +570,7 @@ def delete_instance(sender, instance, using, **kwargs):
if instance.state != "DONE": if instance.state != "DONE":
instance.one_delete() instance.one_delete()
try: try:
instance.firewall_host.delete() instance.firewall_host_delete()
except: except:
pass pass
post_delete.connect(delete_instance, sender=Instance, dispatch_uid="delete_instance") post_delete.connect(delete_instance, sender=Instance, dispatch_uid="delete_instance")
......
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