Revision ae994d2e
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
304 | 304 |
% network.id) |
305 | 305 |
except pools.ValueNotAvailable: |
306 | 306 |
raise faults.Conflict("IP address %s is already used." % address) |
307 |
except pools.InvalidValue: |
|
308 |
raise faults.BadRequest("Address %s does not belong to network %s" % |
|
309 |
(address, network.id)) |
|
307 | 310 |
|
308 | 311 |
|
309 | 312 |
def allocate_public_ip(userid, floating_ip=False, backend=None): |
b/snf-cyclades-app/synnefo/db/pools/__init__.py | ||
---|---|---|
66 | 66 |
self._reserve(index) |
67 | 67 |
return self.index_to_value(index) |
68 | 68 |
else: |
69 |
if not self.contains(value): |
|
70 |
raise InvalidValue("Value %s does not belong to pool." % value) |
|
69 | 71 |
if self.is_available(value): |
70 | 72 |
self.reserve(value) |
71 | 73 |
return value |
... | ... | |
112 | 114 |
else: |
113 | 115 |
self.available[index] = AVAILABLE |
114 | 116 |
|
117 |
def contains(self, value): |
|
118 |
index = self.value_to_index(value) |
|
119 |
return index >= 0 and index < self.pool_size |
|
120 |
|
|
115 | 121 |
def count_available(self): |
116 | 122 |
return self.pool.count(AVAILABLE) |
117 | 123 |
|
... | ... | |
191 | 197 |
pass |
192 | 198 |
|
193 | 199 |
|
200 |
class InvalidValue(Exception): |
|
201 |
pass |
|
202 |
|
|
203 |
|
|
194 | 204 |
def find_padding(size): |
195 | 205 |
extra = size % 8 |
196 | 206 |
return extra and (8 - extra) or 0 |
b/snf-cyclades-app/synnefo/db/pools/tests.py | ||
---|---|---|
35 | 35 |
from django.test import TestCase |
36 | 36 |
from synnefo.db.pools import (PoolManager, EmptyPool, BridgePool, |
37 | 37 |
MacPrefixPool, IPPool, find_padding, |
38 |
bitarray_to_map, ValueNotAvailable) |
|
38 |
bitarray_to_map, ValueNotAvailable, |
|
39 |
InvalidValue) |
|
39 | 40 |
from bitarray import bitarray |
40 | 41 |
|
41 | 42 |
|
... | ... | |
248 | 249 |
# Test if externally reserved |
249 | 250 |
pool.reserve("192.168.2.3", external=True) |
250 | 251 |
self.assertRaises(ValueNotAvailable, pool.get, "192.168.2.3") |
252 |
self.assertRaises(ValueNotAvailable, pool.get, "192.168.2.15") |
|
253 |
self.assertRaises(InvalidValue, pool.get, "192.168.2.16") |
Also available in: Unified diff