Revision 0e0a6ef9 snf-cyclades-app/synnefo/logic/reconciliation.py

b/snf-cyclades-app/synnefo/logic/reconciliation.py
508 508
        corresponding Ganeti networks in all Ganeti backends.
509 509

  
510 510
        """
511
        network_ip_pool = network.get_pool()  # X-Lock on IP Pool
511
        ip_pools = network.get_ip_pools()  # X-Lock on IP pools
512 512
        for bend in self.backends:
513 513
            bnet = get_backend_network(network, bend)
514 514
            gnet = self.ganeti_networks[bend].get(network.id)
......
563 563
            if externally_reserved:
564 564
                for ip in externally_reserved.split(","):
565 565
                    ip = ip.strip()
566
                    if not network_ip_pool.is_reserved(ip):
567
                        msg = ("D: IP '%s' is reserved for network '%s' in"
568
                               " backend '%s' but not in DB.")
569
                        self.log.info(msg, ip, network, bend)
570
                        if self.fix:
571
                            network_ip_pool.reserve(ip, external=True)
572
                            network_ip_pool.save()
573
                            self.log.info("F: Reserved IP '%s'", ip)
566
                    for ip_pool in ip_pools:
567
                        if ip_pool.contains(ip):
568
                            if not ip_pool.is_reserved(ip):
569
                                msg = ("D: IP '%s' is reserved for network"
570
                                       " '%s' in backend '%s' but not in DB.")
571
                                self.log.info(msg, ip, network, bend)
572
                                if self.fix:
573
                                    ip_pool.reserve(ip, external=True)
574
                                    ip_pool.save()
575
                                    self.log.info("F: Reserved IP '%s'", ip)
574 576

  
575 577
    def reconcile_parted_network(self, network, backend):
576 578
        self.log.info("D: Missing DB entry for network %s in backend %s",
......
699 701
    @transaction.commit_on_success
700 702
    def reconcile_ip_pool(self, network):
701 703
        # Check that all NICs have unique IPv4 address
702
        nics = network.nics.filter(ipv4__isnull=False)
703
        check_unique_values(objects=nics, field='ipv4', logger=self.log)
704

  
705
        # Check that all Floating IPs have unique IPv4 address
706
        floating_ips = network.floating_ips.filter(deleted=False)
707
        check_unique_values(objects=floating_ips, field='ipv4',
708
                            logger=self.log)
709

  
710
        # First get(lock) the IP pool of the network to prevent new NICs
711
        # from being created.
712
        network_ip_pool = network.get_pool()
713
        used_ips = set(list(nics.values_list("ipv4", flat=True)) +
714
                       list(floating_ips.values_list("ipv4", flat=True)))
715

  
716
        check_pool_consistent(pool=network_ip_pool,
717
                              pool_class=pools.IPPool,
718
                              used_values=used_ips,
719
                              fix=self.fix, logger=self.log)
704
        nics = network.ips.all()
705
        check_unique_values(objects=nics, field="address", logger=self.log)
706

  
707
        for ip_pool in network.get_ip_pools():
708
            used_ips = ip_pool.pool_table.subnet.ips.values_list("address",
709
                                                                 flat=True)
710
            used_ips = filter(lambda x: ip_pool.contains(x), used_ips)
711
            check_pool_consistent(pool=ip_pool,
712
                                  pool_class=pools.IPPool,
713
                                  used_values=used_ips,
714
                                  fix=self.fix, logger=self.log)
720 715

  
721 716

  
722 717
def check_unique_values(objects, field, logger):

Also available in: Unified diff