From 0e137c28bdb3e835ec2b0f299e97e3f88d48b240 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 11 Oct 2007 15:23:31 +0000 Subject: [PATCH] Some small improvements to the hooks environment For the configuration update hook, it's useful to have a consistent name for the target of the operation. As such, the LU code is modified to include an GANETI_OP_TARGET that points either to the cluster (name), node name or instance name depending on the opcode. Also, the NoHooksLU is modified such that its build env method returns an empty (but conformant) result. This should improve things in case by mistake this class' BuildHooksEnv is called. Reviewed-by: imsnah --- lib/cmdlib.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index bd5e77f9e..46c5c6e1c 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -161,7 +161,7 @@ class NoHooksLU(LogicalUnit): This is a no-op, since we don't run hooks. """ - return + return {}, [], [] def _GetWantedNodes(lu, nodes): @@ -239,6 +239,7 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, secondary_nodes: List of secondary nodes as strings """ env = { + "OP_TARGET": name, "INSTANCE_NAME": name, "INSTANCE_PRIMARY": primary_node, "INSTANCE_SECONDARIES": " ".join(secondary_nodes), @@ -545,7 +546,8 @@ class LUInitCluster(LogicalUnit): ourselves in the post-run node list. """ - return {}, [], [self.hostname.name] + env = {"OP_TARGET": self.op.cluster_name} + return env, [], [self.hostname.name] def CheckPrereq(self): """Verify that the passed name is a valid one. @@ -936,6 +938,7 @@ class LURenameCluster(LogicalUnit): """ env = { + "OP_TARGET": self.op.sstore.GetClusterName(), "NEW_NAME": self.op.name, } mn = self.sstore.GetMasterNode() @@ -1126,6 +1129,7 @@ class LURemoveNode(LogicalUnit): """ env = { + "OP_TARGET": self.op.node_name, "NODE_NAME": self.op.node_name, } all_nodes = self.cfg.GetNodeList() @@ -1365,6 +1369,7 @@ class LUAddNode(LogicalUnit): """ env = { + "OP_TARGET": self.op.node_name, "NODE_NAME": self.op.node_name, "NODE_PIP": self.op.primary_ip, "NODE_SIP": self.op.secondary_ip, @@ -1587,6 +1592,7 @@ class LUMasterFailover(LogicalUnit): """ env = { + "OP_TARGET": self.new_master, "NEW_MASTER": self.new_master, "OLD_MASTER": self.old_master, } -- GitLab