root / lib / mcpu.py @ 204f2086
History | View | Annotate | Download (12.6 kB)
1 | 2f31098c | Iustin Pop | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | a8083063 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc.
|
5 | a8083063 | Iustin Pop | #
|
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | a8083063 | Iustin Pop | # (at your option) any later version.
|
10 | a8083063 | Iustin Pop | #
|
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a8083063 | Iustin Pop | # General Public License for more details.
|
15 | a8083063 | Iustin Pop | #
|
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a8083063 | Iustin Pop | # 02110-1301, USA.
|
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | """Module implementing the logic behind the cluster operations
|
23 | a8083063 | Iustin Pop |
|
24 | a8083063 | Iustin Pop | This module implements the logic for doing operations in the cluster. There
|
25 | a8083063 | Iustin Pop | are two kinds of classes defined:
|
26 | a8083063 | Iustin Pop | - logical units, which know how to deal with their specific opcode only
|
27 | a8083063 | Iustin Pop | - the processor, which dispatches the opcodes to their logical units
|
28 | a8083063 | Iustin Pop |
|
29 | a8083063 | Iustin Pop | """
|
30 | a8083063 | Iustin Pop | |
31 | a8083063 | Iustin Pop | |
32 | a8083063 | Iustin Pop | from ganeti import opcodes |
33 | a8083063 | Iustin Pop | from ganeti import constants |
34 | a8083063 | Iustin Pop | from ganeti import errors |
35 | a8083063 | Iustin Pop | from ganeti import rpc |
36 | a8083063 | Iustin Pop | from ganeti import cmdlib |
37 | a8083063 | Iustin Pop | from ganeti import ssconf |
38 | 0fbbf897 | Iustin Pop | from ganeti import logger |
39 | 04864530 | Guido Trotter | from ganeti import locking |
40 | a8083063 | Iustin Pop | |
41 | 7c0d6283 | Michael Hanselmann | |
42 | a8083063 | Iustin Pop | class Processor(object): |
43 | a8083063 | Iustin Pop | """Object which runs OpCodes"""
|
44 | a8083063 | Iustin Pop | DISPATCH_TABLE = { |
45 | a8083063 | Iustin Pop | # Cluster
|
46 | a8083063 | Iustin Pop | opcodes.OpDestroyCluster: cmdlib.LUDestroyCluster, |
47 | a8083063 | Iustin Pop | opcodes.OpQueryClusterInfo: cmdlib.LUQueryClusterInfo, |
48 | a8083063 | Iustin Pop | opcodes.OpVerifyCluster: cmdlib.LUVerifyCluster, |
49 | a8083063 | Iustin Pop | opcodes.OpDumpClusterConfig: cmdlib.LUDumpClusterConfig, |
50 | 07bd8a51 | Iustin Pop | opcodes.OpRenameCluster: cmdlib.LURenameCluster, |
51 | f4d4e184 | Iustin Pop | opcodes.OpVerifyDisks: cmdlib.LUVerifyDisks, |
52 | 0cc05d44 | Manuel Franceschini | opcodes.OpSetClusterParams: cmdlib.LUSetClusterParams, |
53 | a8083063 | Iustin Pop | # node lu
|
54 | a8083063 | Iustin Pop | opcodes.OpAddNode: cmdlib.LUAddNode, |
55 | a8083063 | Iustin Pop | opcodes.OpQueryNodes: cmdlib.LUQueryNodes, |
56 | dcb93971 | Michael Hanselmann | opcodes.OpQueryNodeVolumes: cmdlib.LUQueryNodeVolumes, |
57 | a8083063 | Iustin Pop | opcodes.OpRemoveNode: cmdlib.LURemoveNode, |
58 | a8083063 | Iustin Pop | # instance lu
|
59 | a8083063 | Iustin Pop | opcodes.OpCreateInstance: cmdlib.LUCreateInstance, |
60 | fe7b0351 | Michael Hanselmann | opcodes.OpReinstallInstance: cmdlib.LUReinstallInstance, |
61 | a8083063 | Iustin Pop | opcodes.OpRemoveInstance: cmdlib.LURemoveInstance, |
62 | decd5f45 | Iustin Pop | opcodes.OpRenameInstance: cmdlib.LURenameInstance, |
63 | a8083063 | Iustin Pop | opcodes.OpActivateInstanceDisks: cmdlib.LUActivateInstanceDisks, |
64 | a8083063 | Iustin Pop | opcodes.OpShutdownInstance: cmdlib.LUShutdownInstance, |
65 | a8083063 | Iustin Pop | opcodes.OpStartupInstance: cmdlib.LUStartupInstance, |
66 | bf6929a2 | Alexander Schreiber | opcodes.OpRebootInstance: cmdlib.LURebootInstance, |
67 | a8083063 | Iustin Pop | opcodes.OpDeactivateInstanceDisks: cmdlib.LUDeactivateInstanceDisks, |
68 | a8083063 | Iustin Pop | opcodes.OpReplaceDisks: cmdlib.LUReplaceDisks, |
69 | a8083063 | Iustin Pop | opcodes.OpFailoverInstance: cmdlib.LUFailoverInstance, |
70 | a8083063 | Iustin Pop | opcodes.OpConnectConsole: cmdlib.LUConnectConsole, |
71 | a8083063 | Iustin Pop | opcodes.OpQueryInstances: cmdlib.LUQueryInstances, |
72 | a8083063 | Iustin Pop | opcodes.OpQueryInstanceData: cmdlib.LUQueryInstanceData, |
73 | 7767bbf5 | Manuel Franceschini | opcodes.OpSetInstanceParams: cmdlib.LUSetInstanceParams, |
74 | 8729e0d7 | Iustin Pop | opcodes.OpGrowDisk: cmdlib.LUGrowDisk, |
75 | a8083063 | Iustin Pop | # os lu
|
76 | a8083063 | Iustin Pop | opcodes.OpDiagnoseOS: cmdlib.LUDiagnoseOS, |
77 | a8083063 | Iustin Pop | # exports lu
|
78 | a8083063 | Iustin Pop | opcodes.OpQueryExports: cmdlib.LUQueryExports, |
79 | a8083063 | Iustin Pop | opcodes.OpExportInstance: cmdlib.LUExportInstance, |
80 | 9ac99fda | Guido Trotter | opcodes.OpRemoveExport: cmdlib.LURemoveExport, |
81 | 5c947f38 | Iustin Pop | # tags lu
|
82 | 5c947f38 | Iustin Pop | opcodes.OpGetTags: cmdlib.LUGetTags, |
83 | 73415719 | Iustin Pop | opcodes.OpSearchTags: cmdlib.LUSearchTags, |
84 | f27302fa | Iustin Pop | opcodes.OpAddTags: cmdlib.LUAddTags, |
85 | f27302fa | Iustin Pop | opcodes.OpDelTags: cmdlib.LUDelTags, |
86 | 06009e27 | Iustin Pop | # test lu
|
87 | 06009e27 | Iustin Pop | opcodes.OpTestDelay: cmdlib.LUTestDelay, |
88 | d61df03e | Iustin Pop | opcodes.OpTestAllocator: cmdlib.LUTestAllocator, |
89 | a8083063 | Iustin Pop | } |
90 | a8083063 | Iustin Pop | |
91 | f1048938 | Iustin Pop | def __init__(self, context): |
92 | a8083063 | Iustin Pop | """Constructor for Processor
|
93 | a8083063 | Iustin Pop |
|
94 | 1a8c0ce1 | Iustin Pop | Args:
|
95 | 1a8c0ce1 | Iustin Pop | - feedback_fn: the feedback function (taking one string) to be run when
|
96 | 1a8c0ce1 | Iustin Pop | interesting events are happening
|
97 | a8083063 | Iustin Pop | """
|
98 | 1c901d13 | Guido Trotter | self.context = context
|
99 | f1048938 | Iustin Pop | self._feedback_fn = None |
100 | 04864530 | Guido Trotter | self.exclusive_BGL = False |
101 | a8083063 | Iustin Pop | |
102 | 36c381d7 | Guido Trotter | def _ExecLU(self, lu): |
103 | 36c381d7 | Guido Trotter | """Logical Unit execution sequence.
|
104 | 36c381d7 | Guido Trotter |
|
105 | 36c381d7 | Guido Trotter | """
|
106 | 36c381d7 | Guido Trotter | write_count = self.context.cfg.write_count
|
107 | 36c381d7 | Guido Trotter | lu.CheckPrereq() |
108 | 36c381d7 | Guido Trotter | hm = HooksMaster(rpc.call_hooks_runner, self, lu)
|
109 | 36c381d7 | Guido Trotter | h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE) |
110 | 36c381d7 | Guido Trotter | lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results, |
111 | 36c381d7 | Guido Trotter | self._feedback_fn, None) |
112 | 36c381d7 | Guido Trotter | try:
|
113 | 36c381d7 | Guido Trotter | result = lu.Exec(self._feedback_fn)
|
114 | 36c381d7 | Guido Trotter | h_results = hm.RunPhase(constants.HOOKS_PHASE_POST) |
115 | 36c381d7 | Guido Trotter | result = lu.HooksCallBack(constants.HOOKS_PHASE_POST, h_results, |
116 | 36c381d7 | Guido Trotter | self._feedback_fn, result)
|
117 | 36c381d7 | Guido Trotter | finally:
|
118 | 36c381d7 | Guido Trotter | # FIXME: This needs locks if not lu_class.REQ_BGL
|
119 | 36c381d7 | Guido Trotter | if write_count != self.context.cfg.write_count: |
120 | 36c381d7 | Guido Trotter | hm.RunConfigUpdate() |
121 | 36c381d7 | Guido Trotter | |
122 | 36c381d7 | Guido Trotter | return result
|
123 | 36c381d7 | Guido Trotter | |
124 | 68adfdb2 | Guido Trotter | def _LockAndExecLU(self, lu, level): |
125 | 68adfdb2 | Guido Trotter | """Execute a Logical Unit, with the needed locks.
|
126 | 68adfdb2 | Guido Trotter |
|
127 | 68adfdb2 | Guido Trotter | This is a recursive function that starts locking the given level, and
|
128 | 68adfdb2 | Guido Trotter | proceeds up, till there are no more locks to acquire. Then it executes the
|
129 | 68adfdb2 | Guido Trotter | given LU and its opcodes.
|
130 | 68adfdb2 | Guido Trotter |
|
131 | 68adfdb2 | Guido Trotter | """
|
132 | 8a2941c4 | Guido Trotter | if level not in locking.LEVELS: |
133 | 8a2941c4 | Guido Trotter | result = self._ExecLU(lu)
|
134 | 8a2941c4 | Guido Trotter | elif level in lu.needed_locks: |
135 | fb8dcb62 | Guido Trotter | # This gives a chance to LUs to make last-minute changes after acquiring
|
136 | fb8dcb62 | Guido Trotter | # locks at any preceding level.
|
137 | fb8dcb62 | Guido Trotter | lu.DeclareLocks(level) |
138 | 3977a4c1 | Guido Trotter | needed_locks = lu.needed_locks[level] |
139 | 3977a4c1 | Guido Trotter | share = lu.share_locks[level] |
140 | 68adfdb2 | Guido Trotter | # This is always safe to do, as we can't acquire more/less locks than
|
141 | 68adfdb2 | Guido Trotter | # what was requested.
|
142 | 6683bba2 | Guido Trotter | lu.acquired_locks[level] = self.context.glm.acquire(level,
|
143 | 6683bba2 | Guido Trotter | needed_locks, |
144 | 6683bba2 | Guido Trotter | shared=share) |
145 | 68adfdb2 | Guido Trotter | try:
|
146 | 68adfdb2 | Guido Trotter | result = self._LockAndExecLU(lu, level + 1) |
147 | 68adfdb2 | Guido Trotter | finally:
|
148 | 6683bba2 | Guido Trotter | # We need to release the current level if we acquired any lock, or if
|
149 | 6683bba2 | Guido Trotter | # we acquired the set-lock (needed_locks is None)
|
150 | 6683bba2 | Guido Trotter | if lu.needed_locks[level] is None or lu.acquired_locks[level]: |
151 | 68adfdb2 | Guido Trotter | self.context.glm.release(level)
|
152 | 68adfdb2 | Guido Trotter | else:
|
153 | 8a2941c4 | Guido Trotter | result = self._LockAndExecLU(lu, level + 1) |
154 | 68adfdb2 | Guido Trotter | |
155 | 68adfdb2 | Guido Trotter | return result
|
156 | 68adfdb2 | Guido Trotter | |
157 | f1048938 | Iustin Pop | def ExecOpCode(self, op, feedback_fn): |
158 | a8083063 | Iustin Pop | """Execute an opcode.
|
159 | a8083063 | Iustin Pop |
|
160 | a8083063 | Iustin Pop | Args:
|
161 | c99a3cc0 | Manuel Franceschini | op: the opcode to be executed
|
162 | a8083063 | Iustin Pop |
|
163 | a8083063 | Iustin Pop | """
|
164 | a8083063 | Iustin Pop | if not isinstance(op, opcodes.OpCode): |
165 | 3ecf6786 | Iustin Pop | raise errors.ProgrammerError("Non-opcode instance passed" |
166 | 3ecf6786 | Iustin Pop | " to ExecOpcode")
|
167 | a8083063 | Iustin Pop | |
168 | f1048938 | Iustin Pop | self._feedback_fn = feedback_fn
|
169 | a8083063 | Iustin Pop | lu_class = self.DISPATCH_TABLE.get(op.__class__, None) |
170 | a8083063 | Iustin Pop | if lu_class is None: |
171 | 3ecf6786 | Iustin Pop | raise errors.OpCodeUnknown("Unknown opcode") |
172 | a8083063 | Iustin Pop | |
173 | c6868e1d | Guido Trotter | if lu_class.REQ_WSSTORE:
|
174 | c6868e1d | Guido Trotter | sstore = ssconf.WritableSimpleStore() |
175 | c6868e1d | Guido Trotter | else:
|
176 | c6868e1d | Guido Trotter | sstore = ssconf.SimpleStore() |
177 | c6868e1d | Guido Trotter | |
178 | 04864530 | Guido Trotter | # Acquire the Big Ganeti Lock exclusively if this LU requires it, and in a
|
179 | 04864530 | Guido Trotter | # shared fashion otherwise (to prevent concurrent run with an exclusive LU.
|
180 | 984f7c32 | Guido Trotter | self.context.glm.acquire(locking.LEVEL_CLUSTER, [locking.BGL],
|
181 | 04864530 | Guido Trotter | shared=not lu_class.REQ_BGL)
|
182 | fe482621 | Iustin Pop | try:
|
183 | 04864530 | Guido Trotter | self.exclusive_BGL = lu_class.REQ_BGL
|
184 | 77b657a3 | Guido Trotter | lu = lu_class(self, op, self.context, sstore) |
185 | d465bdc8 | Guido Trotter | lu.ExpandNames() |
186 | 68adfdb2 | Guido Trotter | assert lu.needed_locks is not None, "needed_locks not set by LU" |
187 | 04e1bfaf | Guido Trotter | result = self._LockAndExecLU(lu, locking.LEVEL_INSTANCE)
|
188 | 04864530 | Guido Trotter | finally:
|
189 | 984f7c32 | Guido Trotter | self.context.glm.release(locking.LEVEL_CLUSTER)
|
190 | 04864530 | Guido Trotter | self.exclusive_BGL = False |
191 | 6a4aa7c1 | Iustin Pop | |
192 | a8083063 | Iustin Pop | return result
|
193 | a8083063 | Iustin Pop | |
194 | 1a8c0ce1 | Iustin Pop | def ChainOpCode(self, op): |
195 | a8083063 | Iustin Pop | """Chain and execute an opcode.
|
196 | a8083063 | Iustin Pop |
|
197 | a8083063 | Iustin Pop | This is used by LUs when they need to execute a child LU.
|
198 | a8083063 | Iustin Pop |
|
199 | a8083063 | Iustin Pop | Args:
|
200 | a8083063 | Iustin Pop | - opcode: the opcode to be executed
|
201 | a8083063 | Iustin Pop |
|
202 | a8083063 | Iustin Pop | """
|
203 | a8083063 | Iustin Pop | if not isinstance(op, opcodes.OpCode): |
204 | 3ecf6786 | Iustin Pop | raise errors.ProgrammerError("Non-opcode instance passed" |
205 | 3ecf6786 | Iustin Pop | " to ExecOpcode")
|
206 | a8083063 | Iustin Pop | |
207 | a8083063 | Iustin Pop | lu_class = self.DISPATCH_TABLE.get(op.__class__, None) |
208 | a8083063 | Iustin Pop | if lu_class is None: |
209 | 3ecf6786 | Iustin Pop | raise errors.OpCodeUnknown("Unknown opcode") |
210 | a8083063 | Iustin Pop | |
211 | 04864530 | Guido Trotter | if lu_class.REQ_BGL and not self.exclusive_BGL: |
212 | 04864530 | Guido Trotter | raise errors.ProgrammerError("LUs which require the BGL cannot" |
213 | 04864530 | Guido Trotter | " be chained to granular ones.")
|
214 | 04864530 | Guido Trotter | |
215 | 64381ad7 | Guido Trotter | assert lu_class.REQ_BGL, "ChainOpCode is still BGL-only" |
216 | 64381ad7 | Guido Trotter | |
217 | c6868e1d | Guido Trotter | if lu_class.REQ_WSSTORE:
|
218 | c6868e1d | Guido Trotter | sstore = ssconf.WritableSimpleStore() |
219 | c6868e1d | Guido Trotter | else:
|
220 | c6868e1d | Guido Trotter | sstore = ssconf.SimpleStore() |
221 | c6868e1d | Guido Trotter | |
222 | f97a6b10 | Iustin Pop | #do_hooks = lu_class.HPATH is not None
|
223 | 77b657a3 | Guido Trotter | lu = lu_class(self, op, self.context, sstore) |
224 | a8083063 | Iustin Pop | lu.CheckPrereq() |
225 | a8083063 | Iustin Pop | #if do_hooks:
|
226 | 2395c322 | Iustin Pop | # hm = HooksMaster(rpc.call_hooks_runner, self, lu)
|
227 | 1fce5219 | Guido Trotter | # h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
|
228 | 1fce5219 | Guido Trotter | # lu.HooksCallBack(constants.HOOKS_PHASE_PRE,
|
229 | 1fce5219 | Guido Trotter | # h_results, self._feedback_fn, None)
|
230 | 1a8c0ce1 | Iustin Pop | result = lu.Exec(self._feedback_fn)
|
231 | a8083063 | Iustin Pop | #if do_hooks:
|
232 | 1fce5219 | Guido Trotter | # h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
|
233 | 1fce5219 | Guido Trotter | # result = lu.HooksCallBack(constants.HOOKS_PHASE_POST,
|
234 | 1fce5219 | Guido Trotter | # h_results, self._feedback_fn, result)
|
235 | a8083063 | Iustin Pop | return result
|
236 | a8083063 | Iustin Pop | |
237 | 0fbbf897 | Iustin Pop | def LogStep(self, current, total, message): |
238 | 0fbbf897 | Iustin Pop | """Log a change in LU execution progress.
|
239 | 0fbbf897 | Iustin Pop |
|
240 | 0fbbf897 | Iustin Pop | """
|
241 | 0fbbf897 | Iustin Pop | logger.Debug("Step %d/%d %s" % (current, total, message))
|
242 | 0fbbf897 | Iustin Pop | self._feedback_fn("STEP %d/%d %s" % (current, total, message)) |
243 | 0fbbf897 | Iustin Pop | |
244 | 5bfac263 | Iustin Pop | def LogWarning(self, message, hint=None): |
245 | 0fbbf897 | Iustin Pop | """Log a warning to the logs and the user.
|
246 | 0fbbf897 | Iustin Pop |
|
247 | 0fbbf897 | Iustin Pop | """
|
248 | 0fbbf897 | Iustin Pop | logger.Error(message) |
249 | 0fbbf897 | Iustin Pop | self._feedback_fn(" - WARNING: %s" % message) |
250 | 5bfac263 | Iustin Pop | if hint:
|
251 | 5bfac263 | Iustin Pop | self._feedback_fn(" Hint: %s" % hint) |
252 | 0fbbf897 | Iustin Pop | |
253 | 0fbbf897 | Iustin Pop | def LogInfo(self, message): |
254 | 0fbbf897 | Iustin Pop | """Log an informational message to the logs and the user.
|
255 | 0fbbf897 | Iustin Pop |
|
256 | 0fbbf897 | Iustin Pop | """
|
257 | 0fbbf897 | Iustin Pop | logger.Info(message) |
258 | 0fbbf897 | Iustin Pop | self._feedback_fn(" - INFO: %s" % message) |
259 | 0fbbf897 | Iustin Pop | |
260 | a8083063 | Iustin Pop | |
261 | a8083063 | Iustin Pop | class HooksMaster(object): |
262 | a8083063 | Iustin Pop | """Hooks master.
|
263 | a8083063 | Iustin Pop |
|
264 | a8083063 | Iustin Pop | This class distributes the run commands to the nodes based on the
|
265 | a8083063 | Iustin Pop | specific LU class.
|
266 | a8083063 | Iustin Pop |
|
267 | a8083063 | Iustin Pop | In order to remove the direct dependency on the rpc module, the
|
268 | a8083063 | Iustin Pop | constructor needs a function which actually does the remote
|
269 | a8083063 | Iustin Pop | call. This will usually be rpc.call_hooks_runner, but any function
|
270 | a8083063 | Iustin Pop | which behaves the same works.
|
271 | a8083063 | Iustin Pop |
|
272 | a8083063 | Iustin Pop | """
|
273 | 2395c322 | Iustin Pop | def __init__(self, callfn, proc, lu): |
274 | a8083063 | Iustin Pop | self.callfn = callfn
|
275 | 2395c322 | Iustin Pop | self.proc = proc
|
276 | a8083063 | Iustin Pop | self.lu = lu
|
277 | a8083063 | Iustin Pop | self.op = lu.op
|
278 | a8083063 | Iustin Pop | self.env, node_list_pre, node_list_post = self._BuildEnv() |
279 | a8083063 | Iustin Pop | self.node_list = {constants.HOOKS_PHASE_PRE: node_list_pre,
|
280 | a8083063 | Iustin Pop | constants.HOOKS_PHASE_POST: node_list_post} |
281 | a8083063 | Iustin Pop | |
282 | a8083063 | Iustin Pop | def _BuildEnv(self): |
283 | a8083063 | Iustin Pop | """Compute the environment and the target nodes.
|
284 | a8083063 | Iustin Pop |
|
285 | a8083063 | Iustin Pop | Based on the opcode and the current node list, this builds the
|
286 | a8083063 | Iustin Pop | environment for the hooks and the target node list for the run.
|
287 | a8083063 | Iustin Pop |
|
288 | a8083063 | Iustin Pop | """
|
289 | a8083063 | Iustin Pop | env = { |
290 | a8083063 | Iustin Pop | "PATH": "/sbin:/bin:/usr/sbin:/usr/bin", |
291 | a8083063 | Iustin Pop | "GANETI_HOOKS_VERSION": constants.HOOKS_VERSION,
|
292 | a8083063 | Iustin Pop | "GANETI_OP_CODE": self.op.OP_ID, |
293 | a8083063 | Iustin Pop | "GANETI_OBJECT_TYPE": self.lu.HTYPE, |
294 | 6a4aa7c1 | Iustin Pop | "GANETI_DATA_DIR": constants.DATA_DIR,
|
295 | a8083063 | Iustin Pop | } |
296 | a8083063 | Iustin Pop | |
297 | 9a395a76 | Iustin Pop | if self.lu.HPATH is not None: |
298 | 9a395a76 | Iustin Pop | lu_env, lu_nodes_pre, lu_nodes_post = self.lu.BuildHooksEnv()
|
299 | 9a395a76 | Iustin Pop | if lu_env:
|
300 | 9a395a76 | Iustin Pop | for key in lu_env: |
301 | 9a395a76 | Iustin Pop | env["GANETI_" + key] = lu_env[key]
|
302 | 9a395a76 | Iustin Pop | else:
|
303 | 9a395a76 | Iustin Pop | lu_nodes_pre = lu_nodes_post = [] |
304 | a8083063 | Iustin Pop | |
305 | 4167825b | Iustin Pop | return env, frozenset(lu_nodes_pre), frozenset(lu_nodes_post) |
306 | 4167825b | Iustin Pop | |
307 | 4167825b | Iustin Pop | def _RunWrapper(self, node_list, hpath, phase): |
308 | 4167825b | Iustin Pop | """Simple wrapper over self.callfn.
|
309 | 4167825b | Iustin Pop |
|
310 | 4167825b | Iustin Pop | This method fixes the environment before doing the rpc call.
|
311 | 4167825b | Iustin Pop |
|
312 | 4167825b | Iustin Pop | """
|
313 | 4167825b | Iustin Pop | env = self.env.copy()
|
314 | 4167825b | Iustin Pop | env["GANETI_HOOKS_PHASE"] = phase
|
315 | 4167825b | Iustin Pop | env["GANETI_HOOKS_PATH"] = hpath
|
316 | f97a6b10 | Iustin Pop | if self.lu.sstore is not None: |
317 | f97a6b10 | Iustin Pop | env["GANETI_CLUSTER"] = self.lu.sstore.GetClusterName() |
318 | f97a6b10 | Iustin Pop | env["GANETI_MASTER"] = self.lu.sstore.GetMasterNode() |
319 | a8083063 | Iustin Pop | |
320 | 4167825b | Iustin Pop | env = dict([(str(key), str(val)) for key, val in env.iteritems()]) |
321 | a8083063 | Iustin Pop | |
322 | 4167825b | Iustin Pop | return self.callfn(node_list, hpath, phase, env) |
323 | a8083063 | Iustin Pop | |
324 | a8083063 | Iustin Pop | def RunPhase(self, phase): |
325 | a8083063 | Iustin Pop | """Run all the scripts for a phase.
|
326 | a8083063 | Iustin Pop |
|
327 | a8083063 | Iustin Pop | This is the main function of the HookMaster.
|
328 | a8083063 | Iustin Pop |
|
329 | b07a6922 | Guido Trotter | Args:
|
330 | b07a6922 | Guido Trotter | phase: the hooks phase to run
|
331 | b07a6922 | Guido Trotter |
|
332 | b07a6922 | Guido Trotter | Returns:
|
333 | b07a6922 | Guido Trotter | the result of the hooks multi-node rpc call
|
334 | b07a6922 | Guido Trotter |
|
335 | a8083063 | Iustin Pop | """
|
336 | a8083063 | Iustin Pop | if not self.node_list[phase]: |
337 | 9a395a76 | Iustin Pop | # empty node list, we should not attempt to run this as either
|
338 | 9a395a76 | Iustin Pop | # we're in the cluster init phase and the rpc client part can't
|
339 | 9a395a76 | Iustin Pop | # even attempt to run, or this LU doesn't do hooks at all
|
340 | a8083063 | Iustin Pop | return
|
341 | 4167825b | Iustin Pop | hpath = self.lu.HPATH
|
342 | 4167825b | Iustin Pop | results = self._RunWrapper(self.node_list[phase], hpath, phase) |
343 | a8083063 | Iustin Pop | if phase == constants.HOOKS_PHASE_PRE:
|
344 | a8083063 | Iustin Pop | errs = [] |
345 | a8083063 | Iustin Pop | if not results: |
346 | 3ecf6786 | Iustin Pop | raise errors.HooksFailure("Communication failure") |
347 | a8083063 | Iustin Pop | for node_name in results: |
348 | a8083063 | Iustin Pop | res = results[node_name] |
349 | a8083063 | Iustin Pop | if res is False or not isinstance(res, list): |
350 | 2395c322 | Iustin Pop | self.proc.LogWarning("Communication failure to node %s" % node_name) |
351 | 2395c322 | Iustin Pop | continue
|
352 | a8083063 | Iustin Pop | for script, hkr, output in res: |
353 | a8083063 | Iustin Pop | if hkr == constants.HKR_FAIL:
|
354 | a8083063 | Iustin Pop | output = output.strip().encode("string_escape")
|
355 | a8083063 | Iustin Pop | errs.append((node_name, script, output)) |
356 | a8083063 | Iustin Pop | if errs:
|
357 | 3ecf6786 | Iustin Pop | raise errors.HooksAbort(errs)
|
358 | b07a6922 | Guido Trotter | return results
|
359 | 6a4aa7c1 | Iustin Pop | |
360 | 6a4aa7c1 | Iustin Pop | def RunConfigUpdate(self): |
361 | 6a4aa7c1 | Iustin Pop | """Run the special configuration update hook
|
362 | 6a4aa7c1 | Iustin Pop |
|
363 | 6a4aa7c1 | Iustin Pop | This is a special hook that runs only on the master after each
|
364 | 6a4aa7c1 | Iustin Pop | top-level LI if the configuration has been updated.
|
365 | 6a4aa7c1 | Iustin Pop |
|
366 | 6a4aa7c1 | Iustin Pop | """
|
367 | 6a4aa7c1 | Iustin Pop | phase = constants.HOOKS_PHASE_POST |
368 | 6a4aa7c1 | Iustin Pop | hpath = constants.HOOKS_NAME_CFGUPDATE |
369 | 6a4aa7c1 | Iustin Pop | if self.lu.sstore is None: |
370 | 6a4aa7c1 | Iustin Pop | raise errors.ProgrammerError("Null sstore on config update hook") |
371 | 6a4aa7c1 | Iustin Pop | nodes = [self.lu.sstore.GetMasterNode()]
|
372 | 6a4aa7c1 | Iustin Pop | results = self._RunWrapper(nodes, hpath, phase) |