Revision c25cc9ec logic/backend.py
b/logic/backend.py | ||
---|---|---|
134 | 134 |
firewall_profile=firewall_profile) |
135 | 135 |
vm.save() |
136 | 136 |
|
137 |
|
|
137 | 138 |
@transaction.commit_on_success |
138 |
def process_progress_update(vm, pr_percentage):
|
|
139 |
def process_create_progress(vm, rprogress, wprogress):
|
|
139 | 140 |
|
140 |
if not type(pr_percentage) == int: |
|
141 |
raise TypeError("Percentage not an integer") |
|
141 |
# XXX: This only uses the read progress for now. |
|
142 |
# Explore whether it would make sense to use the value of wprogress |
|
143 |
# somewhere. |
|
144 |
percentage = int(rprogress) |
|
142 | 145 |
|
143 |
if pr_percentage < 0 or pr_percentage > 100:
|
|
144 |
raise Exception("Percentage not in range (0, 100)")
|
|
146 |
if percentage < 0 or percentage > 100:
|
|
147 |
raise ValueError("Percentage not in range [0, 100]")
|
|
145 | 148 |
|
146 | 149 |
last_update = vm.buildpercentage |
147 | 150 |
|
148 |
if last_update > pr_percentage:
|
|
149 |
raise Exception("Build percentage should increase monotonically" \
|
|
150 |
" (old=%d, new=%d)"%(last_update, pr_percentage))
|
|
151 |
if last_update > percentage: |
|
152 |
raise ValueError("Build percentage should increase monotonically " \
|
|
153 |
"(old = %d, new = %d)" % (last_update, percentage))
|
|
151 | 154 |
|
152 |
if not vm.operstate == 'BUILD': |
|
153 |
raise VirtualMachine.IllegalState("VM is not in building state") |
|
155 |
# This assumes that no message of type 'ganeti-create-progress' is going to |
|
156 |
# arrive once OP_INSTANCE_CREATE has succeeded for a Ganeti instance and |
|
157 |
# the instance is STARTED. What if the two messages are processed by two |
|
158 |
# separate dispatcher threads, and the 'ganeti-op-status' message for |
|
159 |
# successful creation gets processed before the 'ganeti-create-progress' |
|
160 |
# message? [vkoukis] |
|
161 |
# |
|
162 |
#if not vm.operstate == 'BUILD': |
|
163 |
# raise VirtualMachine.IllegalState("VM is not in building state") |
|
154 | 164 |
|
155 |
vm.buildpercentage = pr_percentage
|
|
165 |
vm.buildpercentage = percentage |
|
156 | 166 |
vm.save() |
157 | 167 |
|
168 |
|
|
158 | 169 |
def start_action(vm, action): |
159 | 170 |
"""Update the state of a VM when a new action is initiated.""" |
160 | 171 |
if not action in [x[0] for x in VirtualMachine.ACTIONS]: |
... | ... | |
206 | 217 |
# Handle arguments to CreateInstance() as a dictionary, |
207 | 218 |
# initialize it based on a deployment-specific value. |
208 | 219 |
# This enables the administrator to override deployment-specific |
209 |
# arguments, such as the disk templatei to use, name of os provider
|
|
220 |
# arguments, such as the disk template to use, name of os provider |
|
210 | 221 |
# and hypervisor-specific parameters at will (see Synnefo #785, #835). |
211 | 222 |
# |
212 | 223 |
kw = settings.GANETI_CREATEINSTANCE_KWARGS |
... | ... | |
279 | 290 |
return console |
280 | 291 |
# return rapi.GetInstanceConsole(vm.backend_id) |
281 | 292 |
|
293 |
|
|
282 | 294 |
def request_status_update(vm): |
283 | 295 |
return rapi.GetInstanceInfo(vm.backend_id) |
284 | 296 |
|
... | ... | |
290 | 302 |
def update_status(vm, status): |
291 | 303 |
utils.update_state(vm, status) |
292 | 304 |
|
305 |
|
|
293 | 306 |
def create_network_link(): |
294 | 307 |
try: |
295 | 308 |
last = NetworkLink.objects.order_by('-index')[0] |
... | ... | |
303 | 316 |
available=True) |
304 | 317 |
return None # All link slots are filled |
305 | 318 |
|
319 |
|
|
306 | 320 |
@transaction.commit_on_success |
307 | 321 |
def create_network(name, owner): |
308 | 322 |
try: |
... | ... | |
324 | 338 |
|
325 | 339 |
return network |
326 | 340 |
|
341 |
|
|
327 | 342 |
@transaction.commit_on_success |
328 | 343 |
def delete_network(net): |
329 | 344 |
link = net.link |
... | ... | |
338 | 353 |
net.state = 'DELETED' |
339 | 354 |
net.save() |
340 | 355 |
|
356 |
|
|
341 | 357 |
def connect_to_network(vm, net): |
342 | 358 |
nic = {'mode': 'bridged', 'link': net.link.name} |
343 | 359 |
rapi.ModifyInstance(vm.backend_id, |
344 | 360 |
nics=[('add', nic)], |
345 | 361 |
dry_run=settings.TEST) |
346 | 362 |
|
363 |
|
|
347 | 364 |
def disconnect_from_network(vm, net): |
348 | 365 |
nics = vm.nics.filter(network__public=False).order_by('index') |
349 | 366 |
new_nics = [nic for nic in nics if nic.network != net] |
... | ... | |
356 | 373 |
'link': nic.network.link.name})) |
357 | 374 |
rapi.ModifyInstance(vm.backend_id, nics=ops, dry_run=settings.TEST) |
358 | 375 |
|
376 |
|
|
359 | 377 |
def set_firewall_profile(vm, profile): |
360 | 378 |
try: |
361 | 379 |
tag = _firewall_tags[profile] |
Also available in: Unified diff