Revision 78d9b6b7 db/models.py
b/db/models.py | ||
---|---|---|
196 | 196 |
# VM State [volatile data] |
197 | 197 |
updated = models.DateTimeField(null=True) |
198 | 198 |
action = models.CharField(choices=ACTIONS, max_length=30, null=True) |
199 |
operstate = models.CharField(choices=OPER_STATES, max_length=30, null=True) |
|
200 |
backendjobid = models.PositiveIntegerField(null=True) |
|
201 |
backendopcode = models.CharField(choices=BACKEND_OPCODES, max_length=30, null=True) |
|
202 |
backendjobstatus = models.CharField(choices=BACKEND_STATUSES, max_length=30, null=True) |
|
203 |
backendlogmsg = models.TextField(null=True) |
|
199 |
_operstate = models.CharField(choices=OPER_STATES, max_length=30, null=True)
|
|
200 |
_backendjobid = models.PositiveIntegerField(null=True)
|
|
201 |
_backendopcode = models.CharField(choices=BACKEND_OPCODES, max_length=30, null=True)
|
|
202 |
_backendjobstatus = models.CharField(choices=BACKEND_STATUSES, max_length=30, null=True)
|
|
203 |
_backendlogmsg = models.TextField(null=True)
|
|
204 | 204 |
|
205 | 205 |
# Error classes |
206 | 206 |
class InvalidBackendIdError(Exception): |
... | ... | |
218 | 218 |
|
219 | 219 |
class InvalidActionError(Exception): |
220 | 220 |
def __init__(self, action): |
221 |
self.action = action |
|
221 |
self.__action = action
|
|
222 | 222 |
def __str__(self): |
223 |
return repr(str(self.action)) |
|
223 |
return repr(str(self._action))
|
|
224 | 224 |
|
225 | 225 |
|
226 | 226 |
@staticmethod |
... | ... | |
242 | 242 |
super(VirtualMachine, self).__init__(*args, **kw) |
243 | 243 |
# Before this instance gets save()d |
244 | 244 |
if not self.pk: |
245 |
self.action = None |
|
246 |
self.operstate = "BUILD" |
|
245 |
self._action = None
|
|
246 |
self._operstate = "BUILD"
|
|
247 | 247 |
self.updated = datetime.datetime.now() |
248 |
self.backendjobid = None |
|
249 |
self.backendjobstatus = None |
|
250 |
self.backendopcode = None |
|
251 |
self.backendlogmsg = None |
|
248 |
self._backendjobid = None
|
|
249 |
self._backendjobstatus = None
|
|
250 |
self._backendopcode = None
|
|
251 |
self._backendlogmsg = None
|
|
252 | 252 |
|
253 | 253 |
def process_backend_msg(self, jobid, opcode, status, logmsg): |
254 | 254 |
"""Process a job progress notification from the backend. |
... | ... | |
262 | 262 |
status not in [x[0] for x in VirtualMachine.BACKEND_STATUSES]): |
263 | 263 |
raise VirtualMachine.InvalidBackendMsgError(opcode, status) |
264 | 264 |
|
265 |
self.backendjobid = jobid |
|
266 |
self.backendjobstatus = status |
|
267 |
self.backendopcode = opcode |
|
268 |
self.backendlogmsg = logmsg |
|
265 |
self._backendjobid = jobid
|
|
266 |
self._backendjobstatus = status
|
|
267 |
self._backendopcode = opcode
|
|
268 |
self._backendlogmsg = logmsg
|
|
269 | 269 |
|
270 | 270 |
# Notifications of success change the operating state |
271 | 271 |
if status == 'success': |
272 |
self.operstate = VirtualMachine.OPER_STATE_FROM_OPCODE[opcode] |
|
272 |
self._operstate = VirtualMachine.OPER_STATE_FROM_OPCODE[opcode]
|
|
273 | 273 |
# Special cases OP_INSTANCE_CREATE fails --> ERROR |
274 | 274 |
if status in ('canceled', 'error') and opcode == 'OP_INSTANCE_CREATE': |
275 |
self.operstate = 'ERROR' |
|
275 |
self._operstate = 'ERROR'
|
|
276 | 276 |
# Any other notification of failure leaves the operating state unchanged |
277 | 277 |
|
278 | 278 |
# FIXME: Should be implemented in a pre-save signal handler. |
... | ... | |
284 | 284 |
if not action in [x[0] for x in VirtualMachine.ACTIONS]: |
285 | 285 |
raise VirtualMachine.InvalidActionError(action) |
286 | 286 |
|
287 |
self.action = action |
|
288 |
self.backendjobid = None |
|
289 |
self.backendopcode = None |
|
290 |
self.backendlogmsg = None |
|
287 |
self._action = action
|
|
288 |
self._backendjobid = None
|
|
289 |
self._backendopcode = None
|
|
290 |
self._backendlogmsg = None
|
|
291 | 291 |
self.updated = datetime.datetime.now() |
292 | 292 |
self.save() |
293 | 293 |
|
294 | 294 |
# FIXME: Perhaps move somewhere else, outside the model? |
295 | 295 |
def _get_rsapi_state(self): |
296 | 296 |
try: |
297 |
return VirtualMachine.RSAPI_STATE_FROM_OPER_STATE[self.operstate] |
|
297 |
return VirtualMachine.RSAPI_STATE_FROM_OPER_STATE[self._operstate]
|
|
298 | 298 |
except KeyError: |
299 | 299 |
return "UNKNOWN" |
300 | 300 |
|
Also available in: Unified diff