Revision 1f1d3bf2
b/lib/config.py | ||
---|---|---|
376 | 376 |
net_uuid = self._UnlockedLookupNetwork(net) |
377 | 377 |
nobj = self._UnlockedGetNetwork(net_uuid) |
378 | 378 |
pool = network.AddressPool(nobj) |
379 |
gen_free = pool.GenerateFree() |
|
380 | 379 |
|
381 | 380 |
def gen_one(): |
382 | 381 |
try: |
383 |
ip = gen_free()
|
|
384 |
except StopIteration:
|
|
382 |
ip = pool.GenerateFree()
|
|
383 |
except errors.AddressPoolError:
|
|
385 | 384 |
raise errors.ReservationError("Cannot generate IP. Network is full") |
386 | 385 |
return (constants.RESERVE_ACTION, ip, net_uuid) |
387 | 386 |
|
b/lib/network.py | ||
---|---|---|
173 | 173 |
return address |
174 | 174 |
|
175 | 175 |
def GenerateFree(self): |
176 |
"""A generator for free addresses.""" |
|
177 |
def _iter_free(): |
|
178 |
for idx in self.all_reservations.search("0", 64): |
|
179 |
yield str(self.network[idx]) |
|
180 |
# pylint: disable=E1101 |
|
181 |
return _iter_free().next |
|
176 |
"""Returns the first free address of the network if any or |
|
177 |
raises an error if it is full. |
|
178 |
|
|
179 |
""" |
|
180 |
if self.IsFull(): |
|
181 |
raise errors.AddressPoolError("%s is full" % self.network) |
|
182 |
idx = self.all_reservations.search("0", 1) |
|
183 |
return str(self.network[idx]) |
|
182 | 184 |
|
183 | 185 |
def GetExternalReservations(self): |
184 | 186 |
"""Returns a list of all externally reserved addresses""" |
Also available in: Unified diff