Revision c25cc9ec logic/callbacks.py
b/logic/callbacks.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
|
44 | 44 |
def update_db(message): |
45 |
"""Process the status of a VM based on a ganeti status message"""
|
|
45 |
"""Process a notification of type 'ganeti-op-status'"""
|
|
46 | 46 |
_logger.debug("Processing ganeti-op-status msg: %s", message.body) |
47 | 47 |
try: |
48 |
msg = _parse_json(message.body)
|
|
48 |
msg = json.loads(message.body)
|
|
49 | 49 |
|
50 | 50 |
if msg["type"] != "ganeti-op-status": |
51 | 51 |
_logger.error("Message is of unknown type %s.", msg["type"]) |
... | ... | |
78 | 78 |
|
79 | 79 |
|
80 | 80 |
def update_net(message): |
81 |
"""Process a network status update notification from Ganeti"""
|
|
81 |
"""Process a notification of type 'ganeti-net-status'"""
|
|
82 | 82 |
_logger.debug("Processing ganeti-net-status msg: %s", message.body) |
83 | 83 |
try: |
84 |
msg = _parse_json(message.body)
|
|
84 |
msg = json.loads(message.body)
|
|
85 | 85 |
|
86 | 86 |
if msg["type"] != "ganeti-net-status": |
87 | 87 |
_logger.error("Message is of unknown type %s", msg["type"]) |
... | ... | |
136 | 136 |
|
137 | 137 |
|
138 | 138 |
def update_build_progress(message): |
139 |
"""Process a progress update message"""
|
|
139 |
"""Process a create progress message"""
|
|
140 | 140 |
try: |
141 | 141 |
msg = json.loads(message.body) |
142 | 142 |
|
... | ... | |
145 | 145 |
return |
146 | 146 |
|
147 | 147 |
# XXX: The following assumes names like snf-12 |
148 |
instid = msg['instance'].split('-')[1] |
|
149 |
|
|
150 |
vm = VirtualMachine.objects.get(id = instid) |
|
151 |
|
|
152 |
backend.process_net_status(vm, msg['percentage']) |
|
148 |
vmid = msg['instance'].split('-')[1] |
|
149 |
vm = VirtualMachine.objects.get(id=vmid) |
|
153 | 150 |
|
154 |
_logger.debug("Done processing ganeti-create-progess msg for vm %s.", |
|
151 |
backend.process_create_progress(vm, msg['rprogress'], msg['wprogress']) |
|
152 |
_logger.debug("Done processing ganeti-create-progress msg for vm %s.", |
|
155 | 153 |
msg["instance"]) |
156 | 154 |
message.channel.basic_ack(message.delivery_tag) |
157 |
|
|
158 | 155 |
except KeyError: |
159 | 156 |
_logger.error("Malformed incoming JSON, missing attributes: %s", |
160 | 157 |
message.body) |
161 |
except VirtualMachine.IllegalState: |
|
162 |
_logger.error("Build progress message for non-building VM %s: %s"% |
|
163 |
(instid, message.body)) |
|
164 | 158 |
except Exception as e: |
165 | 159 |
_logger.exception("Unexpected error") |
166 | 160 |
raise |
167 | 161 |
|
168 | 162 |
|
169 | 163 |
def trigger_status_update(message): |
170 |
""" |
|
171 |
Triggers a status update job for a specific VM id. |
|
172 |
""" |
|
164 |
"""Triggers a status update job for a specific VM id""" |
|
173 | 165 |
_logger.debug("Request to trigger status update: %s", message.body) |
174 | 166 |
|
175 | 167 |
try: |
176 |
msg = _parse_json(message.body)
|
|
168 |
msg = json.loads(message.body)
|
|
177 | 169 |
|
178 | 170 |
if msg["type"] != "reconcile": |
179 | 171 |
_logger.error("Message is of unknown type %s", msg["type"]) |
... | ... | |
192 | 184 |
except Exception as e: |
193 | 185 |
_logger.exception("Unexpected error") |
194 | 186 |
|
195 |
def status_job_finished (message): |
|
196 |
""" |
|
197 |
Updates VM status based on a previously sent status update request |
|
198 |
""" |
|
187 |
|
|
188 |
def status_job_finished(message): |
|
189 |
"""Updates VM status based on a previously sent status update request""" |
|
199 | 190 |
try: |
200 |
msg = _parse_json(message.body)
|
|
191 |
msg = json.loads(message.body)
|
|
201 | 192 |
|
202 | 193 |
if msg["operation"] != 'OP_INSTANCE_QUERY_DATA': |
203 | 194 |
_logger.error("Message is of unknown type %s", msg["operation"]) |
... | ... | |
240 | 231 |
except Exception as e: |
241 | 232 |
_logger.exception("Unexpected error") |
242 | 233 |
|
234 |
|
|
243 | 235 |
def dummy_proc(message): |
244 | 236 |
try: |
245 | 237 |
_logger.debug("Msg: %s" %(message.body)) |
... | ... | |
247 | 239 |
except Exception as e: |
248 | 240 |
_logger.exception("Could not receive message") |
249 | 241 |
pass |
250 |
|
|
251 |
def _parse_json(data): |
|
252 |
try: |
|
253 |
return json.loads(data) |
|
254 |
except Exception as e: |
|
255 |
_logger.error("Could not parse JSON file: %s", e) |
|
256 |
raise |
Also available in: Unified diff