Revision ad2d6807 logic/backend.py
b/logic/backend.py | ||
---|---|---|
13 | 13 |
rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO) |
14 | 14 |
|
15 | 15 |
|
16 |
def process_backend_msg(vm, jobid, opcode, status, logmsg):
|
|
17 |
"""Process a job progress notification from the backend.
|
|
16 |
def process_op_status(vm, jobid, opcode, status, logmsg):
|
|
17 |
"""Process a job progress notification from the backend |
|
18 | 18 |
|
19 | 19 |
Process an incoming message from the backend (currently Ganeti). |
20 | 20 |
Job notifications with a terminating status (sucess, error, or canceled), |
... | ... | |
44 | 44 |
|
45 | 45 |
vm.save() |
46 | 46 |
|
47 |
|
|
48 |
def process_net_status(vm, nics): |
|
49 |
"""Process a net status notification from the backend |
|
50 |
|
|
51 |
Process an incoming message from the Ganeti backend, |
|
52 |
detailing the NIC configuration of a VM instance. |
|
53 |
|
|
54 |
Update the state of the VM in the DB accordingly. |
|
55 |
|
|
56 |
""" |
|
57 |
|
|
58 |
# For the time being, we can only update the ipfour field, |
|
59 |
# based on the IPv4 address of the first NIC |
|
60 |
vm.ipfour = nics[0]['ip'] |
|
61 |
vm.save() |
|
62 |
|
|
63 |
|
|
47 | 64 |
def start_action(vm, action): |
48 | 65 |
"""Update the state of a VM when a new action is initiated.""" |
49 | 66 |
if not action in [x[0] for x in VirtualMachine.ACTIONS]: |
... | ... | |
72 | 89 |
vm.suspended = False |
73 | 90 |
vm.save() |
74 | 91 |
|
92 |
|
|
75 | 93 |
def create_instance(vm, flavor, password): |
76 | 94 |
# FIXME: `password` must be passed to the Ganeti OS provider via CreateInstance() |
77 | 95 |
return rapi.CreateInstance( |
... | ... | |
91 | 109 |
start_action(vm, 'DESTROY') |
92 | 110 |
rapi.DeleteInstance(vm.backend_id) |
93 | 111 |
|
112 |
|
|
94 | 113 |
def reboot_instance(vm, reboot_type): |
95 | 114 |
assert reboot_type in ('soft', 'hard') |
96 | 115 |
rapi.RebootInstance(vm.backend_id, reboot_type) |
97 | 116 |
|
117 |
|
|
98 | 118 |
def startup_instance(vm): |
99 | 119 |
start_action(vm, 'START') |
100 | 120 |
rapi.StartupInstance(vm.backend_id) |
101 | 121 |
|
122 |
|
|
102 | 123 |
def shutdown_instance(vm): |
103 | 124 |
start_action(vm, 'STOP') |
104 | 125 |
rapi.ShutdownInstance(vm.backend_id) |
105 | 126 |
|
127 |
|
|
106 | 128 |
def get_instance_console(vm): |
107 | 129 |
return rapi.GetInstanceConsole(vm.backend_id) |
Also available in: Unified diff