Revision ff863a80 snf-cyclades-app/synnefo/logic/backend.py
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
37 | 37 |
from synnefo.db.models import (Backend, VirtualMachine, Network, |
38 | 38 |
BackendNetwork, BACKEND_STATUSES, |
39 | 39 |
pooled_rapi_client, VirtualMachineDiagnostic, |
40 |
Flavor) |
|
40 |
Flavor, IPAddressLog)
|
|
41 | 41 |
from synnefo.logic import utils |
42 | 42 |
from synnefo import quotas |
43 | 43 |
from synnefo.api.util import release_resource, allocate_ip |
... | ... | |
338 | 338 |
""" |
339 | 339 |
|
340 | 340 |
for ip in nic.ips.all(): |
341 |
# Update the DB table holding the logging of all IP addresses |
|
342 |
update_ip_address_log(nic, ip) |
|
343 |
|
|
341 | 344 |
if ip.ipversion == 4: |
342 | 345 |
if ip.floating_ip: |
343 | 346 |
ip.nic = None |
... | ... | |
348 | 351 |
ip.delete() |
349 | 352 |
|
350 | 353 |
|
354 |
def update_ip_address_log(nic, ip): |
|
355 |
"""Update DB logging entry for this IP address.""" |
|
356 |
if not ip.network.public: |
|
357 |
return |
|
358 |
try: |
|
359 |
ip_log, created = \ |
|
360 |
IPAddressLog.objects.get_or_create(server_id=nic.machine_id, |
|
361 |
network_id=ip.network_id, |
|
362 |
address=ip.address, |
|
363 |
active=True) |
|
364 |
except IPAddressLog.MultipleObjectsReturned: |
|
365 |
logmsg = ("Multiple active log entries for IP %s, Network %s," |
|
366 |
"Server %s. Can not proceed!" |
|
367 |
% (ip.address, ip.network, nic.machine)) |
|
368 |
log.error(logmsg) |
|
369 |
raise |
|
370 |
|
|
371 |
if created: |
|
372 |
logmsg = ("No log entry for IP %s, Network %s, Server %s. Created new" |
|
373 |
" but with wrong creation timestamp." |
|
374 |
% (ip.address, ip.network, nic.machine)) |
|
375 |
log.error(logmsg) |
|
376 |
ip_log.released_at = datetime.now() |
|
377 |
ip_log.active = False |
|
378 |
ip_log.save() |
|
379 |
|
|
380 |
|
|
351 | 381 |
@transaction.commit_on_success |
352 | 382 |
def process_network_status(back_network, etime, jobid, opcode, status, logmsg): |
353 | 383 |
if status not in [x[0] for x in BACKEND_STATUSES]: |
Also available in: Unified diff