(2.9) Preserve disk basename on instance rename
authorKlaus Aehlig <aehlig@google.com>
Thu, 30 Jan 2014 11:46:03 +0000 (12:46 +0100)
committerDimitris Aragiorgis <dimara@grnet.gr>
Thu, 27 Mar 2014 08:01:04 +0000 (10:01 +0200)
For file-based instances, upon rename, the directory containing
the instance disks is moved. Therefore, the basename needs to
be preserved in this case. Fix this. Note that so far, this
worked by accident as before 94e252a3 file names used to be
"disk" followed by the index.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>

lib/config.py

index a3cd9fd..52a43ba 100644 (file)
@@ -1545,13 +1545,13 @@ class ConfigWriter:
     inst = self._config_data.instances[old_name].Copy()
     inst.name = new_name
 
-    for (idx, disk) in enumerate(inst.disks):
-      if disk.dev_type == constants.LD_FILE:
+    for (_, disk) in enumerate(inst.disks):
+      if disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
         # rename the file paths in logical and physical id
         file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
         disk.logical_id = (disk.logical_id[0],
                            utils.PathJoin(file_storage_dir, inst.name,
-                                          "disk%s" % idx))
+                                          os.path.basename(disk.logical_id[1])))
         disk.physical_id = disk.logical_id
 
     # Actually replace instance object