Revision cb409cfd
b/logic/dispatcher_callbacks.py | ||
---|---|---|
1 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
1 | 2 |
# |
2 |
# Callback functions used by the dispatcher |
|
3 |
# to process incoming notifications from AMQP queues. |
|
3 |
# Redistribution and use in source and binary forms, with or without |
|
4 |
# modification, are permitted provided that the following conditions |
|
5 |
# are met: |
|
4 | 6 |
# |
5 |
# Copyright 2010 Greek Research and Technology Network |
|
7 |
# 1. Redistributions of source code must retain the above copyright |
|
8 |
# notice, this list of conditions and the following disclaimer. |
|
6 | 9 |
# |
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
11 |
# notice, this list of conditions and the following disclaimer in the |
|
12 |
# documentation and/or other materials provided with the distribution. |
|
13 |
# |
|
14 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
15 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
16 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
17 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
18 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
19 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
20 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
21 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
22 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
23 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
24 |
# SUCH DAMAGE. |
|
25 |
# |
|
26 |
# The views and conclusions contained in the software and documentation are |
|
27 |
# those of the authors and should not be interpreted as representing official |
|
28 |
# policies, either expressed or implied, of GRNET S.A. |
|
29 |
|
|
30 |
# Callback functions used by the dispatcher to process incoming notifications |
|
31 |
# from AMQP queues. |
|
32 |
|
|
7 | 33 |
import traceback |
8 | 34 |
import json |
9 | 35 |
import logging |
b/logic/management/commands/reconcile.py | ||
---|---|---|
1 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or without |
|
4 |
# modification, are permitted provided that the following conditions |
|
5 |
# are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above copyright |
|
8 |
# notice, this list of conditions and the following disclaimer. |
|
9 |
# |
|
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
11 |
# notice, this list of conditions and the following disclaimer in the |
|
12 |
# documentation and/or other materials provided with the distribution. |
|
13 |
# |
|
14 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
15 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
16 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
17 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
18 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
19 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
20 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
21 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
22 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
23 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
24 |
# SUCH DAMAGE. |
|
25 |
# |
|
26 |
# The views and conclusions contained in the software and documentation are |
|
27 |
# those of the authors and should not be interpreted as representing official |
|
28 |
# policies, either expressed or implied, of GRNET S.A. |
|
29 |
# |
|
30 |
# Reconcile VM state - Management Script |
|
31 |
|
|
32 |
|
|
33 |
from django.core.management.base import NoArgsCommand |
|
34 |
from synnefo.db.models import VirtualMachine |
|
35 |
from django.conf import settings |
|
36 |
from datetime import datetime, timedelta |
|
37 |
|
|
38 |
from amqplib import client_0_8 as amqp |
|
39 |
|
|
40 |
import time |
|
41 |
import socket |
|
42 |
import json |
|
43 |
|
|
44 |
class Command(NoArgsCommand): |
|
45 |
help = 'Reconcile VM status with the backend' |
|
46 |
|
|
47 |
def open_channel(self): |
|
48 |
conn = None |
|
49 |
while conn == None: |
|
50 |
try: |
|
51 |
conn = amqp.Connection( host=settings.RABBIT_HOST, |
|
52 |
userid=settings.RABBIT_USERNAME, |
|
53 |
password=settings.RABBIT_PASSWORD, |
|
54 |
virtual_host=settings.RABBIT_VHOST) |
|
55 |
except socket.error: |
|
56 |
time.sleep(1) |
|
57 |
pass |
|
58 |
|
|
59 |
return conn.channel() |
|
60 |
|
|
61 |
def handle_noargs(self, **options): |
|
62 |
|
|
63 |
now = datetime.now() |
|
64 |
last_update = timedelta(minutes = 30) |
|
65 |
not_updated = VirtualMachine.objects.filter(updated__lte = (now - last_update)) |
|
66 |
all = VirtualMachine.objects.all() |
|
67 |
|
|
68 |
to_update = all.count() / settings.RECONCILIATION_MIN |
|
69 |
|
|
70 |
vm_ids = map(lambda x: x.name, VirtualMachine.objects.all()[:to_update]) |
|
71 |
sent = False |
|
72 |
|
|
73 |
for vmid in vm_ids : |
|
74 |
while sent is False: |
|
75 |
try: |
|
76 |
msg = dict(type = "reconciliate", vmid = vmid) |
|
77 |
self.chan.basic_publish(json.dumps(msg), |
|
78 |
exchange=settings.EXCHANGE_CRON, |
|
79 |
routing_key="reconciliation.%s"%vmid) |
|
80 |
sent = True |
|
81 |
except socket.error: |
|
82 |
self.chan = self.open_channel() |
|
83 |
except Exception: |
|
84 |
raise |
|
85 |
|
|
86 |
|
|
87 |
print "All: %d, To update: %d, Triggered update for: %s" % (all.count(), not_updated.count(), vm_ids) |
/dev/null | ||
---|---|---|
1 |
# |
|
2 |
# Reconciliate VM state - Management Script |
|
3 |
# |
|
4 |
# Copyright 2010 Greek Research and Technology Network |
|
5 |
# |
|
6 |
|
|
7 |
from django.core.management.base import NoArgsCommand |
|
8 |
from synnefo.db.models import VirtualMachine |
|
9 |
from django.conf import settings |
|
10 |
from datetime import datetime, timedelta |
|
11 |
|
|
12 |
from amqplib import client_0_8 as amqp |
|
13 |
|
|
14 |
import time |
|
15 |
import socket |
|
16 |
import json |
|
17 |
|
|
18 |
class Command(NoArgsCommand): |
|
19 |
help = 'Reconciliate VM status with the backend' |
|
20 |
|
|
21 |
def open_channel(self): |
|
22 |
conn = None |
|
23 |
while conn == None: |
|
24 |
try: |
|
25 |
conn = amqp.Connection( host=settings.RABBIT_HOST, |
|
26 |
userid=settings.RABBIT_USERNAME, |
|
27 |
password=settings.RABBIT_PASSWORD, |
|
28 |
virtual_host=settings.RABBIT_VHOST) |
|
29 |
except socket.error: |
|
30 |
time.sleep(1) |
|
31 |
pass |
|
32 |
|
|
33 |
return conn.channel() |
|
34 |
|
|
35 |
def handle_noargs(self, **options): |
|
36 |
|
|
37 |
now = datetime.now() |
|
38 |
last_update = timedelta(minutes = 30) |
|
39 |
not_updated = VirtualMachine.objects.filter(updated__lte = (now - last_update)) |
|
40 |
all = VirtualMachine.objects.all() |
|
41 |
|
|
42 |
to_update = all.count() / settings.RECONCILIATION_MIN |
|
43 |
|
|
44 |
vm_ids = map(lambda x: x.name, VirtualMachine.objects.all()[:to_update]) |
|
45 |
sent = False |
|
46 |
|
|
47 |
for vmid in vm_ids : |
|
48 |
while sent is False: |
|
49 |
try: |
|
50 |
msg = dict(type = "reconciliate", vmid = vmid) |
|
51 |
self.chan.basic_publish(json.dumps(msg), |
|
52 |
exchange=settings.EXCHANGE_CRON, |
|
53 |
routing_key="reconciliation.%s"%vmid) |
|
54 |
sent = True |
|
55 |
except socket.error: |
|
56 |
self.chan = self.open_channel() |
|
57 |
except Exception: |
|
58 |
raise |
|
59 |
|
|
60 |
|
|
61 |
print "All: %d, To update: %d, Triggered update for: %s" % (all.count(), not_updated.count(), vm_ids) |
b/settings.py.dist | ||
---|---|---|
186 | 186 |
QUEUE_API = "api" |
187 | 187 |
QUEUE_RECONC = "reconciliation" |
188 | 188 |
QUEUE_DEBUG = "debug" # Debug queue, retrieves all messages |
189 |
QUEUES = (QUEUE_GANETI_EVENTS, QUEUE_CRON_CREDITS, QUEUE_EMAIL, QUEUE_API) |
|
189 |
QUEUES = (QUEUE_GANETI_EVENTS, QUEUE_CRON_CREDITS, QUEUE_EMAIL, QUEUE_API, QUEUE_RECONC)
|
|
190 | 190 |
|
191 | 191 |
BINDINGS_DEBUG = [ |
192 | 192 |
# Queue # Exchange # RouteKey # Handler |
Also available in: Unified diff