Revision f96f60fd snf-cyclades-app/synnefo/logic/allocators/default_allocator.py

b/snf-cyclades-app/synnefo/logic/allocators/default_allocator.py
33 33

  
34 34
from __future__ import division
35 35
import logging
36
from synnefo.api.util import backend_public_networks
36

  
37 37

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

  
......
68 68

  
69 69

  
70 70
def vm_fits_in_backend(backend, vm):
71
    return backend.dfree > vm['disk'] and backend.mfree > vm['ram'] and\
72
           has_free_ip(backend)
71
    return backend.dfree > vm['disk'] and backend.mfree > vm['ram']
73 72

  
74 73

  
75 74
def backend_score(backend, flavor):
......
77 76
    dratio = 1 - (backend.dfree / backend.dtotal)
78 77
    cratio = (backend.pinst_cnt + 1) / (backend.ctotal * 4)
79 78
    return 0.7 * (mratio + dratio) * 0.3 * cratio
80

  
81

  
82
def has_free_ip(backend):
83
    """Find if Backend has any free public IP."""
84
    for network in backend_public_networks(backend):
85
        if not network.get_pool().empty():
86
            return True
87
    return False

Also available in: Unified diff