diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 1b569857ad2540761f90b4c4244a66d679eb7a74..c241dad3b1efd507bd3a8971c94b7013d064f100 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -153,6 +153,24 @@ class LogicalUnit(object): """ raise NotImplementedError + def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result): + """Notify the LU about the results of its hooks. + + This method is called every time a hooks phase is executed, and notifies + the Logical Unit about the hooks' result. The LU can then use it to alter + its result based on the hooks. By default the method does nothing and the + previous result is passed back unchanged but any LU can define it if it + wants to use the local cluster hook-scripts somehow. + + Args: + phase: the hooks phase that has just been run + hooks_results: the results of the multi-node hooks rpc call + feedback_fn: function to send feedback back to the caller + lu_result: the previous result this LU had, or None in the PRE phase. + + """ + return lu_result + class NoHooksLU(LogicalUnit): """Simple LU which runs no hooks. diff --git a/lib/mcpu.py b/lib/mcpu.py index 228465b219580f893c3130660c012a5829f9d84a..6411df522946efce2f62e526e3ed7ecd81a14c10 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -127,10 +127,14 @@ class Processor(object): lu = lu_class(self, op, self.cfg, self.sstore) lu.CheckPrereq() hm = HooksMaster(rpc.call_hooks_runner, self, lu) - hm.RunPhase(constants.HOOKS_PHASE_PRE) + h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE) + lu.HooksCallBack(constants.HOOKS_PHASE_PRE, + h_results, self._feedback_fn, None) try: result = lu.Exec(self._feedback_fn) - hm.RunPhase(constants.HOOKS_PHASE_POST) + h_results = hm.RunPhase(constants.HOOKS_PHASE_POST) + result = lu.HooksCallBack(constants.HOOKS_PHASE_POST, + h_results, self._feedback_fn, result) finally: if lu.cfg is not None: # we use lu.cfg and not self.cfg as for init cluster, self.cfg @@ -166,10 +170,14 @@ class Processor(object): lu.CheckPrereq() #if do_hooks: # hm = HooksMaster(rpc.call_hooks_runner, self, lu) - # hm.RunPhase(constants.HOOKS_PHASE_PRE) + # h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE) + # lu.HooksCallBack(constants.HOOKS_PHASE_PRE, + # h_results, self._feedback_fn, None) result = lu.Exec(self._feedback_fn) #if do_hooks: - # hm.RunPhase(constants.HOOKS_PHASE_POST) + # h_results = hm.RunPhase(constants.HOOKS_PHASE_POST) + # result = lu.HooksCallBack(constants.HOOKS_PHASE_POST, + # h_results, self._feedback_fn, result) return result def LogStep(self, current, total, message):