Add {NEW,OLD}_{PRIMARY,SECONDARY} vars to hooks
authorIustin Pop <iustin@google.com>
Thu, 11 Feb 2010 14:42:49 +0000 (15:42 +0100)
committerIustin Pop <iustin@google.com>
Thu, 11 Feb 2010 16:00:24 +0000 (17:00 +0100)
Per issue 71, the migrate and failover need special variables for
keeping the nodes consistent during instance migrations.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

doc/hooks.rst
lib/cmdlib.py

index 4b46009..9f32d73 100644 (file)
@@ -260,7 +260,7 @@ INSTANCE_SECONDARIES refer to the nodes that were repectively primary
 and secondary before failover.
 
 :directory: instance-failover
 and secondary before failover.
 
 :directory: instance-failover
-:env. vars: IGNORE_CONSISTENCY
+:env. vars: IGNORE_CONSISTENCY, OLD_SECONDARY, OLD_PRIMARY, NEW_SECONDARY, NEW_PRIMARY
 :pre-execution: master node, secondary node
 :post-execution: master node, secondary node
 
 :pre-execution: master node, secondary node
 :post-execution: master node, secondary node
 
@@ -272,7 +272,7 @@ INSTANCE_SECONDARIES refer to the nodes that were repectively primary
 and secondary before migration.
 
 :directory: instance-migrate
 and secondary before migration.
 
 :directory: instance-migrate
-:env. vars: MIGRATE_LIVE, MIGRATE_CLEANUP
+:env. vars: MIGRATE_LIVE, MIGRATE_CLEANUP, OLD_SECONDARY, OLD_PRIMARY, NEW_SECONDARY, NEW_PRIMARY
 :pre-execution: master node, secondary node
 :post-execution: master node, secondary node
 
 :pre-execution: master node, secondary node
 :post-execution: master node, secondary node
 
@@ -492,10 +492,16 @@ INSTANCE_OS_TYPE
   The name of the instance OS.
 
 INSTANCE_PRIMARY
   The name of the instance OS.
 
 INSTANCE_PRIMARY
-  The name of the node which is the primary for the instance.
+  The name of the node which is the primary for the instance. Note that
+  for migrations/failovers, you shouldn't rely on this variable since
+  the nodes change during the exectution, but on the
+  OLD_PRIMARY/NEW_PRIMARY values.
 
 INSTANCE_SECONDARIES
 
 INSTANCE_SECONDARIES
-  Space-separated list of secondary nodes for the instance.
+  Space-separated list of secondary nodes for the instance. Note that
+  for migrations/failovers, you shouldn't rely on this variable since
+  the nodes change during the exectution, but on the
+  OLD_SECONDARY/NEW_SECONDARY values.
 
 INSTANCE_MEMORY
   The memory size (in MiBs) of the instance.
 
 INSTANCE_MEMORY
   The memory size (in MiBs) of the instance.
@@ -538,13 +544,19 @@ SRC_NODE, SRC_PATH, SRC_IMAGE
 
 NEW_SECONDARY
   The name of the node on which the new mirror component is being
 
 NEW_SECONDARY
   The name of the node on which the new mirror component is being
-  added. This can be the name of the current secondary, if the new
-  mirror is on the same secondary.
+  added (for replace disk). This can be the name of the current
+  secondary, if the new mirror is on the same secondary. For
+  migrations/failovers, this is the old primary node.
 
 OLD_SECONDARY
 
 OLD_SECONDARY
-  The name of the old secondary in the replace-disks command Note that
+  The name of the old secondary in the replace-disks command. Note that
   this can be equal to the new secondary if the secondary node hasn't
   this can be equal to the new secondary if the secondary node hasn't
-  actually changed.
+  actually changed. For migrations/failovers, this is the new primary
+  node.
+
+OLD_PRIMARY, NEW_PRIMARY
+  For migrations/failovers, the old and respectively new primary
+  nodes. These two mirror the NEW_SECONDARY/OLD_SECONDARY variables
 
 EXPORT_NODE
   The node on which the exported image of the instance was done.
 
 EXPORT_NODE
   The node on which the exported image of the instance was done.
@@ -595,3 +607,7 @@ script::
   GANETI_OP_TARGET=instance2.example.com
 
 .. vim: set textwidth=72 :
   GANETI_OP_TARGET=instance2.example.com
 
 .. vim: set textwidth=72 :
+.. Local Variables:
+.. mode: rst
+.. fill-column: 72
+.. End:
index 49622c5..473c705 100644 (file)
@@ -4587,12 +4587,19 @@ class LUFailoverInstance(LogicalUnit):
     This runs on master, primary and secondary nodes of the instance.
 
     """
     This runs on master, primary and secondary nodes of the instance.
 
     """
+    instance = self.instance
+    source_node = instance.primary_node
+    target_node = instance.secondary_nodes[0]
     env = {
       "IGNORE_CONSISTENCY": self.op.ignore_consistency,
       "SHUTDOWN_TIMEOUT": self.shutdown_timeout,
     env = {
       "IGNORE_CONSISTENCY": self.op.ignore_consistency,
       "SHUTDOWN_TIMEOUT": self.shutdown_timeout,
+      "OLD_PRIMARY": source_node,
+      "OLD_SECONDARY": target_node,
+      "NEW_PRIMARY": target_node,
+      "NEW_SECONDARY": source_node,
       }
       }
-    env.update(_BuildInstanceHookEnvByObject(self, self.instance))
-    nl = [self.cfg.GetMasterNode()] + list(self.instance.secondary_nodes)
+    env.update(_BuildInstanceHookEnvByObject(self, instance))
+    nl = [self.cfg.GetMasterNode()] + list(instance.secondary_nodes)
     return env, nl, nl
 
   def CheckPrereq(self):
     return env, nl, nl
 
   def CheckPrereq(self):
@@ -4735,9 +4742,17 @@ class LUMigrateInstance(LogicalUnit):
 
     """
     instance = self._migrater.instance
 
     """
     instance = self._migrater.instance
+    source_node = instance.primary_node
+    target_node = instance.secondary_nodes[0]
     env = _BuildInstanceHookEnvByObject(self, instance)
     env["MIGRATE_LIVE"] = self.op.live
     env["MIGRATE_CLEANUP"] = self.op.cleanup
     env = _BuildInstanceHookEnvByObject(self, instance)
     env["MIGRATE_LIVE"] = self.op.live
     env["MIGRATE_CLEANUP"] = self.op.cleanup
+    env.update({
+        "OLD_PRIMARY": source_node,
+        "OLD_SECONDARY": target_node,
+        "NEW_PRIMARY": target_node,
+        "NEW_SECONDARY": source_node,
+        })
     nl = [self.cfg.GetMasterNode()] + list(instance.secondary_nodes)
     return env, nl, nl
 
     nl = [self.cfg.GetMasterNode()] + list(instance.secondary_nodes)
     return env, nl, nl