Revision 7f2dbcad snf-cyclades-app/synnefo/logic/backend.py

b/snf-cyclades-app/synnefo/logic/backend.py
255 255
    vm.save()
256 256

  
257 257

  
258
def start_action(vm, action):
259
    """Update the state of a VM when a new action is initiated."""
260
    log.debug("Applying action %s to VM %s", action, vm)
261

  
262
    if not action in [x[0] for x in VirtualMachine.ACTIONS]:
263
        raise VirtualMachine.InvalidActionError(action)
264

  
265
    # No actions to deleted VMs
266
    if vm.deleted:
267
        raise VirtualMachine.DeletedError
268

  
269
    # No actions to machines being built. They may be destroyed, however.
270
    if vm.operstate == 'BUILD' and action != 'DESTROY':
271
        raise VirtualMachine.BuildingError
272

  
273
    vm.action = action
274
    vm.backendjobid = None
275
    vm.backendopcode = None
276
    vm.backendjobstatus = None
277
    vm.backendlogmsg = None
278

  
279
    vm.save()
280

  
281

  
282 258
def create_instance_diagnostic(vm, message, source, level="DEBUG", etime=None,
283 259
    details=None):
284 260
    """
......
376 352

  
377 353

  
378 354
def delete_instance(vm):
379
    start_action(vm, 'DESTROY')
380 355
    with pooled_rapi_client(vm) as client:
381 356
        return client.DeleteInstance(vm.backend_vm_id, dry_run=settings.TEST)
382 357

  
......
389 364

  
390 365

  
391 366
def startup_instance(vm):
392
    start_action(vm, 'START')
393 367
    with pooled_rapi_client(vm) as client:
394 368
        return client.StartupInstance(vm.backend_vm_id, dry_run=settings.TEST)
395 369

  
396 370

  
397 371
def shutdown_instance(vm):
398
    start_action(vm, 'STOP')
399 372
    with pooled_rapi_client(vm) as client:
400 373
        return client.ShutdownInstance(vm.backend_vm_id, dry_run=settings.TEST)
401 374

  

Also available in: Unified diff