Revision 4cbd934b 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
        ip_pools = network.get_ip_pools()  # X-Lock on IP pools
511
        if network.subnets.filter(ipversion=4, dhcp=True).exists():
512
            ip_pools = network.get_ip_pools()  # X-Lock on IP pools
513
        else:
514
            ip_pools = None
512 515
        for bend in self.backends:
513 516
            bnet = get_backend_network(network, bend)
514 517
            gnet = self.ganeti_networks[bend].get(network.id)
......
560 563
            # Check that externally reserved IPs of the network in Ganeti are
561 564
            # also externally reserved to the IP pool
562 565
            externally_reserved = gnet['external_reservations']
563
            if externally_reserved:
566
            if externally_reserved and ip_pools is not None:
564 567
                for ip in externally_reserved.split(","):
565 568
                    ip = ip.strip()
566 569
                    for ip_pool in ip_pools:
......
663 666
    def reconcile(self):
664 667
        self.reconcile_bridges()
665 668
        self.reconcile_mac_prefixes()
666
        for network in Network.objects.filter(deleted=False):
667
            self.reconcile_ip_pool(network)
669

  
670
        networks = Network.objects.prefetch_related("subnets")\
671
                                  .filter(deleted=False)
672
        for network in networks:
673
            for subnet in network.subnets.all():
674
                if subnet.ipversion == 4 and subnet.dhcp:
675
                    self.reconcile_ip_pool(network)
668 676

  
669 677
    @transaction.commit_on_success
670 678
    def reconcile_bridges(self):
......
701 709
    @transaction.commit_on_success
702 710
    def reconcile_ip_pool(self, network):
703 711
        # Check that all NICs have unique IPv4 address
704
        nics = network.ips.all()
712
        nics = network.ips.exclude(address__isnull=True).all()
705 713
        check_unique_values(objects=nics, field="address", logger=self.log)
706 714

  
707 715
        for ip_pool in network.get_ip_pools():
708
            used_ips = ip_pool.pool_table.subnet.ips.values_list("address",
709
                                                                 flat=True)
716
            used_ips = ip_pool.pool_table.subnet\
717
                              .ips.exclude(address__isnull=True)\
718
                              .values_list("address", flat=True)
710 719
            used_ips = filter(lambda x: ip_pool.contains(x), used_ips)
711 720
            check_pool_consistent(pool=ip_pool,
712 721
                                  pool_class=pools.IPPool,

Also available in: Unified diff