Revision ca4d59e3 snf-cyclades-app/synnefo/logic/backend.py
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
36 | 36 |
|
37 | 37 |
from synnefo.db.models import (Backend, VirtualMachine, Network, |
38 | 38 |
BackendNetwork, BACKEND_STATUSES, |
39 |
pooled_rapi_client, VirtualMachineDiagnostic) |
|
39 |
pooled_rapi_client, VirtualMachineDiagnostic, |
|
40 |
Flavor) |
|
40 | 41 |
from synnefo.logic import utils |
41 | 42 |
from synnefo import quotas |
42 | 43 |
from synnefo.api.util import release_resource |
... | ... | |
55 | 56 |
|
56 | 57 |
|
57 | 58 |
@transaction.commit_on_success |
58 |
def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None): |
|
59 |
def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None, |
|
60 |
beparams=None): |
|
59 | 61 |
"""Process a job progress notification from the backend |
60 | 62 |
|
61 | 63 |
Process an incoming message from the backend (currently Ganeti). |
... | ... | |
78 | 80 |
if status == 'success' and state_for_success is not None: |
79 | 81 |
vm.operstate = state_for_success |
80 | 82 |
|
81 |
# Update the NICs of the VM |
|
82 | 83 |
if status == "success" and nics is not None: |
84 |
# Update the NICs of the VM |
|
83 | 85 |
_process_net_status(vm, etime, nics) |
84 | 86 |
|
87 |
if beparams: |
|
88 |
assert(opcode == "OP_INSTANCE_SET_PARAMS"), "'beparams' should exist"\ |
|
89 |
" only for SET_PARAMS" |
|
90 |
# VM Resize |
|
91 |
if status == "success": |
|
92 |
# VM has been resized. Change the flavor |
|
93 |
_process_resize(vm, beparams) |
|
94 |
vm.operstate = "STOPPED" |
|
95 |
elif status in ("canceled", "error"): |
|
96 |
vm.operstate = "STOPPED" |
|
97 |
else: |
|
98 |
vm.operstate = "RESIZE" |
|
99 |
|
|
85 | 100 |
# Special case: if OP_INSTANCE_CREATE fails --> ERROR |
86 | 101 |
if opcode == 'OP_INSTANCE_CREATE' and status in ('canceled', 'error'): |
87 | 102 |
vm.operstate = 'ERROR' |
... | ... | |
111 | 126 |
vm.save() |
112 | 127 |
|
113 | 128 |
|
129 |
def _process_resize(vm, beparams): |
|
130 |
"""Change flavor of a VirtualMachine based on new beparams.""" |
|
131 |
old_flavor = vm.flavor |
|
132 |
vcpus = beparams.get("vcpus", None) or old_flavor.cpu |
|
133 |
minmem, maxmem = beparams.get("minmem"), beparams.get("maxmem") |
|
134 |
assert(minmem == maxmem), "Different minmem from maxmem" |
|
135 |
if vcpus is None and maxmem is None: |
|
136 |
return |
|
137 |
ram = maxmem or old_flavor.ram |
|
138 |
try: |
|
139 |
new_flavor = Flavor.objects.get(cpu=vcpus, ram=ram, |
|
140 |
disk=old_flavor.disk, |
|
141 |
disk_template=old_flavor.disk_template) |
|
142 |
except Flavor.DoesNotExist: |
|
143 |
raise Exception("Can not find flavor for VM") |
|
144 |
vm.flavor = new_flavor |
|
145 |
vm.save() |
|
146 |
|
|
147 |
|
|
114 | 148 |
@transaction.commit_on_success |
115 | 149 |
def process_net_status(vm, etime, nics): |
116 | 150 |
"""Wrap _process_net_status inside transaction.""" |
Also available in: Unified diff