Revision cb7b1c23

b/snf-cyclades-app/synnefo/db/models.py
712 712
        # assigned to more than one NICs
713 713
        unique_together = ("network", "ipv4")
714 714

  
715
    def delete(self):
716
        """Custom method for deleting NetworkInterfaces.
717

  
718
        In case the NIC is of 'FLOATING' type, this method clears the 'machine'
719
        flag of the FloatingIP object, before deleting the NIC.
720

  
721
        """
722
        if self.ip_type == "FLOATING":
723
            FloatingIP.objects.filter(machine=self.machine_id,
724
                                      network=self.network_id,
725
                                      ipv4=self.ipv4).update(machine=None)
726
        super(NetworkInterface, self).delete()
727

  
715 728

  
716 729
class FloatingIP(models.Model):
717 730
    userid = models.CharField("UUID of the owner", max_length=128,
b/snf-cyclades-app/synnefo/logic/backend.py
37 37
from synnefo.db.models import (Backend, VirtualMachine, Network,
38 38
                               BackendNetwork, BACKEND_STATUSES,
39 39
                               pooled_rapi_client, VirtualMachineDiagnostic,
40
                               Flavor)
40
                               Flavor, FloatingIP)
41 41
from synnefo.logic import utils
42 42
from synnefo import quotas
43 43
from synnefo.api.util import release_resource
......
325 325
    """Release the IPv4 address of a NIC.
326 326

  
327 327
    Check if an instance's NIC has an IPv4 address and release it if it is not
328
    a Floating IP.
328
    a Floating IP. If it is as Floating IP, then disassociate the FloatingIP
329
    from the machine.
329 330

  
330 331
    """
331 332

  
332
    if nic.ipv4 and not nic.ip_type == "FLOATING":
333
        nic.network.release_address(nic.ipv4)
333
    if nic.ipv4:
334
        if nic.ip_type == "FLOATING":
335
            FloatingIP.objects.filter(machine=nic.machine_id,
336
                                      network=nic.network_id,
337
                                      ipv4=nic.ipv4).update(machine=None)
338
        else:
339
            nic.network.release_address(nic.ipv4)
334 340

  
335 341

  
336 342
@transaction.commit_on_success

Also available in: Unified diff