Revision 8a67cddc logic/management/commands/reconcile.py
b/logic/management/commands/reconcile.py | ||
---|---|---|
28 | 28 |
# policies, either expressed or implied, of GRNET S.A. |
29 | 29 |
# |
30 | 30 |
# Reconcile VM state - Management Script |
31 |
|
|
32 | 31 |
from synnefo.db.models import VirtualMachine |
32 |
from django.db.models import Q |
|
33 | 33 |
from django.conf import settings |
34 | 34 |
from datetime import datetime, timedelta |
35 | 35 |
from optparse import make_option |
... | ... | |
52 | 52 |
) |
53 | 53 |
|
54 | 54 |
def handle(self, all_vms = False, interval = 1, **options): |
55 |
all = VirtualMachine.objects.all().filter(deleted = False) \
|
|
56 |
.filter(suspended = False)
|
|
55 |
all = VirtualMachine.objects.filter(Q(deleted = False) &
|
|
56 |
Q(suspended = False))
|
|
57 | 57 |
|
58 | 58 |
if not all_vms: |
59 | 59 |
now = datetime.now() |
60 | 60 |
last_update = timedelta(minutes = settings.RECONCILIATION_MIN) |
61 |
not_updated = VirtualMachine.objects \ |
|
62 |
.filter(updated__lte = (now - last_update)) |
|
61 |
not_updated = VirtualMachine.objects.filter(Q(deleted = False) & |
|
62 |
Q(suspended = False) & |
|
63 |
Q(updated__lte = (now - last_update))) |
|
63 | 64 |
|
64 | 65 |
to_update = ((all.count() / settings.RECONCILIATION_MIN) * interval) |
65 | 66 |
else: |
Also available in: Unified diff