Revision decd5f45 lib/backend.py
b/lib/backend.py | ||
---|---|---|
416 | 416 |
return True |
417 | 417 |
|
418 | 418 |
|
419 |
def RunRenameInstance(instance, old_name, os_disk, swap_disk): |
|
420 |
"""Run the OS rename script for an instance. |
|
421 |
|
|
422 |
Args: |
|
423 |
instance: the instance object |
|
424 |
old_name: the old name of the instance |
|
425 |
os_disk: the instance-visible name of the os device |
|
426 |
swap_disk: the instance-visible name of the swap device |
|
427 |
|
|
428 |
""" |
|
429 |
inst_os = OSFromDisk(instance.os) |
|
430 |
|
|
431 |
script = inst_os.rename_script |
|
432 |
|
|
433 |
os_device = instance.FindDisk(os_disk) |
|
434 |
if os_device is None: |
|
435 |
logger.Error("Can't find this device-visible name '%s'" % os_disk) |
|
436 |
return False |
|
437 |
|
|
438 |
swap_device = instance.FindDisk(swap_disk) |
|
439 |
if swap_device is None: |
|
440 |
logger.Error("Can't find this device-visible name '%s'" % swap_disk) |
|
441 |
return False |
|
442 |
|
|
443 |
real_os_dev = _RecursiveFindBD(os_device) |
|
444 |
if real_os_dev is None: |
|
445 |
raise errors.BlockDeviceError("Block device '%s' is not set up" % |
|
446 |
str(os_device)) |
|
447 |
real_os_dev.Open() |
|
448 |
|
|
449 |
real_swap_dev = _RecursiveFindBD(swap_device) |
|
450 |
if real_swap_dev is None: |
|
451 |
raise errors.BlockDeviceError("Block device '%s' is not set up" % |
|
452 |
str(swap_device)) |
|
453 |
real_swap_dev.Open() |
|
454 |
|
|
455 |
logfile = "%s/rename-%s-%s-%s-%d.log" % (constants.LOG_OS_DIR, instance.os, |
|
456 |
old_name, |
|
457 |
instance.name, int(time.time())) |
|
458 |
if not os.path.exists(constants.LOG_OS_DIR): |
|
459 |
os.mkdir(constants.LOG_OS_DIR, 0750) |
|
460 |
|
|
461 |
command = utils.BuildShellCmd("cd %s && %s -o %s -n %s -b %s -s %s &>%s", |
|
462 |
inst_os.path, script, old_name, instance.name, |
|
463 |
real_os_dev.dev_path, real_swap_dev.dev_path, |
|
464 |
logfile) |
|
465 |
|
|
466 |
result = utils.RunCmd(command) |
|
467 |
|
|
468 |
if result.failed: |
|
469 |
logger.Error("os create command '%s' returned error: %s" |
|
470 |
" output: %s" % |
|
471 |
(command, result.fail_reason, result.output)) |
|
472 |
return False |
|
473 |
|
|
474 |
return True |
|
475 |
|
|
476 |
|
|
419 | 477 |
def _GetVGInfo(vg_name): |
420 | 478 |
"""Get informations about the volume group. |
421 | 479 |
|
Also available in: Unified diff