Revision 237a833c
b/lib/backend.py | ||
---|---|---|
332 | 332 |
cfg = _GetConfig() |
333 | 333 |
hr = HooksRunner() |
334 | 334 |
hm = hooksmaster.HooksMaster(hook_opcode, hooks_path, nodes, |
335 |
hr.RunLocalHooks, None, env_fn, |
|
335 |
hr.RunLocalHooks, None, env_fn, None,
|
|
336 | 336 |
logging.warning, cfg.GetClusterName(), |
337 | 337 |
cfg.GetMasterNode()) |
338 | 338 |
hm.RunPhase(constants.HOOKS_PHASE_PRE) |
b/lib/cmdlib/base.py | ||
---|---|---|
283 | 283 |
""" |
284 | 284 |
raise NotImplementedError |
285 | 285 |
|
286 |
def PreparePostHookNodes(self, post_hook_node_uuids): |
|
287 |
"""Extend list of nodes to run the post LU hook. |
|
288 |
|
|
289 |
This method allows LUs to change the list of node UUIDs on which the |
|
290 |
post hook should run after the LU has been executed but before the post |
|
291 |
hook is run. |
|
292 |
|
|
293 |
@type post_hook_node_uuids: list |
|
294 |
@param post_hook_node_uuids: The initial list of node UUIDs to run the |
|
295 |
post hook on, as returned by L{BuildHooksNodes}. |
|
296 |
@rtype: list |
|
297 |
@return: list of node UUIDs on which the post hook should run. The default |
|
298 |
implementation returns the passed in C{post_hook_node_uuids}, but |
|
299 |
custom implementations can choose to alter the list. |
|
300 |
|
|
301 |
""" |
|
302 |
# For consistency with HooksCallBack we ignore the "could be a function" |
|
303 |
# warning |
|
304 |
# pylint: disable=R0201 |
|
305 |
return post_hook_node_uuids |
|
306 |
|
|
286 | 307 |
def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result): |
287 | 308 |
"""Notify the LU about the results of its hooks. |
288 | 309 |
|
... | ... | |
401 | 422 |
""" |
402 | 423 |
raise AssertionError("BuildHooksNodes called for NoHooksLU") |
403 | 424 |
|
425 |
def PreparePostHookNodes(self, post_hook_node_uuids): |
|
426 |
"""Empty PreparePostHookNodes for NoHooksLU. |
|
427 |
|
|
428 |
""" |
|
429 |
raise AssertionError("PreparePostHookNodes called for NoHooksLU") |
|
430 |
|
|
404 | 431 |
|
405 | 432 |
class Tasklet: |
406 | 433 |
"""Tasklet base class. |
b/lib/hooksmaster.py | ||
---|---|---|
46 | 46 |
|
47 | 47 |
class HooksMaster(object): |
48 | 48 |
def __init__(self, opcode, hooks_path, nodes, hooks_execution_fn, |
49 |
hooks_results_adapt_fn, build_env_fn, log_fn, htype=None,
|
|
50 |
cluster_name=None, master_name=None): |
|
49 |
hooks_results_adapt_fn, build_env_fn, prepare_post_nodes_fn,
|
|
50 |
log_fn, htype=None, cluster_name=None, master_name=None):
|
|
51 | 51 |
"""Base class for hooks masters. |
52 | 52 |
|
53 | 53 |
This class invokes the execution of hooks according to the behaviour |
... | ... | |
70 | 70 |
@type build_env_fn: function that returns a dictionary having strings as |
71 | 71 |
keys |
72 | 72 |
@param build_env_fn: function that builds the environment for the hooks |
73 |
@type prepare_post_nodes_fn: function that take a list of node UUIDs and |
|
74 |
returns a list of node UUIDs |
|
75 |
@param prepare_post_nodes_fn: function that is invoked right before |
|
76 |
executing post hooks and can change the list of node UUIDs to run the post |
|
77 |
hooks on |
|
73 | 78 |
@type log_fn: function that accepts a string |
74 | 79 |
@param log_fn: logging function |
75 | 80 |
@type htype: string or None |
... | ... | |
86 | 91 |
self.hooks_execution_fn = hooks_execution_fn |
87 | 92 |
self.hooks_results_adapt_fn = hooks_results_adapt_fn |
88 | 93 |
self.build_env_fn = build_env_fn |
94 |
self.prepare_post_nodes_fn = prepare_post_nodes_fn |
|
89 | 95 |
self.log_fn = log_fn |
90 | 96 |
self.htype = htype |
91 | 97 |
self.cluster_name = cluster_name |
... | ... | |
195 | 201 |
elif phase == constants.HOOKS_PHASE_POST: |
196 | 202 |
if node_names is None: |
197 | 203 |
node_names = self.post_nodes |
204 |
if node_names is not None and self.prepare_post_nodes_fn is not None: |
|
205 |
node_names = frozenset(self.prepare_post_nodes_fn(list(node_names))) |
|
198 | 206 |
env = self._BuildEnv(phase) |
199 | 207 |
else: |
200 | 208 |
raise AssertionError("Unknown phase '%s'" % phase) |
... | ... | |
277 | 285 |
|
278 | 286 |
return HooksMaster(lu.op.OP_ID, lu.HPATH, nodes, hooks_execution_fn, |
279 | 287 |
_RpcResultsToHooksResults, lu.BuildHooksEnv, |
280 |
lu.LogWarning, lu.HTYPE, cluster_name, master_name) |
|
288 |
lu.PreparePostHookNodes, lu.LogWarning, lu.HTYPE, |
|
289 |
cluster_name, master_name) |
Also available in: Unified diff