Revision 7aea0198 lib/network.py
b/lib/network.py | ||
---|---|---|
30 | 30 |
from ganeti import errors |
31 | 31 |
from ganeti import utils |
32 | 32 |
from ganeti import constants |
33 |
import logging |
|
33 | 34 |
|
34 | 35 |
|
35 | 36 |
def _ComputeIpv4NumHosts(network_size): |
... | ... | |
80 | 81 |
(address, network), |
81 | 82 |
errors.ECODE_INVAL) |
82 | 83 |
|
84 |
def Contains(self, address): |
|
85 |
pass |
|
86 |
|
|
87 |
def IsReserved(self, address): |
|
88 |
pass |
|
89 |
|
|
90 |
def Reserve(self, address, external): |
|
91 |
pass |
|
92 |
|
|
93 |
def Release(self, address, external): |
|
94 |
pass |
|
95 |
|
|
96 |
def GenerateFree(self): |
|
97 |
pass |
|
98 |
|
|
99 |
def GetStats(self): |
|
100 |
pass |
|
101 |
|
|
83 | 102 |
|
84 | 103 |
class GenericNetwork(object): |
85 | 104 |
""" Base class for networks. |
... | ... | |
145 | 164 |
return False |
146 | 165 |
|
147 | 166 |
def IsReserved(self, address): |
167 |
logging.info("Check if %s is reserved in network %s", |
|
168 |
address, self.nobj.name) |
|
148 | 169 |
return False |
149 | 170 |
|
150 | 171 |
def Reserve(self, address, external): |
... | ... | |
278 | 299 |
|
279 | 300 |
""" |
280 | 301 |
if self.IsReserved(address): |
281 |
raise errors.AddressPoolError("%s is already reserved" % address)
|
|
302 |
raise errors.NetworkError("%s is already reserved" % address)
|
|
282 | 303 |
self._Mark(address, external=external) |
283 | 304 |
|
284 | 305 |
def Release(self, address, external=False): |
... | ... | |
291 | 312 |
"""Returns the first available address. |
292 | 313 |
|
293 | 314 |
""" |
294 |
if self.IsFull():
|
|
295 |
raise errors.AddressPoolError("%s is full" % self.network)
|
|
315 |
if self._all_reservations.all():
|
|
316 |
raise errors.NetworkError("%s is full" % self.network)
|
|
296 | 317 |
|
297 |
idx = self.all_reservations.index(False) |
|
318 |
idx = self._all_reservations.index(False)
|
|
298 | 319 |
address = str(self.network[idx]) |
299 | 320 |
self.Reserve(address) |
300 | 321 |
return address |
... | ... | |
302 | 323 |
def GenerateFree(self): |
303 | 324 |
"""Returns the first free address of the network. |
304 | 325 |
|
305 |
@raise errors.AddressPoolError: Pool is full
|
|
326 |
@raise errors.NetworkError: Pool is full
|
|
306 | 327 |
|
307 | 328 |
""" |
308 | 329 |
idx = self._all_reservations.search(self.FREE, 1) |
Also available in: Unified diff