From 3a3e4f1ed0edaa5122b5bcf2319faf7b0a01bbeb Mon Sep 17 00:00:00 2001
From: Andrea Spadaccini <spadaccio@google.com>
Date: Wed, 2 Nov 2011 11:47:28 +0000
Subject: [PATCH] Add netmask and IP version to master IP hooks env

Add the master netmask and master IP version parameters to the hooks and
document them. In this way, the hook environment building function can
be reused for the planned master IP turnup changes.

Signed-off-by: Andrea Spadaccini <spadaccio@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 doc/hooks.rst  | 10 ++++++++--
 lib/backend.py | 15 +++++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/doc/hooks.rst b/doc/hooks.rst
index aa934f550..bd3b8d56e 100644
--- a/doc/hooks.rst
+++ b/doc/hooks.rst
@@ -478,7 +478,7 @@ Modifies the cluster parameters.
 Called when the master IP is activated.
 
 :directory: master-ip-turnup
-:env. vars: MASTER_NETDEV, MASTER_IP
+:env. vars: MASTER_NETDEV, MASTER_IP, MASTER_NETMASK, CLUSTER_IP_VERSION
 :pre-execution: master node
 :post-execution: master node
 
@@ -488,7 +488,7 @@ Called when the master IP is activated.
 Called when the master IP is deactivated.
 
 :directory: master-ip-turndown
-:env. vars: MASTER_NETDEV, MASTER_IP
+:env. vars: MASTER_NETDEV, MASTER_IP, MASTER_NETMASK, CLUSTER_IP_VERSION
 :pre-execution: master node
 :post-execution: master node
 
@@ -549,6 +549,9 @@ Specialised variables
 This is the list of variables which are specific to one or more
 operations.
 
+CLUSTER_IP_VERSION
+  IP version of the master IP (4 or 6)
+
 INSTANCE_NAME
   The name of the instance which is the target of the operation.
 
@@ -627,6 +630,9 @@ MASTER_NETDEV
 MASTER_IP
   The master IP
 
+MASTER_NETMASK
+  Netmask of the master IP
+
 INSTANCE_TAGS
   A space-delimited list of the instance's tags.
 
diff --git a/lib/backend.py b/lib/backend.py
index 47a83e3cf..84a936896 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -283,21 +283,24 @@ def RunLocalHooks(hook_opcode, hooks_path, env_builder_fn):
   return decorator
 
 
-def _BuildMasterIpHookEnv():
+def _BuildMasterIpEnv():
   """Builds environment variables for master IP hooks.
 
   """
-  cfg = _GetConfig()
+  master_netdev, master_ip, _, family, master_netmask = GetMasterInfo()
+  version = str(netutils.IPAddress.GetVersionFromAddressFamily(family))
   env = {
-    "MASTER_NETDEV": cfg.GetMasterNetdev(),
-    "MASTER_IP": cfg.GetMasterIP(),
+    "MASTER_NETDEV": master_netdev,
+    "MASTER_IP": master_ip,
+    "MASTER_NETMASK": master_netmask,
+    "CLUSTER_IP_VERSION": version,
   }
 
   return env
 
 
 @RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup",
-               _BuildMasterIpHookEnv)
+               _BuildMasterIpEnv)
 def ActivateMasterIp(master_ip, master_netmask, master_netdev, family):
   """Activate the IP address of the master daemon.
 
@@ -374,7 +377,7 @@ def StartMasterDaemons(no_voting):
 
 
 @RunLocalHooks(constants.FAKE_OP_MASTER_TURNDOWN, "master-ip-turndown",
-               _BuildMasterIpHookEnv)
+               _BuildMasterIpEnv)
 def DeactivateMasterIp(master_ip, master_netmask, master_netdev):
   """Deactivate the master IP on this node.
 
-- 
GitLab