55 |
55 |
_reverse_tags = dict((v.split(':')[3], k) for k, v in _firewall_tags.items())
|
56 |
56 |
|
57 |
57 |
|
|
58 |
def create_client(hostname, port=5080, username=None, password=None):
|
|
59 |
return GanetiRapiClient(hostname=hostname,
|
|
60 |
port=port,
|
|
61 |
username=username,
|
|
62 |
password=password)
|
|
63 |
|
58 |
64 |
@transaction.commit_on_success
|
59 |
65 |
def process_op_status(vm, etime, jobid, opcode, status, logmsg):
|
60 |
66 |
"""Process a job progress notification from the backend
|
... | ... | |
164 |
170 |
if percentage < 0:
|
165 |
171 |
raise ValueError("Percentage cannot be negative")
|
166 |
172 |
|
167 |
|
last_update = vm.buildpercentage
|
168 |
|
|
169 |
173 |
# FIXME: log a warning here, see #1033
|
170 |
174 |
# if last_update > percentage:
|
171 |
175 |
# raise ValueError("Build percentage should increase monotonically " \
|
... | ... | |
246 |
250 |
#
|
247 |
251 |
kw = settings.GANETI_CREATEINSTANCE_KWARGS
|
248 |
252 |
kw['mode'] = 'create'
|
249 |
|
kw['name'] = vm.backend_id
|
|
253 |
kw['name'] = vm.backend_vm_id
|
250 |
254 |
# Defined in settings.GANETI_CREATEINSTANCE_KWARGS
|
251 |
255 |
kw['disk_template'] = flavor.disk_template
|
252 |
256 |
kw['disks'] = [{"size": sz}]
|
... | ... | |
283 |
287 |
|
284 |
288 |
def delete_instance(vm):
|
285 |
289 |
start_action(vm, 'DESTROY')
|
286 |
|
rapi.DeleteInstance(vm.backend_id, dry_run=settings.TEST)
|
|
290 |
rapi.DeleteInstance(vm.backend_vm_id, dry_run=settings.TEST)
|
287 |
291 |
|
288 |
292 |
|
289 |
293 |
def reboot_instance(vm, reboot_type):
|
290 |
294 |
assert reboot_type in ('soft', 'hard')
|
291 |
|
rapi.RebootInstance(vm.backend_id, reboot_type, dry_run=settings.TEST)
|
292 |
|
log.info('Rebooting instance %s', vm.backend_id)
|
|
295 |
rapi.RebootInstance(vm.backend_vm_id, reboot_type, dry_run=settings.TEST)
|
|
296 |
log.info('Rebooting instance %s', vm.backend_vm_id)
|
293 |
297 |
|
294 |
298 |
|
295 |
299 |
def startup_instance(vm):
|
296 |
300 |
start_action(vm, 'START')
|
297 |
|
rapi.StartupInstance(vm.backend_id, dry_run=settings.TEST)
|
|
301 |
rapi.StartupInstance(vm.backend_vm_id, dry_run=settings.TEST)
|
298 |
302 |
|
299 |
303 |
|
300 |
304 |
def shutdown_instance(vm):
|
301 |
305 |
start_action(vm, 'STOP')
|
302 |
|
rapi.ShutdownInstance(vm.backend_id, dry_run=settings.TEST)
|
|
306 |
rapi.ShutdownInstance(vm.backend_vm_id, dry_run=settings.TEST)
|
303 |
307 |
|
304 |
308 |
|
305 |
309 |
def get_instance_console(vm):
|
... | ... | |
316 |
320 |
#
|
317 |
321 |
console = {}
|
318 |
322 |
console['kind'] = 'vnc'
|
319 |
|
i = rapi.GetInstance(vm.backend_id)
|
|
323 |
i = rapi.GetInstance(vm.backend_vm_id)
|
320 |
324 |
if i['hvparams']['serial_console']:
|
321 |
325 |
raise Exception("hv parameter serial_console cannot be true")
|
322 |
326 |
console['host'] = i['pnode']
|
323 |
327 |
console['port'] = i['network_port']
|
324 |
328 |
|
325 |
329 |
return console
|
326 |
|
# return rapi.GetInstanceConsole(vm.backend_id)
|
|
330 |
# return rapi.GetInstanceConsole(vm.backend_vm_id)
|
327 |
331 |
|
328 |
332 |
|
329 |
333 |
def request_status_update(vm):
|
330 |
|
return rapi.GetInstanceInfo(vm.backend_id)
|
|
334 |
return rapi.GetInstanceInfo(vm.backend_vm_id)
|
331 |
335 |
|
332 |
336 |
|
333 |
337 |
def get_job_status(jobid):
|
... | ... | |
391 |
395 |
|
392 |
396 |
def connect_to_network(vm, net):
|
393 |
397 |
nic = {'mode': 'bridged', 'link': net.link.name}
|
394 |
|
rapi.ModifyInstance(vm.backend_id, nics=[('add', -1, nic)],
|
|
398 |
rapi.ModifyInstance(vm.backend_vm_id, nics=[('add', -1, nic)],
|
395 |
399 |
hotplug=True, dry_run=settings.TEST)
|
396 |
400 |
|
397 |
401 |
|
398 |
402 |
def disconnect_from_network(vm, net):
|
399 |
403 |
nics = vm.nics.filter(network__public=False).order_by('index')
|
400 |
404 |
ops = [('remove', nic.index, {}) for nic in nics if nic.network == net]
|
401 |
|
if not ops: # Vm not connected to network
|
|
405 |
if not ops: # Vm not connected to network
|
402 |
406 |
return
|
403 |
|
rapi.ModifyInstance(vm.backend_id, nics=ops[::-1],
|
|
407 |
rapi.ModifyInstance(vm.backend_vm_id, nics=ops[::-1],
|
404 |
408 |
hotplug=True, dry_run=settings.TEST)
|
405 |
409 |
|
406 |
410 |
|
... | ... | |
412 |
416 |
|
413 |
417 |
# Delete all firewall tags
|
414 |
418 |
for t in _firewall_tags.values():
|
415 |
|
rapi.DeleteInstanceTags(vm.backend_id, [t], dry_run=settings.TEST)
|
|
419 |
rapi.DeleteInstanceTags(vm.backend_vm_id, [t], dry_run=settings.TEST)
|
416 |
420 |
|
417 |
|
rapi.AddInstanceTags(vm.backend_id, [tag], dry_run=settings.TEST)
|
|
421 |
rapi.AddInstanceTags(vm.backend_vm_id, [tag], dry_run=settings.TEST)
|
418 |
422 |
|
419 |
423 |
# XXX NOP ModifyInstance call to force process_net_status to run
|
420 |
424 |
# on the dispatcher
|
421 |
|
rapi.ModifyInstance(vm.backend_id,
|
|
425 |
rapi.ModifyInstance(vm.backend_vm_id,
|
422 |
426 |
os_name=settings.GANETI_CREATEINSTANCE_KWARGS['os'])
|
423 |
427 |
|
424 |
428 |
|