Revision 22e52ede logic/backend.py

b/logic/backend.py
27 27
    # Any other notification of failure leaves the operating state unchanged
28 28

  
29 29
    vm.save()
30

  
31
def start_action(vm, action):
32
    """Update the state of a VM when a new action is initiated."""
33
    if not action in [x[0] for x in VirtualMachine.ACTIONS]:
34
        raise VirtualMachine.InvalidActionError(action)
35

  
36
    # No actions to deleted and no actions beside destroy to suspended VMs
37
    if vm.deleted:
38
        raise VirtualMachine.InvalidActionError(action)
39

  
40
    vm._action = action
41
    vm._backendjobid = None
42
    vm._backendopcode = None
43
    vm._backendjobstatus = None
44
    vm._backendlogmsg = None
45

  
46
    # Update the relevant flags if the VM is being suspended or destroyed
47
    if action == "DESTROY":
48
        vm.deleted = True
49
    elif action == "SUSPEND":
50
        vm.suspended = True
51
    elif action == "START":
52
        vm.suspended = False
53
    vm.save()

Also available in: Unified diff