Revision fd22fc77 snf-cyclades-app/synnefo/logic/management/commands/reconcile-networks.py
b/snf-cyclades-app/synnefo/logic/management/commands/reconcile-networks.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
from synnefo.settings import PUBLIC_USE_POOL |
44 | 44 |
from django.core.management.base import BaseCommand |
45 |
from django.db import transaction |
|
45 | 46 |
|
46 | 47 |
from synnefo.db.models import Backend, Network, BackendNetwork |
47 | 48 |
from synnefo.db.pools import IPPool |
... | ... | |
221 | 222 |
"Reconciliation simulated eventd") |
222 | 223 |
|
223 | 224 |
|
225 |
@transaction.commit_on_success |
|
224 | 226 |
def reconcile_ip_pools(network, available_maps, reserved_maps): |
225 | 227 |
available_map = reduce(lambda x, y: x & y, available_maps) |
226 | 228 |
reserved_map = reduce(lambda x, y: x & y, reserved_maps) |
227 | 229 |
|
228 | 230 |
pool = network.get_pool() |
229 |
if pool.available != available_map: |
|
231 |
# Temporary release unused floating IPs |
|
232 |
temp_pool = network.get_pool() |
|
233 |
used_ips = network.nics.values_list("ipv4", flat=True) |
|
234 |
unused_static_ips = network.floating_ips.exclude(ipv4__in=used_ips) |
|
235 |
map(lambda ip: temp_pool.put(ip.ipv4), unused_static_ips) |
|
236 |
if temp_pool.available != available_map: |
|
230 | 237 |
write("D: Unsynced available map of network %s:\n" |
231 | 238 |
"\tDB: %r\n\tGB: %r\n" % |
232 |
(network, pool.available.to01(), available_map.to01())) |
|
239 |
(network, temp_pool.available.to01(), available_map.to01()))
|
|
233 | 240 |
if fix: |
234 | 241 |
pool.available = available_map |
242 |
# Release unsued floating IPs, as they are not included in the |
|
243 |
# available map |
|
244 |
map(lambda ip: pool.reserve(ip.ipv4), unused_static_ips) |
|
245 |
pool.save() |
|
235 | 246 |
if pool.reserved != reserved_map: |
236 | 247 |
write("D: Unsynced reserved map of network %s:\n" |
237 | 248 |
"\tDB: %r\n\tGB: %r\n" % |
238 | 249 |
(network, pool.reserved.to01(), reserved_map.to01())) |
239 | 250 |
if fix: |
240 | 251 |
pool.reserved = reserved_map |
241 |
pool.save() |
|
252 |
pool.save()
|
|
242 | 253 |
|
243 | 254 |
|
244 | 255 |
def detect_conflicting_ips(network): |
Also available in: Unified diff