From 08eec276bb785384fd86b5a24a79741f0ba3bdb7 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Thu, 11 Feb 2010 15:42:49 +0100 Subject: [PATCH] Add {NEW,OLD}_{PRIMARY,SECONDARY} vars to hooks Per issue 71, the migrate and failover need special variables for keeping the nodes consistent during instance migrations. Signed-off-by: Iustin Pop Reviewed-by: Michael Hanselmann --- doc/hooks.rst | 32 ++++++++++++++++++++++++-------- lib/cmdlib.py | 19 +++++++++++++++++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/doc/hooks.rst b/doc/hooks.rst index 4b46009..9f32d73 100644 --- a/doc/hooks.rst +++ b/doc/hooks.rst @@ -260,7 +260,7 @@ INSTANCE_SECONDARIES refer to the nodes that were repectively primary 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 @@ -272,7 +272,7 @@ INSTANCE_SECONDARIES refer to the nodes that were repectively primary 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 @@ -492,10 +492,16 @@ INSTANCE_OS_TYPE 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 - 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. @@ -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 - 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 - 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 - 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. @@ -595,3 +607,7 @@ script:: GANETI_OP_TARGET=instance2.example.com .. vim: set textwidth=72 : +.. Local Variables: +.. mode: rst +.. fill-column: 72 +.. End: diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 49622c5..473c705 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -4587,12 +4587,19 @@ class LUFailoverInstance(LogicalUnit): 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, + "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): @@ -4735,9 +4742,17 @@ class LUMigrateInstance(LogicalUnit): """ 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.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 -- 1.7.10.4