From b5f5fae92c731a48bf325ddc65c1fd4cc18d7e6b Mon Sep 17 00:00:00 2001
From: Luca Bigliardi <shammash@google.com>
Date: Mon, 10 Aug 2009 09:48:48 +0100
Subject: [PATCH] Post cluster initialization LU

Add an 'empty' logical unit to run hooks after cluster initialization.

Signed-off-by: Luca Bigliardi <shammash@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/cmdlib.py  | 29 +++++++++++++++++++++++++++++
 lib/mcpu.py    |  1 +
 lib/opcodes.py | 11 +++++++++++
 3 files changed, 41 insertions(+)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 132325293..ce2f0b1ec 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -749,6 +749,35 @@ def _GetStorageTypeArgs(cfg, storage_type):
   return []
 
 
+class LUPostInitCluster(LogicalUnit):
+  """Logical unit for running hooks after cluster initialization.
+
+  """
+  HPATH = "cluster-init"
+  HTYPE = constants.HTYPE_CLUSTER
+  _OP_REQP = []
+
+  def BuildHooksEnv(self):
+    """Build hooks env.
+
+    """
+    env = {"OP_TARGET": self.cfg.GetClusterName()}
+    mn = self.cfg.GetMasterNode()
+    return env, [], [mn]
+
+  def CheckPrereq(self):
+    """No prerequisites to check.
+
+    """
+    return True
+
+  def Exec(self, feedback_fn):
+    """Nothing to do.
+
+    """
+    return True
+
+
 class LUDestroyCluster(NoHooksLU):
   """Logical unit for destroying the cluster.
 
diff --git a/lib/mcpu.py b/lib/mcpu.py
index 01d6eb3ef..59d312e50 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -42,6 +42,7 @@ class Processor(object):
   """Object which runs OpCodes"""
   DISPATCH_TABLE = {
     # Cluster
+    opcodes.OpPostInitCluster: cmdlib.LUPostInitCluster,
     opcodes.OpDestroyCluster: cmdlib.LUDestroyCluster,
     opcodes.OpQueryClusterInfo: cmdlib.LUQueryClusterInfo,
     opcodes.OpVerifyCluster: cmdlib.LUVerifyCluster,
diff --git a/lib/opcodes.py b/lib/opcodes.py
index 77497fcac..b8673f24b 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -170,6 +170,17 @@ class OpCode(BaseOpCode):
 
 # cluster opcodes
 
+class OpPostInitCluster(OpCode):
+  """Post cluster initialization.
+
+  This opcode does not touch the cluster at all. Its purpose is to run hooks
+  after the cluster has been initialized.
+
+  """
+  OP_ID = "OP_CLUSTER_POST_INIT"
+  __slots__ = OpCode.__slots__ + []
+
+
 class OpDestroyCluster(OpCode):
   """Destroy the cluster.
 
-- 
GitLab