root / logic / dispatcher_callbacks.py @ 76343e61
History | View | Annotate | Download (1.9 kB)
1 |
import traceback |
---|---|
2 |
import json |
3 |
import logging |
4 |
import sys |
5 |
|
6 |
from synnefo.db.models import VirtualMachine |
7 |
from synnefo.logic import utils, backend |
8 |
|
9 |
_logger = logging.getLogger("synnefo.dispatcher")
|
10 |
|
11 |
def update_db(message): |
12 |
"""Process the status of a VM based on a ganeti status message"""
|
13 |
_logger.debug("Processing msg: %s" % message.body)
|
14 |
try:
|
15 |
msg = json.loads(message.body) |
16 |
|
17 |
if msg["type"] != "ganeti-op-status": |
18 |
_logger.error("Message is of uknown type %s." % (msg["type"],)) |
19 |
return
|
20 |
|
21 |
vmid = utils.id_from_instance_name(msg["instance"])
|
22 |
vm = VirtualMachine.objects.get(id=vmid) |
23 |
|
24 |
backend.process_backend_msg(vm, msg["jobId"], msg["operation"], msg["status"], msg["logmsg"]) |
25 |
_logger.debug("Done processing msg for vm %s." % (msg["instance"])) |
26 |
message.channel.basic_ack(message.delivery_tag) |
27 |
except KeyError: |
28 |
_logger.error("Malformed incoming JSON, missing attributes: " + message.body)
|
29 |
except VirtualMachine.InvalidBackendIdError:
|
30 |
_logger.debug("Ignoring msg for unknown instance %s." % (msg["instance"],)) |
31 |
except VirtualMachine.DoesNotExist:
|
32 |
_logger.error("VM for instance %s with id %d not found in DB." % (msg["instance"], vmid)) |
33 |
except Exception as e: |
34 |
_logger.error("Unexpected error:\n" + "".join(traceback.format_exception(*sys.exc_info()))) |
35 |
|
36 |
def send_email(message): |
37 |
_logger.debug("Request to send email message")
|
38 |
message.channel.basic_ack(message.delivery_tag) |
39 |
|
40 |
|
41 |
def update_credits(message): |
42 |
_logger.debug("Request to update credits")
|
43 |
message.channel.basic_ack(message.delivery_tag) |
44 |
|
45 |
|
46 |
def dummy_proc(message): |
47 |
try:
|
48 |
msg = json.loads(message.body) |
49 |
_logger.debug("Msg (exchange:%s) " % (msg, ))
|
50 |
message.channel.basic_ack(message.delivery_tag) |
51 |
except Exception as e: |
52 |
_logger.error("Could not receive message %s" % e.message)
|
53 |
pass
|