Modify LURenameInstance to support file backend
authorManuel Franceschini <manuel.franceschini@gmail.com>
Tue, 8 Apr 2008 16:00:52 +0000 (16:00 +0000)
committerManuel Franceschini <manuel.franceschini@gmail.com>
Tue, 8 Apr 2008 16:00:52 +0000 (16:00 +0000)
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

lib/cmdlib.py
lib/config.py

index 4cfb38f..91f3fdb 100644 (file)
@@ -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,
index 3b9c3d4..3b25994 100644 (file)
@@ -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()