Revision 30418cbe snf-cyclades-app/synnefo/logic/ippool.py

b/snf-cyclades-app/synnefo/logic/ippool.py
5 5

  
6 6

  
7 7
class IPPool(object):
8
    """IP pool class, based on a models.Network object
9

  
10
    Implementation of an IP address pool based on a models.Network
11
    object.
12

  
13
    """
8 14
    def __init__(self, network):
9 15
        self.net = network
10 16
        self.network = ipaddr.IPNetwork(self.net.subnet)
......
21 27
            self.reservations.setall(False)
22 28
            self.reservations[0] = True
23 29
            self.reservations[numhosts - 1] = True
24
            # if self.net.type == 'PUBLIC_ROUTED':
25
            #     self.reservations[numhosts - 2] = True
30
            if self.gateway:
31
                self.reserve(self.gateway)
26 32

  
27 33
    def _contains(self, address):
28 34
        if address is None:
......
36 42

  
37 43
        """
38 44
        if not self._contains(address):
39
            raise Exception("%s does not contain %s" % (str(self.network), address))
45
            raise Exception("%s does not contain %s" %
46
                            (str(self.network), address))
40 47
        addr = ipaddr.IPAddress(address)
41 48

  
42 49
        return int(addr) - int(self.network.network)
......
56 63
        return self.reservations[index]
57 64

  
58 65
    def is_full(self):
59
        return self.reservations.all()
66
            return self.reservations.all()
60 67

  
61 68
    def count_reserved(self):
62 69
        return self.reservations.count(True)
......
68 75
        return self.reservations.to01().replace("1", "X").replace("0", ".")
69 76

  
70 77
    def get_free_address(self):
78
        """Get the first available address."""
71 79
        if self.is_full():
72 80
            raise IPPool.IPPoolExhausted("%s if full" % str(self.network))
73 81

  
......
77 85
        return address
78 86

  
79 87
    def save(self):
88
        """Update the Network model and save it to DB."""
80 89
        self._update_network()
81 90
        self.net.save()
82 91

  

Also available in: Unified diff