Revision e3a99a08
b/db/db_controller.py | ||
---|---|---|
30 | 30 |
from threading import Thread, Event, currentThread |
31 | 31 |
|
32 | 32 |
from synnefo.db.models import VirtualMachine |
33 |
from synnefo.logic import utils |
|
33 | 34 |
|
34 | 35 |
GANETI_ZMQ_PUBLISHER = "tcp://62.217.120.67:5801" # FIXME: move to settings.py |
35 | 36 |
|
... | ... | |
65 | 66 |
return |
66 | 67 |
|
67 | 68 |
if msg["type"] != "ganeti-op-status": |
68 |
logging.debug("Ignoring message of uknown type %s." % (msg["type"])) |
|
69 |
logging.debug("Ignoring message of uknown type %s." % (msg["type"],))
|
|
69 | 70 |
continue |
70 | 71 |
|
71 |
vmid = VirtualMachine.id_from_instance_name(msg["instance"])
|
|
72 |
vmid = utils.id_from_instance_name(msg["instance"])
|
|
72 | 73 |
vm = VirtualMachine.objects.get(id=vmid) |
73 | 74 |
|
74 |
logging.debug("Processing msg: %s" % (msg)) |
|
75 |
logging.debug("Processing msg: %s" % (msg,))
|
|
75 | 76 |
vm.process_backend_msg(msg["jobId"], msg["operation"], msg["status"], msg["logmsg"]) |
76 | 77 |
vm.save() |
77 | 78 |
logging.debug("Done processing msg for vm %s." % (msg["instance"])) |
... | ... | |
79 | 80 |
except KeyError: |
80 | 81 |
logging.error("Malformed incoming JSON, missing attributes: " + data) |
81 | 82 |
except VirtualMachine.InvalidBackendIdError: |
82 |
logging.debug("Ignoring msg for unknown instance %s." % msg["instance"])
|
|
83 |
logging.debug("Ignoring msg for unknown instance %s." % (msg["instance"],))
|
|
83 | 84 |
except VirtualMachine.DoesNotExist: |
84 | 85 |
logging.error("VM for instance %s with id %d not found in DB." % (msg["instance"], vmid)) |
85 | 86 |
except Exception as e: |
b/db/models.py | ||
---|---|---|
328 | 328 |
def __str__(self): |
329 | 329 |
return repr(str(self._action)) |
330 | 330 |
|
331 |
@staticmethod |
|
332 |
def id_from_instance_name(name): |
|
333 |
"""Returns VirtualMachine's Django id, given a ganeti machine name. |
|
334 |
|
|
335 |
Strips the ganeti prefix atm. Needs a better name! |
|
336 |
|
|
337 |
""" |
|
338 |
if not str(name).startswith(settings.BACKEND_PREFIX_ID): |
|
339 |
raise VirtualMachine.InvalidBackendIdError(str(name)) |
|
340 |
ns = str(name).lstrip(settings.BACKEND_PREFIX_ID) |
|
341 |
if not ns.isdigit(): |
|
342 |
raise VirtualMachine.InvalidBackendIdError(str(name)) |
|
343 |
return int(ns) |
|
344 |
|
|
345 | 331 |
def __init__(self, *args, **kw): |
346 | 332 |
"""Initialize state for just created VM instances.""" |
347 | 333 |
super(VirtualMachine, self).__init__(*args, **kw) |
b/logic/utils.py | ||
---|---|---|
3 | 3 |
# |
4 | 4 |
# Copyright 2010 Greek Research and Technology Network |
5 | 5 |
# |
6 |
from django.conf import settings |
|
6 | 7 |
|
8 |
from db.models import VirtualMachine |
|
9 |
|
|
10 |
def id_from_instance_name(name): |
|
11 |
"""Returns VirtualMachine's Django id, given a ganeti machine name. |
|
12 |
|
|
13 |
Strips the ganeti prefix atm. Needs a better name! |
|
14 |
|
|
15 |
""" |
|
16 |
if not str(name).startswith(settings.BACKEND_PREFIX_ID): |
|
17 |
raise VirtualMachine.InvalidBackendIdError(str(name)) |
|
18 |
ns = str(name).lstrip(settings.BACKEND_PREFIX_ID) |
|
19 |
if not ns.isdigit(): |
|
20 |
raise VirtualMachine.InvalidBackendIdError(str(name)) |
|
21 |
|
|
22 |
return int(ns) |
Also available in: Unified diff