Commit b23c4333 authored by Manuel Franceschini's avatar Manuel Franceschini
Browse files

Modify LURenameInstance to support file backend

This patch does two things:
- Modify LURenameInstance.Exec to rename directory
  when a file-based instance is renamed
- Modify config.RenameInstance() to replace the directory name in
  config.data for file devices

Reviewed-by: iustinp
parent 0f1a06e3
......@@ -2369,11 +2369,33 @@ class LURenameInstance(LogicalUnit):
inst = self.instance
old_name = inst.name
if inst.disk_template == constants.DT_FILE:
old_file_storage_dir = os.path.dirname(inst.disks[0].logical_id[1])
self.cfg.RenameInstance(inst.name, self.op.new_name)
# re-read the instance from the configuration after rename
inst = self.cfg.GetInstanceInfo(self.op.new_name)
if inst.disk_template == constants.DT_FILE:
new_file_storage_dir = os.path.dirname(inst.disks[0].logical_id[1])
result = rpc.call_file_storage_dir_rename(inst.primary_node,
old_file_storage_dir,
new_file_storage_dir)
if not result:
raise errors.OpExecError("Could not connect to node '%s' to rename"
" directory '%s' to '%s' (but the instance"
" has been renamed in Ganeti)" % (
inst.primary_node, old_file_storage_dir,
new_file_storage_dir))
if not result[0]:
raise errors.OpExecError("Could not rename directory '%s' to '%s'"
" (but the instance has been renamed in"
" Ganeti)" % (old_file_storage_dir,
new_file_storage_dir))
_StartInstanceDisks(self.cfg, inst, None)
try:
if not rpc.call_instance_run_rename(inst.primary_node, inst, old_name,
......
......@@ -34,6 +34,7 @@ much memory.
import os
import tempfile
import random
import re
from ganeti import errors
from ganeti import logger
......@@ -341,6 +342,16 @@ class ConfigWriter:
inst = self._config_data.instances[old_name]
del self._config_data.instances[old_name]
inst.name = new_name
for disk in inst.disks:
if disk.dev_type == constants.LD_FILE:
# rename the file paths in logical and physical id
file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
disk.physical_id = disk.logical_id = (disk.logical_id[0],
os.path.join(file_storage_dir,
inst.name,
disk.iv_name))
self._config_data.instances[inst.name] = inst
self._WriteConfig()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment