Skip to content
Snippets Groups Projects
Commit ea642319 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

ConfigWriter.RenameInstance: Stop using iv_name, safer operation


Stop using the disk index encoded in “iv_name” when renaming an instance.

This patch also changes the code to operate on a copy of the instance
until the major changes have been applied. In the case of a failure we
won't loose the instance object anymore.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent a71f835e
No related branches found
No related tags found
No related merge requests found
...@@ -1260,24 +1260,27 @@ class ConfigWriter: ...@@ -1260,24 +1260,27 @@ class ConfigWriter:
""" """
if old_name not in self._config_data.instances: if old_name not in self._config_data.instances:
raise errors.ConfigurationError("Unknown instance '%s'" % old_name) raise errors.ConfigurationError("Unknown instance '%s'" % old_name)
inst = self._config_data.instances[old_name]
del self._config_data.instances[old_name] # Operate on a copy to not loose instance object in case of a failure
inst = self._config_data.instances[old_name].Copy()
inst.name = new_name inst.name = new_name
for disk in inst.disks: for (idx, disk) in enumerate(inst.disks):
if disk.dev_type == constants.LD_FILE: if disk.dev_type == constants.LD_FILE:
# rename the file paths in logical and physical id # rename the file paths in logical and physical id
file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1])) file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
disk_fname = "disk%s" % disk.iv_name.split("/")[1] disk.logical_id = (disk.logical_id[0],
disk.physical_id = disk.logical_id = (disk.logical_id[0], utils.PathJoin(file_storage_dir, inst.name,
utils.PathJoin(file_storage_dir, "disk%s" % idx))
inst.name, disk.physical_id = disk.logical_id
disk_fname))
# Actually replace instance object
del self._config_data.instances[old_name]
self._config_data.instances[inst.name] = inst
# Force update of ssconf files # Force update of ssconf files
self._config_data.cluster.serial_no += 1 self._config_data.cluster.serial_no += 1
self._config_data.instances[inst.name] = inst
self._WriteConfig() self._WriteConfig()
@locking.ssynchronized(_config_lock) @locking.ssynchronized(_config_lock)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment