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,
import os
import tempfile
import random
+import re
from ganeti import errors
from ganeti import logger
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()