Revision 1c3231aa lib/hooksmaster.py
b/lib/hooksmaster.py | ||
---|---|---|
171 | 171 |
|
172 | 172 |
return self.hooks_execution_fn(node_list, hpath, phase, env) |
173 | 173 |
|
174 |
def RunPhase(self, phase, nodes=None): |
|
174 |
def RunPhase(self, phase, node_names=None):
|
|
175 | 175 |
"""Run all the scripts for a phase. |
176 | 176 |
|
177 | 177 |
This is the main function of the HookMaster. |
178 | 178 |
It executes self.hooks_execution_fn, and after running |
179 |
self.hooks_results_adapt_fn on its results it expects them to be in the form
|
|
180 |
{node_name: (fail_msg, [(script, result, output), ...]}). |
|
179 |
self.hooks_results_adapt_fn on its results it expects them to be in the |
|
180 |
form {node_name: (fail_msg, [(script, result, output), ...]}).
|
|
181 | 181 |
|
182 | 182 |
@param phase: one of L{constants.HOOKS_PHASE_POST} or |
183 | 183 |
L{constants.HOOKS_PHASE_PRE}; it denotes the hooks phase |
184 |
@param nodes: overrides the predefined list of nodes for the given phase |
|
184 |
@param node_names: overrides the predefined list of nodes for the given |
|
185 |
phase |
|
185 | 186 |
@return: the processed results of the hooks multi-node rpc call |
186 | 187 |
@raise errors.HooksFailure: on communication failure to the nodes |
187 | 188 |
@raise errors.HooksAbort: on failure of one of the hooks |
188 | 189 |
|
189 | 190 |
""" |
190 | 191 |
if phase == constants.HOOKS_PHASE_PRE: |
191 |
if nodes is None: |
|
192 |
nodes = self.pre_nodes |
|
192 |
if node_names is None:
|
|
193 |
node_names = self.pre_nodes
|
|
193 | 194 |
env = self.pre_env |
194 | 195 |
elif phase == constants.HOOKS_PHASE_POST: |
195 |
if nodes is None: |
|
196 |
nodes = self.post_nodes |
|
196 |
if node_names is None:
|
|
197 |
node_names = self.post_nodes
|
|
197 | 198 |
env = self._BuildEnv(phase) |
198 | 199 |
else: |
199 | 200 |
raise AssertionError("Unknown phase '%s'" % phase) |
200 | 201 |
|
201 |
if not nodes: |
|
202 |
if not node_names:
|
|
202 | 203 |
# empty node list, we should not attempt to run this as either |
203 | 204 |
# we're in the cluster init phase and the rpc client part can't |
204 | 205 |
# even attempt to run, or this LU doesn't do hooks at all |
205 | 206 |
return |
206 | 207 |
|
207 |
results = self._RunWrapper(nodes, self.hooks_path, phase, env) |
|
208 |
results = self._RunWrapper(node_names, self.hooks_path, phase, env)
|
|
208 | 209 |
if not results: |
209 | 210 |
msg = "Communication Failure" |
210 | 211 |
if phase == constants.HOOKS_PHASE_PRE: |
... | ... | |
258 | 259 |
if lu.HPATH is None: |
259 | 260 |
nodes = (None, None) |
260 | 261 |
else: |
261 |
nodes = map(frozenset, lu.BuildHooksNodes()) |
|
262 |
hooks_nodes = lu.BuildHooksNodes() |
|
263 |
to_name = lambda node_uuids: frozenset(lu.cfg.GetNodeNames(node_uuids)) |
|
264 |
if len(hooks_nodes) == 2: |
|
265 |
nodes = (to_name(hooks_nodes[0]), to_name(hooks_nodes[1])) |
|
266 |
elif len(hooks_nodes) == 3: |
|
267 |
nodes = (to_name(hooks_nodes[0]), |
|
268 |
to_name(hooks_nodes[1]) | frozenset(hooks_nodes[2])) |
|
269 |
else: |
|
270 |
raise errors.ProgrammerError( |
|
271 |
"LogicalUnit.BuildHooksNodes must return a 2- or 3-tuple") |
|
262 | 272 |
|
263 | 273 |
master_name = cluster_name = None |
264 | 274 |
if lu.cfg: |
265 |
master_name = lu.cfg.GetMasterNode() |
|
275 |
master_name = lu.cfg.GetMasterNodeName()
|
|
266 | 276 |
cluster_name = lu.cfg.GetClusterName() |
267 | 277 |
|
268 | 278 |
return HooksMaster(lu.op.OP_ID, lu.HPATH, nodes, hooks_execution_fn, |
Also available in: Unified diff