Revision f96f60fd snf-cyclades-app/synnefo/logic/backend_allocator.py

b/snf-cyclades-app/synnefo/logic/backend_allocator.py
34 34
from synnefo import settings
35 35
from synnefo.db.models import Backend
36 36
from synnefo.logic.backend import update_resources
37
from synnefo.api.util import backend_public_networks
37 38

  
38 39
log = logging.getLogger(__name__)
39 40

  
......
88 89
    """Get available backends from db.
89 90

  
90 91
    """
91
    return list(Backend.objects.select_for_update().filter(drained=False,
92
                                                           offline=False))
92
    backends = list(Backend.objects.select_for_update().filter(drained=False,
93
                                                               offline=False))
94
    return filter(lambda x: has_free_ip(x), backends)
95

  
96

  
97
def has_free_ip(backend):
98
    """Find if Backend has any free public IP."""
99
    for network in backend_public_networks(backend):
100
        if not network.get_pool().empty():
101
            return True
102
    return False
93 103

  
94 104

  
95 105
def flavor_disk(flavor):

Also available in: Unified diff