root / lib / cmdlib.py @ 58385fad
History | View | Annotate | Download (340.8 kB)
1 | 2f31098c | Iustin Pop | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | e7c6e02b | Michael Hanselmann | # Copyright (C) 2006, 2007, 2008 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 | 880478f8 | Iustin Pop | """Module implementing the master-side code."""
|
23 | a8083063 | Iustin Pop | |
24 | c70d2d9b | Iustin Pop | # pylint: disable-msg=W0201
|
25 | c70d2d9b | Iustin Pop | |
26 | c70d2d9b | Iustin Pop | # W0201 since most LU attributes are defined in CheckPrereq or similar
|
27 | c70d2d9b | Iustin Pop | # functions
|
28 | a8083063 | Iustin Pop | |
29 | a8083063 | Iustin Pop | import os |
30 | a8083063 | Iustin Pop | import os.path |
31 | a8083063 | Iustin Pop | import time |
32 | a8083063 | Iustin Pop | import re |
33 | a8083063 | Iustin Pop | import platform |
34 | ffa1c0dc | Iustin Pop | import logging |
35 | 74409b12 | Iustin Pop | import copy |
36 | b98bf262 | Michael Hanselmann | import OpenSSL |
37 | a8083063 | Iustin Pop | |
38 | a8083063 | Iustin Pop | from ganeti import ssh |
39 | a8083063 | Iustin Pop | from ganeti import utils |
40 | a8083063 | Iustin Pop | from ganeti import errors |
41 | a8083063 | Iustin Pop | from ganeti import hypervisor |
42 | 6048c986 | Guido Trotter | from ganeti import locking |
43 | a8083063 | Iustin Pop | from ganeti import constants |
44 | a8083063 | Iustin Pop | from ganeti import objects |
45 | 8d14b30d | Iustin Pop | from ganeti import serializer |
46 | 112f18a5 | Iustin Pop | from ganeti import ssconf |
47 | 1338f2b4 | Balazs Lecz | from ganeti import uidpool |
48 | e311ed53 | Michael Hanselmann | from ganeti import compat |
49 | d61df03e | Iustin Pop | |
50 | d61df03e | Iustin Pop | |
51 | a8083063 | Iustin Pop | class LogicalUnit(object): |
52 | 396e1b78 | Michael Hanselmann | """Logical Unit base class.
|
53 | a8083063 | Iustin Pop |
|
54 | a8083063 | Iustin Pop | Subclasses must follow these rules:
|
55 | d465bdc8 | Guido Trotter | - implement ExpandNames
|
56 | 6fd35c4d | Michael Hanselmann | - implement CheckPrereq (except when tasklets are used)
|
57 | 6fd35c4d | Michael Hanselmann | - implement Exec (except when tasklets are used)
|
58 | a8083063 | Iustin Pop | - implement BuildHooksEnv
|
59 | a8083063 | Iustin Pop | - redefine HPATH and HTYPE
|
60 | 05f86716 | Guido Trotter | - optionally redefine their run requirements:
|
61 | 7e55040e | Guido Trotter | REQ_BGL: the LU needs to hold the Big Ganeti Lock exclusively
|
62 | 05f86716 | Guido Trotter |
|
63 | 05f86716 | Guido Trotter | Note that all commands require root permissions.
|
64 | a8083063 | Iustin Pop |
|
65 | 20777413 | Iustin Pop | @ivar dry_run_result: the value (if any) that will be returned to the caller
|
66 | 20777413 | Iustin Pop | in dry-run mode (signalled by opcode dry_run parameter)
|
67 | 20777413 | Iustin Pop |
|
68 | a8083063 | Iustin Pop | """
|
69 | a8083063 | Iustin Pop | HPATH = None
|
70 | a8083063 | Iustin Pop | HTYPE = None
|
71 | a8083063 | Iustin Pop | _OP_REQP = [] |
72 | 7e55040e | Guido Trotter | REQ_BGL = True
|
73 | a8083063 | Iustin Pop | |
74 | 72737a7f | Iustin Pop | def __init__(self, processor, op, context, rpc): |
75 | a8083063 | Iustin Pop | """Constructor for LogicalUnit.
|
76 | a8083063 | Iustin Pop |
|
77 | 5bbd3f7f | Michael Hanselmann | This needs to be overridden in derived classes in order to check op
|
78 | a8083063 | Iustin Pop | validity.
|
79 | a8083063 | Iustin Pop |
|
80 | a8083063 | Iustin Pop | """
|
81 | 5bfac263 | Iustin Pop | self.proc = processor
|
82 | a8083063 | Iustin Pop | self.op = op
|
83 | 77b657a3 | Guido Trotter | self.cfg = context.cfg
|
84 | 77b657a3 | Guido Trotter | self.context = context
|
85 | 72737a7f | Iustin Pop | self.rpc = rpc
|
86 | ca2a79e1 | Guido Trotter | # Dicts used to declare locking needs to mcpu
|
87 | d465bdc8 | Guido Trotter | self.needed_locks = None |
88 | 6683bba2 | Guido Trotter | self.acquired_locks = {}
|
89 | c772d142 | Michael Hanselmann | self.share_locks = dict.fromkeys(locking.LEVELS, 0) |
90 | ca2a79e1 | Guido Trotter | self.add_locks = {}
|
91 | ca2a79e1 | Guido Trotter | self.remove_locks = {}
|
92 | c4a2fee1 | Guido Trotter | # Used to force good behavior when calling helper functions
|
93 | c4a2fee1 | Guido Trotter | self.recalculate_locks = {}
|
94 | c92b310a | Michael Hanselmann | self.__ssh = None |
95 | 86d9d3bb | Iustin Pop | # logging
|
96 | fe267188 | Iustin Pop | self.LogWarning = processor.LogWarning # pylint: disable-msg=C0103 |
97 | fe267188 | Iustin Pop | self.LogInfo = processor.LogInfo # pylint: disable-msg=C0103 |
98 | d984846d | Iustin Pop | self.LogStep = processor.LogStep # pylint: disable-msg=C0103 |
99 | 20777413 | Iustin Pop | # support for dry-run
|
100 | 20777413 | Iustin Pop | self.dry_run_result = None |
101 | ee844e20 | Iustin Pop | # support for generic debug attribute
|
102 | ee844e20 | Iustin Pop | if (not hasattr(self.op, "debug_level") or |
103 | ee844e20 | Iustin Pop | not isinstance(self.op.debug_level, int)): |
104 | ee844e20 | Iustin Pop | self.op.debug_level = 0 |
105 | c92b310a | Michael Hanselmann | |
106 | 6fd35c4d | Michael Hanselmann | # Tasklets
|
107 | 3a012b41 | Michael Hanselmann | self.tasklets = None |
108 | 6fd35c4d | Michael Hanselmann | |
109 | a8083063 | Iustin Pop | for attr_name in self._OP_REQP: |
110 | a8083063 | Iustin Pop | attr_val = getattr(op, attr_name, None) |
111 | a8083063 | Iustin Pop | if attr_val is None: |
112 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Required parameter '%s' missing" % |
113 | 5c983ee5 | Iustin Pop | attr_name, errors.ECODE_INVAL) |
114 | 6fd35c4d | Michael Hanselmann | |
115 | 4be4691d | Iustin Pop | self.CheckArguments()
|
116 | a8083063 | Iustin Pop | |
117 | c92b310a | Michael Hanselmann | def __GetSSH(self): |
118 | c92b310a | Michael Hanselmann | """Returns the SshRunner object
|
119 | c92b310a | Michael Hanselmann |
|
120 | c92b310a | Michael Hanselmann | """
|
121 | c92b310a | Michael Hanselmann | if not self.__ssh: |
122 | 6b0469d2 | Iustin Pop | self.__ssh = ssh.SshRunner(self.cfg.GetClusterName()) |
123 | c92b310a | Michael Hanselmann | return self.__ssh |
124 | c92b310a | Michael Hanselmann | |
125 | c92b310a | Michael Hanselmann | ssh = property(fget=__GetSSH)
|
126 | c92b310a | Michael Hanselmann | |
127 | 4be4691d | Iustin Pop | def CheckArguments(self): |
128 | 4be4691d | Iustin Pop | """Check syntactic validity for the opcode arguments.
|
129 | 4be4691d | Iustin Pop |
|
130 | 4be4691d | Iustin Pop | This method is for doing a simple syntactic check and ensure
|
131 | 4be4691d | Iustin Pop | validity of opcode parameters, without any cluster-related
|
132 | 4be4691d | Iustin Pop | checks. While the same can be accomplished in ExpandNames and/or
|
133 | 4be4691d | Iustin Pop | CheckPrereq, doing these separate is better because:
|
134 | 4be4691d | Iustin Pop |
|
135 | 4be4691d | Iustin Pop | - ExpandNames is left as as purely a lock-related function
|
136 | 5bbd3f7f | Michael Hanselmann | - CheckPrereq is run after we have acquired locks (and possible
|
137 | 4be4691d | Iustin Pop | waited for them)
|
138 | 4be4691d | Iustin Pop |
|
139 | 4be4691d | Iustin Pop | The function is allowed to change the self.op attribute so that
|
140 | 4be4691d | Iustin Pop | later methods can no longer worry about missing parameters.
|
141 | 4be4691d | Iustin Pop |
|
142 | 4be4691d | Iustin Pop | """
|
143 | 4be4691d | Iustin Pop | pass
|
144 | 4be4691d | Iustin Pop | |
145 | d465bdc8 | Guido Trotter | def ExpandNames(self): |
146 | d465bdc8 | Guido Trotter | """Expand names for this LU.
|
147 | d465bdc8 | Guido Trotter |
|
148 | d465bdc8 | Guido Trotter | This method is called before starting to execute the opcode, and it should
|
149 | d465bdc8 | Guido Trotter | update all the parameters of the opcode to their canonical form (e.g. a
|
150 | d465bdc8 | Guido Trotter | short node name must be fully expanded after this method has successfully
|
151 | d465bdc8 | Guido Trotter | completed). This way locking, hooks, logging, ecc. can work correctly.
|
152 | d465bdc8 | Guido Trotter |
|
153 | d465bdc8 | Guido Trotter | LUs which implement this method must also populate the self.needed_locks
|
154 | d465bdc8 | Guido Trotter | member, as a dict with lock levels as keys, and a list of needed lock names
|
155 | d465bdc8 | Guido Trotter | as values. Rules:
|
156 | e4376078 | Iustin Pop |
|
157 | e4376078 | Iustin Pop | - use an empty dict if you don't need any lock
|
158 | e4376078 | Iustin Pop | - if you don't need any lock at a particular level omit that level
|
159 | e4376078 | Iustin Pop | - don't put anything for the BGL level
|
160 | e4376078 | Iustin Pop | - if you want all locks at a level use locking.ALL_SET as a value
|
161 | d465bdc8 | Guido Trotter |
|
162 | 3977a4c1 | Guido Trotter | If you need to share locks (rather than acquire them exclusively) at one
|
163 | 3977a4c1 | Guido Trotter | level you can modify self.share_locks, setting a true value (usually 1) for
|
164 | 3977a4c1 | Guido Trotter | that level. By default locks are not shared.
|
165 | 3977a4c1 | Guido Trotter |
|
166 | 6fd35c4d | Michael Hanselmann | This function can also define a list of tasklets, which then will be
|
167 | 6fd35c4d | Michael Hanselmann | executed in order instead of the usual LU-level CheckPrereq and Exec
|
168 | 6fd35c4d | Michael Hanselmann | functions, if those are not defined by the LU.
|
169 | 6fd35c4d | Michael Hanselmann |
|
170 | e4376078 | Iustin Pop | Examples::
|
171 | e4376078 | Iustin Pop |
|
172 | e4376078 | Iustin Pop | # Acquire all nodes and one instance
|
173 | e4376078 | Iustin Pop | self.needed_locks = {
|
174 | e4376078 | Iustin Pop | locking.LEVEL_NODE: locking.ALL_SET,
|
175 | e4376078 | Iustin Pop | locking.LEVEL_INSTANCE: ['instance1.example.tld'],
|
176 | e4376078 | Iustin Pop | }
|
177 | e4376078 | Iustin Pop | # Acquire just two nodes
|
178 | e4376078 | Iustin Pop | self.needed_locks = {
|
179 | e4376078 | Iustin Pop | locking.LEVEL_NODE: ['node1.example.tld', 'node2.example.tld'],
|
180 | e4376078 | Iustin Pop | }
|
181 | e4376078 | Iustin Pop | # Acquire no locks
|
182 | e4376078 | Iustin Pop | self.needed_locks = {} # No, you can't leave it to the default value None
|
183 | d465bdc8 | Guido Trotter |
|
184 | d465bdc8 | Guido Trotter | """
|
185 | d465bdc8 | Guido Trotter | # The implementation of this method is mandatory only if the new LU is
|
186 | d465bdc8 | Guido Trotter | # concurrent, so that old LUs don't need to be changed all at the same
|
187 | d465bdc8 | Guido Trotter | # time.
|
188 | d465bdc8 | Guido Trotter | if self.REQ_BGL: |
189 | d465bdc8 | Guido Trotter | self.needed_locks = {} # Exclusive LUs don't need locks. |
190 | d465bdc8 | Guido Trotter | else:
|
191 | d465bdc8 | Guido Trotter | raise NotImplementedError |
192 | d465bdc8 | Guido Trotter | |
193 | fb8dcb62 | Guido Trotter | def DeclareLocks(self, level): |
194 | fb8dcb62 | Guido Trotter | """Declare LU locking needs for a level
|
195 | fb8dcb62 | Guido Trotter |
|
196 | fb8dcb62 | Guido Trotter | While most LUs can just declare their locking needs at ExpandNames time,
|
197 | fb8dcb62 | Guido Trotter | sometimes there's the need to calculate some locks after having acquired
|
198 | fb8dcb62 | Guido Trotter | the ones before. This function is called just before acquiring locks at a
|
199 | fb8dcb62 | Guido Trotter | particular level, but after acquiring the ones at lower levels, and permits
|
200 | fb8dcb62 | Guido Trotter | such calculations. It can be used to modify self.needed_locks, and by
|
201 | fb8dcb62 | Guido Trotter | default it does nothing.
|
202 | fb8dcb62 | Guido Trotter |
|
203 | fb8dcb62 | Guido Trotter | This function is only called if you have something already set in
|
204 | fb8dcb62 | Guido Trotter | self.needed_locks for the level.
|
205 | fb8dcb62 | Guido Trotter |
|
206 | fb8dcb62 | Guido Trotter | @param level: Locking level which is going to be locked
|
207 | fb8dcb62 | Guido Trotter | @type level: member of ganeti.locking.LEVELS
|
208 | fb8dcb62 | Guido Trotter |
|
209 | fb8dcb62 | Guido Trotter | """
|
210 | fb8dcb62 | Guido Trotter | |
211 | a8083063 | Iustin Pop | def CheckPrereq(self): |
212 | a8083063 | Iustin Pop | """Check prerequisites for this LU.
|
213 | a8083063 | Iustin Pop |
|
214 | a8083063 | Iustin Pop | This method should check that the prerequisites for the execution
|
215 | a8083063 | Iustin Pop | of this LU are fulfilled. It can do internode communication, but
|
216 | a8083063 | Iustin Pop | it should be idempotent - no cluster or system changes are
|
217 | a8083063 | Iustin Pop | allowed.
|
218 | a8083063 | Iustin Pop |
|
219 | a8083063 | Iustin Pop | The method should raise errors.OpPrereqError in case something is
|
220 | a8083063 | Iustin Pop | not fulfilled. Its return value is ignored.
|
221 | a8083063 | Iustin Pop |
|
222 | a8083063 | Iustin Pop | This method should also update all the parameters of the opcode to
|
223 | d465bdc8 | Guido Trotter | their canonical form if it hasn't been done by ExpandNames before.
|
224 | a8083063 | Iustin Pop |
|
225 | a8083063 | Iustin Pop | """
|
226 | 3a012b41 | Michael Hanselmann | if self.tasklets is not None: |
227 | b4a9eb66 | Michael Hanselmann | for (idx, tl) in enumerate(self.tasklets): |
228 | abae1b2b | Michael Hanselmann | logging.debug("Checking prerequisites for tasklet %s/%s",
|
229 | abae1b2b | Michael Hanselmann | idx + 1, len(self.tasklets)) |
230 | 6fd35c4d | Michael Hanselmann | tl.CheckPrereq() |
231 | 6fd35c4d | Michael Hanselmann | else:
|
232 | 6fd35c4d | Michael Hanselmann | raise NotImplementedError |
233 | a8083063 | Iustin Pop | |
234 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
235 | a8083063 | Iustin Pop | """Execute the LU.
|
236 | a8083063 | Iustin Pop |
|
237 | a8083063 | Iustin Pop | This method should implement the actual work. It should raise
|
238 | a8083063 | Iustin Pop | errors.OpExecError for failures that are somewhat dealt with in
|
239 | a8083063 | Iustin Pop | code, or expected.
|
240 | a8083063 | Iustin Pop |
|
241 | a8083063 | Iustin Pop | """
|
242 | 3a012b41 | Michael Hanselmann | if self.tasklets is not None: |
243 | b4a9eb66 | Michael Hanselmann | for (idx, tl) in enumerate(self.tasklets): |
244 | abae1b2b | Michael Hanselmann | logging.debug("Executing tasklet %s/%s", idx + 1, len(self.tasklets)) |
245 | 6fd35c4d | Michael Hanselmann | tl.Exec(feedback_fn) |
246 | 6fd35c4d | Michael Hanselmann | else:
|
247 | 6fd35c4d | Michael Hanselmann | raise NotImplementedError |
248 | a8083063 | Iustin Pop | |
249 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
250 | a8083063 | Iustin Pop | """Build hooks environment for this LU.
|
251 | a8083063 | Iustin Pop |
|
252 | a8083063 | Iustin Pop | This method should return a three-node tuple consisting of: a dict
|
253 | a8083063 | Iustin Pop | containing the environment that will be used for running the
|
254 | a8083063 | Iustin Pop | specific hook for this LU, a list of node names on which the hook
|
255 | a8083063 | Iustin Pop | should run before the execution, and a list of node names on which
|
256 | a8083063 | Iustin Pop | the hook should run after the execution.
|
257 | a8083063 | Iustin Pop |
|
258 | a8083063 | Iustin Pop | The keys of the dict must not have 'GANETI_' prefixed as this will
|
259 | a8083063 | Iustin Pop | be handled in the hooks runner. Also note additional keys will be
|
260 | a8083063 | Iustin Pop | added by the hooks runner. If the LU doesn't define any
|
261 | a8083063 | Iustin Pop | environment, an empty dict (and not None) should be returned.
|
262 | a8083063 | Iustin Pop |
|
263 | 8a3fe350 | Guido Trotter | No nodes should be returned as an empty list (and not None).
|
264 | a8083063 | Iustin Pop |
|
265 | a8083063 | Iustin Pop | Note that if the HPATH for a LU class is None, this function will
|
266 | a8083063 | Iustin Pop | not be called.
|
267 | a8083063 | Iustin Pop |
|
268 | a8083063 | Iustin Pop | """
|
269 | a8083063 | Iustin Pop | raise NotImplementedError |
270 | a8083063 | Iustin Pop | |
271 | 1fce5219 | Guido Trotter | def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result): |
272 | 1fce5219 | Guido Trotter | """Notify the LU about the results of its hooks.
|
273 | 1fce5219 | Guido Trotter |
|
274 | 1fce5219 | Guido Trotter | This method is called every time a hooks phase is executed, and notifies
|
275 | 1fce5219 | Guido Trotter | the Logical Unit about the hooks' result. The LU can then use it to alter
|
276 | 1fce5219 | Guido Trotter | its result based on the hooks. By default the method does nothing and the
|
277 | 1fce5219 | Guido Trotter | previous result is passed back unchanged but any LU can define it if it
|
278 | 1fce5219 | Guido Trotter | wants to use the local cluster hook-scripts somehow.
|
279 | 1fce5219 | Guido Trotter |
|
280 | e4376078 | Iustin Pop | @param phase: one of L{constants.HOOKS_PHASE_POST} or
|
281 | e4376078 | Iustin Pop | L{constants.HOOKS_PHASE_PRE}; it denotes the hooks phase
|
282 | e4376078 | Iustin Pop | @param hook_results: the results of the multi-node hooks rpc call
|
283 | e4376078 | Iustin Pop | @param feedback_fn: function used send feedback back to the caller
|
284 | e4376078 | Iustin Pop | @param lu_result: the previous Exec result this LU had, or None
|
285 | e4376078 | Iustin Pop | in the PRE phase
|
286 | e4376078 | Iustin Pop | @return: the new Exec result, based on the previous result
|
287 | e4376078 | Iustin Pop | and hook results
|
288 | 1fce5219 | Guido Trotter |
|
289 | 1fce5219 | Guido Trotter | """
|
290 | 2d54e29c | Iustin Pop | # API must be kept, thus we ignore the unused argument and could
|
291 | 2d54e29c | Iustin Pop | # be a function warnings
|
292 | 2d54e29c | Iustin Pop | # pylint: disable-msg=W0613,R0201
|
293 | 1fce5219 | Guido Trotter | return lu_result
|
294 | 1fce5219 | Guido Trotter | |
295 | 43905206 | Guido Trotter | def _ExpandAndLockInstance(self): |
296 | 43905206 | Guido Trotter | """Helper function to expand and lock an instance.
|
297 | 43905206 | Guido Trotter |
|
298 | 43905206 | Guido Trotter | Many LUs that work on an instance take its name in self.op.instance_name
|
299 | 43905206 | Guido Trotter | and need to expand it and then declare the expanded name for locking. This
|
300 | 43905206 | Guido Trotter | function does it, and then updates self.op.instance_name to the expanded
|
301 | 43905206 | Guido Trotter | name. It also initializes needed_locks as a dict, if this hasn't been done
|
302 | 43905206 | Guido Trotter | before.
|
303 | 43905206 | Guido Trotter |
|
304 | 43905206 | Guido Trotter | """
|
305 | 43905206 | Guido Trotter | if self.needed_locks is None: |
306 | 43905206 | Guido Trotter | self.needed_locks = {}
|
307 | 43905206 | Guido Trotter | else:
|
308 | 43905206 | Guido Trotter | assert locking.LEVEL_INSTANCE not in self.needed_locks, \ |
309 | 43905206 | Guido Trotter | "_ExpandAndLockInstance called with instance-level locks set"
|
310 | cf26a87a | Iustin Pop | self.op.instance_name = _ExpandInstanceName(self.cfg, |
311 | cf26a87a | Iustin Pop | self.op.instance_name)
|
312 | cf26a87a | Iustin Pop | self.needed_locks[locking.LEVEL_INSTANCE] = self.op.instance_name |
313 | 43905206 | Guido Trotter | |
314 | a82ce292 | Guido Trotter | def _LockInstancesNodes(self, primary_only=False): |
315 | c4a2fee1 | Guido Trotter | """Helper function to declare instances' nodes for locking.
|
316 | c4a2fee1 | Guido Trotter |
|
317 | c4a2fee1 | Guido Trotter | This function should be called after locking one or more instances to lock
|
318 | c4a2fee1 | Guido Trotter | their nodes. Its effect is populating self.needed_locks[locking.LEVEL_NODE]
|
319 | c4a2fee1 | Guido Trotter | with all primary or secondary nodes for instances already locked and
|
320 | c4a2fee1 | Guido Trotter | present in self.needed_locks[locking.LEVEL_INSTANCE].
|
321 | c4a2fee1 | Guido Trotter |
|
322 | c4a2fee1 | Guido Trotter | It should be called from DeclareLocks, and for safety only works if
|
323 | c4a2fee1 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] is set.
|
324 | c4a2fee1 | Guido Trotter |
|
325 | c4a2fee1 | Guido Trotter | In the future it may grow parameters to just lock some instance's nodes, or
|
326 | c4a2fee1 | Guido Trotter | to just lock primaries or secondary nodes, if needed.
|
327 | c4a2fee1 | Guido Trotter |
|
328 | e4376078 | Iustin Pop | If should be called in DeclareLocks in a way similar to::
|
329 | c4a2fee1 | Guido Trotter |
|
330 | e4376078 | Iustin Pop | if level == locking.LEVEL_NODE:
|
331 | e4376078 | Iustin Pop | self._LockInstancesNodes()
|
332 | c4a2fee1 | Guido Trotter |
|
333 | a82ce292 | Guido Trotter | @type primary_only: boolean
|
334 | a82ce292 | Guido Trotter | @param primary_only: only lock primary nodes of locked instances
|
335 | a82ce292 | Guido Trotter |
|
336 | c4a2fee1 | Guido Trotter | """
|
337 | c4a2fee1 | Guido Trotter | assert locking.LEVEL_NODE in self.recalculate_locks, \ |
338 | c4a2fee1 | Guido Trotter | "_LockInstancesNodes helper function called with no nodes to recalculate"
|
339 | c4a2fee1 | Guido Trotter | |
340 | c4a2fee1 | Guido Trotter | # TODO: check if we're really been called with the instance locks held
|
341 | c4a2fee1 | Guido Trotter | |
342 | c4a2fee1 | Guido Trotter | # For now we'll replace self.needed_locks[locking.LEVEL_NODE], but in the
|
343 | c4a2fee1 | Guido Trotter | # future we might want to have different behaviors depending on the value
|
344 | c4a2fee1 | Guido Trotter | # of self.recalculate_locks[locking.LEVEL_NODE]
|
345 | c4a2fee1 | Guido Trotter | wanted_nodes = [] |
346 | 6683bba2 | Guido Trotter | for instance_name in self.acquired_locks[locking.LEVEL_INSTANCE]: |
347 | c4a2fee1 | Guido Trotter | instance = self.context.cfg.GetInstanceInfo(instance_name)
|
348 | c4a2fee1 | Guido Trotter | wanted_nodes.append(instance.primary_node) |
349 | a82ce292 | Guido Trotter | if not primary_only: |
350 | a82ce292 | Guido Trotter | wanted_nodes.extend(instance.secondary_nodes) |
351 | 9513b6ab | Guido Trotter | |
352 | 9513b6ab | Guido Trotter | if self.recalculate_locks[locking.LEVEL_NODE] == constants.LOCKS_REPLACE: |
353 | 9513b6ab | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = wanted_nodes
|
354 | 9513b6ab | Guido Trotter | elif self.recalculate_locks[locking.LEVEL_NODE] == constants.LOCKS_APPEND: |
355 | 9513b6ab | Guido Trotter | self.needed_locks[locking.LEVEL_NODE].extend(wanted_nodes)
|
356 | c4a2fee1 | Guido Trotter | |
357 | c4a2fee1 | Guido Trotter | del self.recalculate_locks[locking.LEVEL_NODE] |
358 | c4a2fee1 | Guido Trotter | |
359 | a8083063 | Iustin Pop | |
360 | fe267188 | Iustin Pop | class NoHooksLU(LogicalUnit): # pylint: disable-msg=W0223 |
361 | a8083063 | Iustin Pop | """Simple LU which runs no hooks.
|
362 | a8083063 | Iustin Pop |
|
363 | a8083063 | Iustin Pop | This LU is intended as a parent for other LogicalUnits which will
|
364 | a8083063 | Iustin Pop | run no hooks, in order to reduce duplicate code.
|
365 | a8083063 | Iustin Pop |
|
366 | a8083063 | Iustin Pop | """
|
367 | a8083063 | Iustin Pop | HPATH = None
|
368 | a8083063 | Iustin Pop | HTYPE = None
|
369 | a8083063 | Iustin Pop | |
370 | fc8a6b8f | Iustin Pop | def BuildHooksEnv(self): |
371 | fc8a6b8f | Iustin Pop | """Empty BuildHooksEnv for NoHooksLu.
|
372 | fc8a6b8f | Iustin Pop |
|
373 | fc8a6b8f | Iustin Pop | This just raises an error.
|
374 | fc8a6b8f | Iustin Pop |
|
375 | fc8a6b8f | Iustin Pop | """
|
376 | fc8a6b8f | Iustin Pop | assert False, "BuildHooksEnv called for NoHooksLUs" |
377 | fc8a6b8f | Iustin Pop | |
378 | a8083063 | Iustin Pop | |
379 | 9a6800e1 | Michael Hanselmann | class Tasklet: |
380 | 9a6800e1 | Michael Hanselmann | """Tasklet base class.
|
381 | 9a6800e1 | Michael Hanselmann |
|
382 | 9a6800e1 | Michael Hanselmann | Tasklets are subcomponents for LUs. LUs can consist entirely of tasklets or
|
383 | 9a6800e1 | Michael Hanselmann | they can mix legacy code with tasklets. Locking needs to be done in the LU,
|
384 | 9a6800e1 | Michael Hanselmann | tasklets know nothing about locks.
|
385 | 9a6800e1 | Michael Hanselmann |
|
386 | 9a6800e1 | Michael Hanselmann | Subclasses must follow these rules:
|
387 | 9a6800e1 | Michael Hanselmann | - Implement CheckPrereq
|
388 | 9a6800e1 | Michael Hanselmann | - Implement Exec
|
389 | 9a6800e1 | Michael Hanselmann |
|
390 | 9a6800e1 | Michael Hanselmann | """
|
391 | 464243a7 | Michael Hanselmann | def __init__(self, lu): |
392 | 464243a7 | Michael Hanselmann | self.lu = lu
|
393 | 464243a7 | Michael Hanselmann | |
394 | 464243a7 | Michael Hanselmann | # Shortcuts
|
395 | 464243a7 | Michael Hanselmann | self.cfg = lu.cfg
|
396 | 464243a7 | Michael Hanselmann | self.rpc = lu.rpc
|
397 | 464243a7 | Michael Hanselmann | |
398 | 9a6800e1 | Michael Hanselmann | def CheckPrereq(self): |
399 | 9a6800e1 | Michael Hanselmann | """Check prerequisites for this tasklets.
|
400 | 9a6800e1 | Michael Hanselmann |
|
401 | 9a6800e1 | Michael Hanselmann | This method should check whether the prerequisites for the execution of
|
402 | 9a6800e1 | Michael Hanselmann | this tasklet are fulfilled. It can do internode communication, but it
|
403 | 9a6800e1 | Michael Hanselmann | should be idempotent - no cluster or system changes are allowed.
|
404 | 9a6800e1 | Michael Hanselmann |
|
405 | 9a6800e1 | Michael Hanselmann | The method should raise errors.OpPrereqError in case something is not
|
406 | 9a6800e1 | Michael Hanselmann | fulfilled. Its return value is ignored.
|
407 | 9a6800e1 | Michael Hanselmann |
|
408 | 9a6800e1 | Michael Hanselmann | This method should also update all parameters to their canonical form if it
|
409 | 9a6800e1 | Michael Hanselmann | hasn't been done before.
|
410 | 9a6800e1 | Michael Hanselmann |
|
411 | 9a6800e1 | Michael Hanselmann | """
|
412 | 9a6800e1 | Michael Hanselmann | raise NotImplementedError |
413 | 9a6800e1 | Michael Hanselmann | |
414 | 9a6800e1 | Michael Hanselmann | def Exec(self, feedback_fn): |
415 | 9a6800e1 | Michael Hanselmann | """Execute the tasklet.
|
416 | 9a6800e1 | Michael Hanselmann |
|
417 | 9a6800e1 | Michael Hanselmann | This method should implement the actual work. It should raise
|
418 | 9a6800e1 | Michael Hanselmann | errors.OpExecError for failures that are somewhat dealt with in code, or
|
419 | 9a6800e1 | Michael Hanselmann | expected.
|
420 | 9a6800e1 | Michael Hanselmann |
|
421 | 9a6800e1 | Michael Hanselmann | """
|
422 | 9a6800e1 | Michael Hanselmann | raise NotImplementedError |
423 | 9a6800e1 | Michael Hanselmann | |
424 | 9a6800e1 | Michael Hanselmann | |
425 | dcb93971 | Michael Hanselmann | def _GetWantedNodes(lu, nodes): |
426 | a7ba5e53 | Iustin Pop | """Returns list of checked and expanded node names.
|
427 | 83120a01 | Michael Hanselmann |
|
428 | e4376078 | Iustin Pop | @type lu: L{LogicalUnit}
|
429 | e4376078 | Iustin Pop | @param lu: the logical unit on whose behalf we execute
|
430 | e4376078 | Iustin Pop | @type nodes: list
|
431 | e4376078 | Iustin Pop | @param nodes: list of node names or None for all nodes
|
432 | e4376078 | Iustin Pop | @rtype: list
|
433 | e4376078 | Iustin Pop | @return: the list of nodes, sorted
|
434 | 083a91c9 | Iustin Pop | @raise errors.ProgrammerError: if the nodes parameter is wrong type
|
435 | 83120a01 | Michael Hanselmann |
|
436 | 83120a01 | Michael Hanselmann | """
|
437 | 3312b702 | Iustin Pop | if not isinstance(nodes, list): |
438 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid argument type 'nodes'", |
439 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
440 | dcb93971 | Michael Hanselmann | |
441 | ea47808a | Guido Trotter | if not nodes: |
442 | ea47808a | Guido Trotter | raise errors.ProgrammerError("_GetWantedNodes should only be called with a" |
443 | ea47808a | Guido Trotter | " non-empty list of nodes whose name is to be expanded.")
|
444 | dcb93971 | Michael Hanselmann | |
445 | 61dabca4 | Iustin Pop | wanted = [_ExpandNodeName(lu.cfg, name) for name in nodes] |
446 | a7ba5e53 | Iustin Pop | return utils.NiceSort(wanted)
|
447 | 3312b702 | Iustin Pop | |
448 | 3312b702 | Iustin Pop | |
449 | 3312b702 | Iustin Pop | def _GetWantedInstances(lu, instances): |
450 | a7ba5e53 | Iustin Pop | """Returns list of checked and expanded instance names.
|
451 | 3312b702 | Iustin Pop |
|
452 | e4376078 | Iustin Pop | @type lu: L{LogicalUnit}
|
453 | e4376078 | Iustin Pop | @param lu: the logical unit on whose behalf we execute
|
454 | e4376078 | Iustin Pop | @type instances: list
|
455 | e4376078 | Iustin Pop | @param instances: list of instance names or None for all instances
|
456 | e4376078 | Iustin Pop | @rtype: list
|
457 | e4376078 | Iustin Pop | @return: the list of instances, sorted
|
458 | e4376078 | Iustin Pop | @raise errors.OpPrereqError: if the instances parameter is wrong type
|
459 | e4376078 | Iustin Pop | @raise errors.OpPrereqError: if any of the passed instances is not found
|
460 | 3312b702 | Iustin Pop |
|
461 | 3312b702 | Iustin Pop | """
|
462 | 3312b702 | Iustin Pop | if not isinstance(instances, list): |
463 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid argument type 'instances'", |
464 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
465 | 3312b702 | Iustin Pop | |
466 | 3312b702 | Iustin Pop | if instances:
|
467 | cf26a87a | Iustin Pop | wanted = [_ExpandInstanceName(lu.cfg, name) for name in instances] |
468 | 3312b702 | Iustin Pop | else:
|
469 | a7f5dc98 | Iustin Pop | wanted = utils.NiceSort(lu.cfg.GetInstanceList()) |
470 | a7f5dc98 | Iustin Pop | return wanted
|
471 | dcb93971 | Michael Hanselmann | |
472 | dcb93971 | Michael Hanselmann | |
473 | dcb93971 | Michael Hanselmann | def _CheckOutputFields(static, dynamic, selected): |
474 | 83120a01 | Michael Hanselmann | """Checks whether all selected fields are valid.
|
475 | 83120a01 | Michael Hanselmann |
|
476 | a2d2e1a7 | Iustin Pop | @type static: L{utils.FieldSet}
|
477 | 31bf511f | Iustin Pop | @param static: static fields set
|
478 | a2d2e1a7 | Iustin Pop | @type dynamic: L{utils.FieldSet}
|
479 | 31bf511f | Iustin Pop | @param dynamic: dynamic fields set
|
480 | 83120a01 | Michael Hanselmann |
|
481 | 83120a01 | Michael Hanselmann | """
|
482 | a2d2e1a7 | Iustin Pop | f = utils.FieldSet() |
483 | 31bf511f | Iustin Pop | f.Extend(static) |
484 | 31bf511f | Iustin Pop | f.Extend(dynamic) |
485 | dcb93971 | Michael Hanselmann | |
486 | 31bf511f | Iustin Pop | delta = f.NonMatching(selected) |
487 | 31bf511f | Iustin Pop | if delta:
|
488 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Unknown output fields selected: %s" |
489 | 5c983ee5 | Iustin Pop | % ",".join(delta), errors.ECODE_INVAL)
|
490 | dcb93971 | Michael Hanselmann | |
491 | dcb93971 | Michael Hanselmann | |
492 | a5961235 | Iustin Pop | def _CheckBooleanOpField(op, name): |
493 | a5961235 | Iustin Pop | """Validates boolean opcode parameters.
|
494 | a5961235 | Iustin Pop |
|
495 | a5961235 | Iustin Pop | This will ensure that an opcode parameter is either a boolean value,
|
496 | a5961235 | Iustin Pop | or None (but that it always exists).
|
497 | a5961235 | Iustin Pop |
|
498 | a5961235 | Iustin Pop | """
|
499 | a5961235 | Iustin Pop | val = getattr(op, name, None) |
500 | a5961235 | Iustin Pop | if not (val is None or isinstance(val, bool)): |
501 | a5961235 | Iustin Pop | raise errors.OpPrereqError("Invalid boolean parameter '%s' (%s)" % |
502 | 5c983ee5 | Iustin Pop | (name, str(val)), errors.ECODE_INVAL)
|
503 | a5961235 | Iustin Pop | setattr(op, name, val)
|
504 | a5961235 | Iustin Pop | |
505 | a5961235 | Iustin Pop | |
506 | 7736a5f2 | Iustin Pop | def _CheckGlobalHvParams(params): |
507 | 7736a5f2 | Iustin Pop | """Validates that given hypervisor params are not global ones.
|
508 | 7736a5f2 | Iustin Pop |
|
509 | 7736a5f2 | Iustin Pop | This will ensure that instances don't get customised versions of
|
510 | 7736a5f2 | Iustin Pop | global params.
|
511 | 7736a5f2 | Iustin Pop |
|
512 | 7736a5f2 | Iustin Pop | """
|
513 | 7736a5f2 | Iustin Pop | used_globals = constants.HVC_GLOBALS.intersection(params) |
514 | 7736a5f2 | Iustin Pop | if used_globals:
|
515 | 7736a5f2 | Iustin Pop | msg = ("The following hypervisor parameters are global and cannot"
|
516 | 7736a5f2 | Iustin Pop | " be customized at instance level, please modify them at"
|
517 | 1f864b60 | Iustin Pop | " cluster level: %s" % utils.CommaJoin(used_globals))
|
518 | 7736a5f2 | Iustin Pop | raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
519 | 7736a5f2 | Iustin Pop | |
520 | 7736a5f2 | Iustin Pop | |
521 | a5961235 | Iustin Pop | def _CheckNodeOnline(lu, node): |
522 | a5961235 | Iustin Pop | """Ensure that a given node is online.
|
523 | a5961235 | Iustin Pop |
|
524 | a5961235 | Iustin Pop | @param lu: the LU on behalf of which we make the check
|
525 | a5961235 | Iustin Pop | @param node: the node to check
|
526 | 733a2b6a | Iustin Pop | @raise errors.OpPrereqError: if the node is offline
|
527 | a5961235 | Iustin Pop |
|
528 | a5961235 | Iustin Pop | """
|
529 | a5961235 | Iustin Pop | if lu.cfg.GetNodeInfo(node).offline:
|
530 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Can't use offline node %s" % node, |
531 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
532 | a5961235 | Iustin Pop | |
533 | a5961235 | Iustin Pop | |
534 | 733a2b6a | Iustin Pop | def _CheckNodeNotDrained(lu, node): |
535 | 733a2b6a | Iustin Pop | """Ensure that a given node is not drained.
|
536 | 733a2b6a | Iustin Pop |
|
537 | 733a2b6a | Iustin Pop | @param lu: the LU on behalf of which we make the check
|
538 | 733a2b6a | Iustin Pop | @param node: the node to check
|
539 | 733a2b6a | Iustin Pop | @raise errors.OpPrereqError: if the node is drained
|
540 | 733a2b6a | Iustin Pop |
|
541 | 733a2b6a | Iustin Pop | """
|
542 | 733a2b6a | Iustin Pop | if lu.cfg.GetNodeInfo(node).drained:
|
543 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Can't use drained node %s" % node, |
544 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
545 | 733a2b6a | Iustin Pop | |
546 | 733a2b6a | Iustin Pop | |
547 | 231cd901 | Iustin Pop | def _CheckNodeHasOS(lu, node, os_name, force_variant): |
548 | 231cd901 | Iustin Pop | """Ensure that a node supports a given OS.
|
549 | 231cd901 | Iustin Pop |
|
550 | 231cd901 | Iustin Pop | @param lu: the LU on behalf of which we make the check
|
551 | 231cd901 | Iustin Pop | @param node: the node to check
|
552 | 231cd901 | Iustin Pop | @param os_name: the OS to query about
|
553 | 231cd901 | Iustin Pop | @param force_variant: whether to ignore variant errors
|
554 | 231cd901 | Iustin Pop | @raise errors.OpPrereqError: if the node is not supporting the OS
|
555 | 231cd901 | Iustin Pop |
|
556 | 231cd901 | Iustin Pop | """
|
557 | 231cd901 | Iustin Pop | result = lu.rpc.call_os_get(node, os_name) |
558 | 231cd901 | Iustin Pop | result.Raise("OS '%s' not in supported OS list for node %s" %
|
559 | 231cd901 | Iustin Pop | (os_name, node), |
560 | 231cd901 | Iustin Pop | prereq=True, ecode=errors.ECODE_INVAL)
|
561 | 231cd901 | Iustin Pop | if not force_variant: |
562 | 231cd901 | Iustin Pop | _CheckOSVariant(result.payload, os_name) |
563 | 231cd901 | Iustin Pop | |
564 | 231cd901 | Iustin Pop | |
565 | 0e3baaf3 | Iustin Pop | def _RequireFileStorage(): |
566 | 0e3baaf3 | Iustin Pop | """Checks that file storage is enabled.
|
567 | 0e3baaf3 | Iustin Pop |
|
568 | 0e3baaf3 | Iustin Pop | @raise errors.OpPrereqError: when file storage is disabled
|
569 | 0e3baaf3 | Iustin Pop |
|
570 | 0e3baaf3 | Iustin Pop | """
|
571 | 0e3baaf3 | Iustin Pop | if not constants.ENABLE_FILE_STORAGE: |
572 | 0e3baaf3 | Iustin Pop | raise errors.OpPrereqError("File storage disabled at configure time", |
573 | 0e3baaf3 | Iustin Pop | errors.ECODE_INVAL) |
574 | 0e3baaf3 | Iustin Pop | |
575 | 0e3baaf3 | Iustin Pop | |
576 | 5d55819e | Iustin Pop | def _CheckDiskTemplate(template): |
577 | 5d55819e | Iustin Pop | """Ensure a given disk template is valid.
|
578 | 5d55819e | Iustin Pop |
|
579 | 5d55819e | Iustin Pop | """
|
580 | 5d55819e | Iustin Pop | if template not in constants.DISK_TEMPLATES: |
581 | 5d55819e | Iustin Pop | msg = ("Invalid disk template name '%s', valid templates are: %s" %
|
582 | 5d55819e | Iustin Pop | (template, utils.CommaJoin(constants.DISK_TEMPLATES))) |
583 | 5d55819e | Iustin Pop | raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
584 | 0e3baaf3 | Iustin Pop | if template == constants.DT_FILE:
|
585 | 0e3baaf3 | Iustin Pop | _RequireFileStorage() |
586 | 0e3baaf3 | Iustin Pop | |
587 | 0e3baaf3 | Iustin Pop | |
588 | 0e3baaf3 | Iustin Pop | def _CheckStorageType(storage_type): |
589 | 0e3baaf3 | Iustin Pop | """Ensure a given storage type is valid.
|
590 | 0e3baaf3 | Iustin Pop |
|
591 | 0e3baaf3 | Iustin Pop | """
|
592 | 0e3baaf3 | Iustin Pop | if storage_type not in constants.VALID_STORAGE_TYPES: |
593 | 0e3baaf3 | Iustin Pop | raise errors.OpPrereqError("Unknown storage type: %s" % storage_type, |
594 | f276c4b5 | Iustin Pop | errors.ECODE_INVAL) |
595 | 0e3baaf3 | Iustin Pop | if storage_type == constants.ST_FILE:
|
596 | 0e3baaf3 | Iustin Pop | _RequireFileStorage() |
597 | 0e3baaf3 | Iustin Pop | |
598 | 5d55819e | Iustin Pop | |
599 | 5d55819e | Iustin Pop | |
600 | 31624382 | Iustin Pop | def _CheckInstanceDown(lu, instance, reason): |
601 | 31624382 | Iustin Pop | """Ensure that an instance is not running."""
|
602 | 31624382 | Iustin Pop | if instance.admin_up:
|
603 | 31624382 | Iustin Pop | raise errors.OpPrereqError("Instance %s is marked to be up, %s" % |
604 | 31624382 | Iustin Pop | (instance.name, reason), errors.ECODE_STATE) |
605 | 31624382 | Iustin Pop | |
606 | 31624382 | Iustin Pop | pnode = instance.primary_node |
607 | 31624382 | Iustin Pop | ins_l = lu.rpc.call_instance_list([pnode], [instance.hypervisor])[pnode] |
608 | 31624382 | Iustin Pop | ins_l.Raise("Can't contact node %s for instance information" % pnode,
|
609 | 31624382 | Iustin Pop | prereq=True, ecode=errors.ECODE_ENVIRON)
|
610 | 31624382 | Iustin Pop | |
611 | 31624382 | Iustin Pop | if instance.name in ins_l.payload: |
612 | 31624382 | Iustin Pop | raise errors.OpPrereqError("Instance %s is running, %s" % |
613 | 31624382 | Iustin Pop | (instance.name, reason), errors.ECODE_STATE) |
614 | 31624382 | Iustin Pop | |
615 | 31624382 | Iustin Pop | |
616 | cf26a87a | Iustin Pop | def _ExpandItemName(fn, name, kind): |
617 | cf26a87a | Iustin Pop | """Expand an item name.
|
618 | cf26a87a | Iustin Pop |
|
619 | cf26a87a | Iustin Pop | @param fn: the function to use for expansion
|
620 | cf26a87a | Iustin Pop | @param name: requested item name
|
621 | cf26a87a | Iustin Pop | @param kind: text description ('Node' or 'Instance')
|
622 | cf26a87a | Iustin Pop | @return: the resolved (full) name
|
623 | cf26a87a | Iustin Pop | @raise errors.OpPrereqError: if the item is not found
|
624 | cf26a87a | Iustin Pop |
|
625 | cf26a87a | Iustin Pop | """
|
626 | cf26a87a | Iustin Pop | full_name = fn(name) |
627 | cf26a87a | Iustin Pop | if full_name is None: |
628 | cf26a87a | Iustin Pop | raise errors.OpPrereqError("%s '%s' not known" % (kind, name), |
629 | cf26a87a | Iustin Pop | errors.ECODE_NOENT) |
630 | cf26a87a | Iustin Pop | return full_name
|
631 | cf26a87a | Iustin Pop | |
632 | cf26a87a | Iustin Pop | |
633 | cf26a87a | Iustin Pop | def _ExpandNodeName(cfg, name): |
634 | cf26a87a | Iustin Pop | """Wrapper over L{_ExpandItemName} for nodes."""
|
635 | cf26a87a | Iustin Pop | return _ExpandItemName(cfg.ExpandNodeName, name, "Node") |
636 | cf26a87a | Iustin Pop | |
637 | cf26a87a | Iustin Pop | |
638 | cf26a87a | Iustin Pop | def _ExpandInstanceName(cfg, name): |
639 | cf26a87a | Iustin Pop | """Wrapper over L{_ExpandItemName} for instance."""
|
640 | cf26a87a | Iustin Pop | return _ExpandItemName(cfg.ExpandInstanceName, name, "Instance") |
641 | cf26a87a | Iustin Pop | |
642 | cf26a87a | Iustin Pop | |
643 | ecb215b5 | Michael Hanselmann | def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, |
644 | 67fc3042 | Iustin Pop | memory, vcpus, nics, disk_template, disks, |
645 | 7c4d6c7b | Michael Hanselmann | bep, hvp, hypervisor_name): |
646 | e4376078 | Iustin Pop | """Builds instance related env variables for hooks
|
647 | e4376078 | Iustin Pop |
|
648 | e4376078 | Iustin Pop | This builds the hook environment from individual variables.
|
649 | e4376078 | Iustin Pop |
|
650 | e4376078 | Iustin Pop | @type name: string
|
651 | e4376078 | Iustin Pop | @param name: the name of the instance
|
652 | e4376078 | Iustin Pop | @type primary_node: string
|
653 | e4376078 | Iustin Pop | @param primary_node: the name of the instance's primary node
|
654 | e4376078 | Iustin Pop | @type secondary_nodes: list
|
655 | e4376078 | Iustin Pop | @param secondary_nodes: list of secondary nodes as strings
|
656 | e4376078 | Iustin Pop | @type os_type: string
|
657 | e4376078 | Iustin Pop | @param os_type: the name of the instance's OS
|
658 | 0d68c45d | Iustin Pop | @type status: boolean
|
659 | 0d68c45d | Iustin Pop | @param status: the should_run status of the instance
|
660 | e4376078 | Iustin Pop | @type memory: string
|
661 | e4376078 | Iustin Pop | @param memory: the memory size of the instance
|
662 | e4376078 | Iustin Pop | @type vcpus: string
|
663 | e4376078 | Iustin Pop | @param vcpus: the count of VCPUs the instance has
|
664 | e4376078 | Iustin Pop | @type nics: list
|
665 | 5e3d3eb3 | Guido Trotter | @param nics: list of tuples (ip, mac, mode, link) representing
|
666 | 5e3d3eb3 | Guido Trotter | the NICs the instance has
|
667 | 2c2690c9 | Iustin Pop | @type disk_template: string
|
668 | 5bbd3f7f | Michael Hanselmann | @param disk_template: the disk template of the instance
|
669 | 2c2690c9 | Iustin Pop | @type disks: list
|
670 | 2c2690c9 | Iustin Pop | @param disks: the list of (size, mode) pairs
|
671 | 67fc3042 | Iustin Pop | @type bep: dict
|
672 | 67fc3042 | Iustin Pop | @param bep: the backend parameters for the instance
|
673 | 67fc3042 | Iustin Pop | @type hvp: dict
|
674 | 67fc3042 | Iustin Pop | @param hvp: the hypervisor parameters for the instance
|
675 | 7c4d6c7b | Michael Hanselmann | @type hypervisor_name: string
|
676 | 7c4d6c7b | Michael Hanselmann | @param hypervisor_name: the hypervisor for the instance
|
677 | e4376078 | Iustin Pop | @rtype: dict
|
678 | e4376078 | Iustin Pop | @return: the hook environment for this instance
|
679 | ecb215b5 | Michael Hanselmann |
|
680 | 396e1b78 | Michael Hanselmann | """
|
681 | 0d68c45d | Iustin Pop | if status:
|
682 | 0d68c45d | Iustin Pop | str_status = "up"
|
683 | 0d68c45d | Iustin Pop | else:
|
684 | 0d68c45d | Iustin Pop | str_status = "down"
|
685 | 396e1b78 | Michael Hanselmann | env = { |
686 | 0e137c28 | Iustin Pop | "OP_TARGET": name,
|
687 | 396e1b78 | Michael Hanselmann | "INSTANCE_NAME": name,
|
688 | 396e1b78 | Michael Hanselmann | "INSTANCE_PRIMARY": primary_node,
|
689 | 396e1b78 | Michael Hanselmann | "INSTANCE_SECONDARIES": " ".join(secondary_nodes), |
690 | ecb215b5 | Michael Hanselmann | "INSTANCE_OS_TYPE": os_type,
|
691 | 0d68c45d | Iustin Pop | "INSTANCE_STATUS": str_status,
|
692 | 396e1b78 | Michael Hanselmann | "INSTANCE_MEMORY": memory,
|
693 | 396e1b78 | Michael Hanselmann | "INSTANCE_VCPUS": vcpus,
|
694 | 2c2690c9 | Iustin Pop | "INSTANCE_DISK_TEMPLATE": disk_template,
|
695 | 7c4d6c7b | Michael Hanselmann | "INSTANCE_HYPERVISOR": hypervisor_name,
|
696 | 396e1b78 | Michael Hanselmann | } |
697 | 396e1b78 | Michael Hanselmann | |
698 | 396e1b78 | Michael Hanselmann | if nics:
|
699 | 396e1b78 | Michael Hanselmann | nic_count = len(nics)
|
700 | 62f0dd02 | Guido Trotter | for idx, (ip, mac, mode, link) in enumerate(nics): |
701 | 396e1b78 | Michael Hanselmann | if ip is None: |
702 | 396e1b78 | Michael Hanselmann | ip = ""
|
703 | 396e1b78 | Michael Hanselmann | env["INSTANCE_NIC%d_IP" % idx] = ip
|
704 | 2c2690c9 | Iustin Pop | env["INSTANCE_NIC%d_MAC" % idx] = mac
|
705 | 62f0dd02 | Guido Trotter | env["INSTANCE_NIC%d_MODE" % idx] = mode
|
706 | 62f0dd02 | Guido Trotter | env["INSTANCE_NIC%d_LINK" % idx] = link
|
707 | 62f0dd02 | Guido Trotter | if mode == constants.NIC_MODE_BRIDGED:
|
708 | 62f0dd02 | Guido Trotter | env["INSTANCE_NIC%d_BRIDGE" % idx] = link
|
709 | 396e1b78 | Michael Hanselmann | else:
|
710 | 396e1b78 | Michael Hanselmann | nic_count = 0
|
711 | 396e1b78 | Michael Hanselmann | |
712 | 396e1b78 | Michael Hanselmann | env["INSTANCE_NIC_COUNT"] = nic_count
|
713 | 396e1b78 | Michael Hanselmann | |
714 | 2c2690c9 | Iustin Pop | if disks:
|
715 | 2c2690c9 | Iustin Pop | disk_count = len(disks)
|
716 | 2c2690c9 | Iustin Pop | for idx, (size, mode) in enumerate(disks): |
717 | 2c2690c9 | Iustin Pop | env["INSTANCE_DISK%d_SIZE" % idx] = size
|
718 | 2c2690c9 | Iustin Pop | env["INSTANCE_DISK%d_MODE" % idx] = mode
|
719 | 2c2690c9 | Iustin Pop | else:
|
720 | 2c2690c9 | Iustin Pop | disk_count = 0
|
721 | 2c2690c9 | Iustin Pop | |
722 | 2c2690c9 | Iustin Pop | env["INSTANCE_DISK_COUNT"] = disk_count
|
723 | 2c2690c9 | Iustin Pop | |
724 | 67fc3042 | Iustin Pop | for source, kind in [(bep, "BE"), (hvp, "HV")]: |
725 | 67fc3042 | Iustin Pop | for key, value in source.items(): |
726 | 67fc3042 | Iustin Pop | env["INSTANCE_%s_%s" % (kind, key)] = value
|
727 | 67fc3042 | Iustin Pop | |
728 | 396e1b78 | Michael Hanselmann | return env
|
729 | 396e1b78 | Michael Hanselmann | |
730 | 96acbc09 | Michael Hanselmann | |
731 | f9b10246 | Guido Trotter | def _NICListToTuple(lu, nics): |
732 | 62f0dd02 | Guido Trotter | """Build a list of nic information tuples.
|
733 | 62f0dd02 | Guido Trotter |
|
734 | f9b10246 | Guido Trotter | This list is suitable to be passed to _BuildInstanceHookEnv or as a return
|
735 | f9b10246 | Guido Trotter | value in LUQueryInstanceData.
|
736 | 62f0dd02 | Guido Trotter |
|
737 | 62f0dd02 | Guido Trotter | @type lu: L{LogicalUnit}
|
738 | 62f0dd02 | Guido Trotter | @param lu: the logical unit on whose behalf we execute
|
739 | 62f0dd02 | Guido Trotter | @type nics: list of L{objects.NIC}
|
740 | 62f0dd02 | Guido Trotter | @param nics: list of nics to convert to hooks tuples
|
741 | 62f0dd02 | Guido Trotter |
|
742 | 62f0dd02 | Guido Trotter | """
|
743 | 62f0dd02 | Guido Trotter | hooks_nics = [] |
744 | 62f0dd02 | Guido Trotter | c_nicparams = lu.cfg.GetClusterInfo().nicparams[constants.PP_DEFAULT] |
745 | 62f0dd02 | Guido Trotter | for nic in nics: |
746 | 62f0dd02 | Guido Trotter | ip = nic.ip |
747 | 62f0dd02 | Guido Trotter | mac = nic.mac |
748 | 62f0dd02 | Guido Trotter | filled_params = objects.FillDict(c_nicparams, nic.nicparams) |
749 | 62f0dd02 | Guido Trotter | mode = filled_params[constants.NIC_MODE] |
750 | 62f0dd02 | Guido Trotter | link = filled_params[constants.NIC_LINK] |
751 | 62f0dd02 | Guido Trotter | hooks_nics.append((ip, mac, mode, link)) |
752 | 62f0dd02 | Guido Trotter | return hooks_nics
|
753 | 396e1b78 | Michael Hanselmann | |
754 | 96acbc09 | Michael Hanselmann | |
755 | 338e51e8 | Iustin Pop | def _BuildInstanceHookEnvByObject(lu, instance, override=None): |
756 | ecb215b5 | Michael Hanselmann | """Builds instance related env variables for hooks from an object.
|
757 | ecb215b5 | Michael Hanselmann |
|
758 | e4376078 | Iustin Pop | @type lu: L{LogicalUnit}
|
759 | e4376078 | Iustin Pop | @param lu: the logical unit on whose behalf we execute
|
760 | e4376078 | Iustin Pop | @type instance: L{objects.Instance}
|
761 | e4376078 | Iustin Pop | @param instance: the instance for which we should build the
|
762 | e4376078 | Iustin Pop | environment
|
763 | e4376078 | Iustin Pop | @type override: dict
|
764 | e4376078 | Iustin Pop | @param override: dictionary with key/values that will override
|
765 | e4376078 | Iustin Pop | our values
|
766 | e4376078 | Iustin Pop | @rtype: dict
|
767 | e4376078 | Iustin Pop | @return: the hook environment dictionary
|
768 | e4376078 | Iustin Pop |
|
769 | ecb215b5 | Michael Hanselmann | """
|
770 | 67fc3042 | Iustin Pop | cluster = lu.cfg.GetClusterInfo() |
771 | 67fc3042 | Iustin Pop | bep = cluster.FillBE(instance) |
772 | 67fc3042 | Iustin Pop | hvp = cluster.FillHV(instance) |
773 | 396e1b78 | Michael Hanselmann | args = { |
774 | 396e1b78 | Michael Hanselmann | 'name': instance.name,
|
775 | 396e1b78 | Michael Hanselmann | 'primary_node': instance.primary_node,
|
776 | 396e1b78 | Michael Hanselmann | 'secondary_nodes': instance.secondary_nodes,
|
777 | ecb215b5 | Michael Hanselmann | 'os_type': instance.os,
|
778 | 0d68c45d | Iustin Pop | 'status': instance.admin_up,
|
779 | 338e51e8 | Iustin Pop | 'memory': bep[constants.BE_MEMORY],
|
780 | 338e51e8 | Iustin Pop | 'vcpus': bep[constants.BE_VCPUS],
|
781 | f9b10246 | Guido Trotter | 'nics': _NICListToTuple(lu, instance.nics),
|
782 | 2c2690c9 | Iustin Pop | 'disk_template': instance.disk_template,
|
783 | 2c2690c9 | Iustin Pop | 'disks': [(disk.size, disk.mode) for disk in instance.disks], |
784 | 67fc3042 | Iustin Pop | 'bep': bep,
|
785 | 67fc3042 | Iustin Pop | 'hvp': hvp,
|
786 | b0c63e2b | Iustin Pop | 'hypervisor_name': instance.hypervisor,
|
787 | 396e1b78 | Michael Hanselmann | } |
788 | 396e1b78 | Michael Hanselmann | if override:
|
789 | 396e1b78 | Michael Hanselmann | args.update(override) |
790 | 7260cfbe | Iustin Pop | return _BuildInstanceHookEnv(**args) # pylint: disable-msg=W0142 |
791 | 396e1b78 | Michael Hanselmann | |
792 | 396e1b78 | Michael Hanselmann | |
793 | 44485f49 | Guido Trotter | def _AdjustCandidatePool(lu, exceptions): |
794 | ec0292f1 | Iustin Pop | """Adjust the candidate pool after node operations.
|
795 | ec0292f1 | Iustin Pop |
|
796 | ec0292f1 | Iustin Pop | """
|
797 | 44485f49 | Guido Trotter | mod_list = lu.cfg.MaintainCandidatePool(exceptions) |
798 | ec0292f1 | Iustin Pop | if mod_list:
|
799 | ec0292f1 | Iustin Pop | lu.LogInfo("Promoted nodes to master candidate role: %s",
|
800 | 1f864b60 | Iustin Pop | utils.CommaJoin(node.name for node in mod_list)) |
801 | ec0292f1 | Iustin Pop | for name in mod_list: |
802 | ec0292f1 | Iustin Pop | lu.context.ReaddNode(name) |
803 | 44485f49 | Guido Trotter | mc_now, mc_max, _ = lu.cfg.GetMasterCandidateStats(exceptions) |
804 | ec0292f1 | Iustin Pop | if mc_now > mc_max:
|
805 | ec0292f1 | Iustin Pop | lu.LogInfo("Note: more nodes are candidates (%d) than desired (%d)" %
|
806 | ec0292f1 | Iustin Pop | (mc_now, mc_max)) |
807 | ec0292f1 | Iustin Pop | |
808 | ec0292f1 | Iustin Pop | |
809 | 6d7e1f20 | Guido Trotter | def _DecideSelfPromotion(lu, exceptions=None): |
810 | 6d7e1f20 | Guido Trotter | """Decide whether I should promote myself as a master candidate.
|
811 | 6d7e1f20 | Guido Trotter |
|
812 | 6d7e1f20 | Guido Trotter | """
|
813 | 6d7e1f20 | Guido Trotter | cp_size = lu.cfg.GetClusterInfo().candidate_pool_size |
814 | 6d7e1f20 | Guido Trotter | mc_now, mc_should, _ = lu.cfg.GetMasterCandidateStats(exceptions) |
815 | 6d7e1f20 | Guido Trotter | # the new node will increase mc_max with one, so:
|
816 | 6d7e1f20 | Guido Trotter | mc_should = min(mc_should + 1, cp_size) |
817 | 6d7e1f20 | Guido Trotter | return mc_now < mc_should
|
818 | 6d7e1f20 | Guido Trotter | |
819 | 6d7e1f20 | Guido Trotter | |
820 | b165e77e | Guido Trotter | def _CheckNicsBridgesExist(lu, target_nics, target_node, |
821 | b165e77e | Guido Trotter | profile=constants.PP_DEFAULT): |
822 | b165e77e | Guido Trotter | """Check that the brigdes needed by a list of nics exist.
|
823 | b165e77e | Guido Trotter |
|
824 | b165e77e | Guido Trotter | """
|
825 | b165e77e | Guido Trotter | c_nicparams = lu.cfg.GetClusterInfo().nicparams[profile] |
826 | b165e77e | Guido Trotter | paramslist = [objects.FillDict(c_nicparams, nic.nicparams) |
827 | b165e77e | Guido Trotter | for nic in target_nics] |
828 | b165e77e | Guido Trotter | brlist = [params[constants.NIC_LINK] for params in paramslist |
829 | b165e77e | Guido Trotter | if params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED]
|
830 | b165e77e | Guido Trotter | if brlist:
|
831 | b165e77e | Guido Trotter | result = lu.rpc.call_bridges_exist(target_node, brlist) |
832 | 4c4e4e1e | Iustin Pop | result.Raise("Error checking bridges on destination node '%s'" %
|
833 | 045dd6d9 | Iustin Pop | target_node, prereq=True, ecode=errors.ECODE_ENVIRON)
|
834 | b165e77e | Guido Trotter | |
835 | b165e77e | Guido Trotter | |
836 | b165e77e | Guido Trotter | def _CheckInstanceBridgesExist(lu, instance, node=None): |
837 | bf6929a2 | Alexander Schreiber | """Check that the brigdes needed by an instance exist.
|
838 | bf6929a2 | Alexander Schreiber |
|
839 | bf6929a2 | Alexander Schreiber | """
|
840 | b165e77e | Guido Trotter | if node is None: |
841 | 29921401 | Iustin Pop | node = instance.primary_node |
842 | b165e77e | Guido Trotter | _CheckNicsBridgesExist(lu, instance.nics, node) |
843 | bf6929a2 | Alexander Schreiber | |
844 | bf6929a2 | Alexander Schreiber | |
845 | c6f1af07 | Iustin Pop | def _CheckOSVariant(os_obj, name): |
846 | f2c05717 | Guido Trotter | """Check whether an OS name conforms to the os variants specification.
|
847 | f2c05717 | Guido Trotter |
|
848 | c6f1af07 | Iustin Pop | @type os_obj: L{objects.OS}
|
849 | c6f1af07 | Iustin Pop | @param os_obj: OS object to check
|
850 | f2c05717 | Guido Trotter | @type name: string
|
851 | f2c05717 | Guido Trotter | @param name: OS name passed by the user, to check for validity
|
852 | f2c05717 | Guido Trotter |
|
853 | f2c05717 | Guido Trotter | """
|
854 | c6f1af07 | Iustin Pop | if not os_obj.supported_variants: |
855 | f2c05717 | Guido Trotter | return
|
856 | f2c05717 | Guido Trotter | try:
|
857 | f2c05717 | Guido Trotter | variant = name.split("+", 1)[1] |
858 | f2c05717 | Guido Trotter | except IndexError: |
859 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("OS name must include a variant", |
860 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
861 | f2c05717 | Guido Trotter | |
862 | c6f1af07 | Iustin Pop | if variant not in os_obj.supported_variants: |
863 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Unsupported OS variant", errors.ECODE_INVAL) |
864 | f2c05717 | Guido Trotter | |
865 | f2c05717 | Guido Trotter | |
866 | 5ba9701d | Michael Hanselmann | def _GetNodeInstancesInner(cfg, fn): |
867 | 5ba9701d | Michael Hanselmann | return [i for i in cfg.GetAllInstancesInfo().values() if fn(i)] |
868 | 5ba9701d | Michael Hanselmann | |
869 | 5ba9701d | Michael Hanselmann | |
870 | e9721add | Michael Hanselmann | def _GetNodeInstances(cfg, node_name): |
871 | e9721add | Michael Hanselmann | """Returns a list of all primary and secondary instances on a node.
|
872 | e9721add | Michael Hanselmann |
|
873 | e9721add | Michael Hanselmann | """
|
874 | e9721add | Michael Hanselmann | |
875 | e9721add | Michael Hanselmann | return _GetNodeInstancesInner(cfg, lambda inst: node_name in inst.all_nodes) |
876 | e9721add | Michael Hanselmann | |
877 | e9721add | Michael Hanselmann | |
878 | 80cb875c | Michael Hanselmann | def _GetNodePrimaryInstances(cfg, node_name): |
879 | 80cb875c | Michael Hanselmann | """Returns primary instances on a node.
|
880 | 80cb875c | Michael Hanselmann |
|
881 | 80cb875c | Michael Hanselmann | """
|
882 | 5ba9701d | Michael Hanselmann | return _GetNodeInstancesInner(cfg,
|
883 | 5ba9701d | Michael Hanselmann | lambda inst: node_name == inst.primary_node)
|
884 | 80cb875c | Michael Hanselmann | |
885 | 80cb875c | Michael Hanselmann | |
886 | 692738fc | Michael Hanselmann | def _GetNodeSecondaryInstances(cfg, node_name): |
887 | 692738fc | Michael Hanselmann | """Returns secondary instances on a node.
|
888 | 692738fc | Michael Hanselmann |
|
889 | 692738fc | Michael Hanselmann | """
|
890 | 5ba9701d | Michael Hanselmann | return _GetNodeInstancesInner(cfg,
|
891 | 5ba9701d | Michael Hanselmann | lambda inst: node_name in inst.secondary_nodes) |
892 | 692738fc | Michael Hanselmann | |
893 | 692738fc | Michael Hanselmann | |
894 | efb8da02 | Michael Hanselmann | def _GetStorageTypeArgs(cfg, storage_type): |
895 | efb8da02 | Michael Hanselmann | """Returns the arguments for a storage type.
|
896 | efb8da02 | Michael Hanselmann |
|
897 | efb8da02 | Michael Hanselmann | """
|
898 | efb8da02 | Michael Hanselmann | # Special case for file storage
|
899 | efb8da02 | Michael Hanselmann | if storage_type == constants.ST_FILE:
|
900 | a4d138b7 | Michael Hanselmann | # storage.FileStorage wants a list of storage directories
|
901 | a4d138b7 | Michael Hanselmann | return [[cfg.GetFileStorageDir()]]
|
902 | efb8da02 | Michael Hanselmann | |
903 | efb8da02 | Michael Hanselmann | return []
|
904 | efb8da02 | Michael Hanselmann | |
905 | efb8da02 | Michael Hanselmann | |
906 | 2d9005d8 | Michael Hanselmann | def _FindFaultyInstanceDisks(cfg, rpc, instance, node_name, prereq): |
907 | 2d9005d8 | Michael Hanselmann | faulty = [] |
908 | 2d9005d8 | Michael Hanselmann | |
909 | 2d9005d8 | Michael Hanselmann | for dev in instance.disks: |
910 | 2d9005d8 | Michael Hanselmann | cfg.SetDiskID(dev, node_name) |
911 | 2d9005d8 | Michael Hanselmann | |
912 | 2d9005d8 | Michael Hanselmann | result = rpc.call_blockdev_getmirrorstatus(node_name, instance.disks) |
913 | 2d9005d8 | Michael Hanselmann | result.Raise("Failed to get disk status from node %s" % node_name,
|
914 | 045dd6d9 | Iustin Pop | prereq=prereq, ecode=errors.ECODE_ENVIRON) |
915 | 2d9005d8 | Michael Hanselmann | |
916 | 2d9005d8 | Michael Hanselmann | for idx, bdev_status in enumerate(result.payload): |
917 | 2d9005d8 | Michael Hanselmann | if bdev_status and bdev_status.ldisk_status == constants.LDS_FAULTY: |
918 | 2d9005d8 | Michael Hanselmann | faulty.append(idx) |
919 | 2d9005d8 | Michael Hanselmann | |
920 | 2d9005d8 | Michael Hanselmann | return faulty
|
921 | 2d9005d8 | Michael Hanselmann | |
922 | 2d9005d8 | Michael Hanselmann | |
923 | b98bf262 | Michael Hanselmann | def _FormatTimestamp(secs): |
924 | b98bf262 | Michael Hanselmann | """Formats a Unix timestamp with the local timezone.
|
925 | b98bf262 | Michael Hanselmann |
|
926 | b98bf262 | Michael Hanselmann | """
|
927 | b98bf262 | Michael Hanselmann | return time.strftime("%F %T %Z", time.gmtime(secs)) |
928 | b98bf262 | Michael Hanselmann | |
929 | b98bf262 | Michael Hanselmann | |
930 | b5f5fae9 | Luca Bigliardi | class LUPostInitCluster(LogicalUnit): |
931 | b5f5fae9 | Luca Bigliardi | """Logical unit for running hooks after cluster initialization.
|
932 | b5f5fae9 | Luca Bigliardi |
|
933 | b5f5fae9 | Luca Bigliardi | """
|
934 | b5f5fae9 | Luca Bigliardi | HPATH = "cluster-init"
|
935 | b5f5fae9 | Luca Bigliardi | HTYPE = constants.HTYPE_CLUSTER |
936 | b5f5fae9 | Luca Bigliardi | _OP_REQP = [] |
937 | b5f5fae9 | Luca Bigliardi | |
938 | b5f5fae9 | Luca Bigliardi | def BuildHooksEnv(self): |
939 | b5f5fae9 | Luca Bigliardi | """Build hooks env.
|
940 | b5f5fae9 | Luca Bigliardi |
|
941 | b5f5fae9 | Luca Bigliardi | """
|
942 | b5f5fae9 | Luca Bigliardi | env = {"OP_TARGET": self.cfg.GetClusterName()} |
943 | b5f5fae9 | Luca Bigliardi | mn = self.cfg.GetMasterNode()
|
944 | b5f5fae9 | Luca Bigliardi | return env, [], [mn]
|
945 | b5f5fae9 | Luca Bigliardi | |
946 | b5f5fae9 | Luca Bigliardi | def CheckPrereq(self): |
947 | b5f5fae9 | Luca Bigliardi | """No prerequisites to check.
|
948 | b5f5fae9 | Luca Bigliardi |
|
949 | b5f5fae9 | Luca Bigliardi | """
|
950 | b5f5fae9 | Luca Bigliardi | return True |
951 | b5f5fae9 | Luca Bigliardi | |
952 | b5f5fae9 | Luca Bigliardi | def Exec(self, feedback_fn): |
953 | b5f5fae9 | Luca Bigliardi | """Nothing to do.
|
954 | b5f5fae9 | Luca Bigliardi |
|
955 | b5f5fae9 | Luca Bigliardi | """
|
956 | b5f5fae9 | Luca Bigliardi | return True |
957 | b5f5fae9 | Luca Bigliardi | |
958 | b5f5fae9 | Luca Bigliardi | |
959 | b2c750a4 | Luca Bigliardi | class LUDestroyCluster(LogicalUnit): |
960 | a8083063 | Iustin Pop | """Logical unit for destroying the cluster.
|
961 | a8083063 | Iustin Pop |
|
962 | a8083063 | Iustin Pop | """
|
963 | b2c750a4 | Luca Bigliardi | HPATH = "cluster-destroy"
|
964 | b2c750a4 | Luca Bigliardi | HTYPE = constants.HTYPE_CLUSTER |
965 | a8083063 | Iustin Pop | _OP_REQP = [] |
966 | a8083063 | Iustin Pop | |
967 | b2c750a4 | Luca Bigliardi | def BuildHooksEnv(self): |
968 | b2c750a4 | Luca Bigliardi | """Build hooks env.
|
969 | b2c750a4 | Luca Bigliardi |
|
970 | b2c750a4 | Luca Bigliardi | """
|
971 | b2c750a4 | Luca Bigliardi | env = {"OP_TARGET": self.cfg.GetClusterName()} |
972 | b2c750a4 | Luca Bigliardi | return env, [], []
|
973 | b2c750a4 | Luca Bigliardi | |
974 | a8083063 | Iustin Pop | def CheckPrereq(self): |
975 | a8083063 | Iustin Pop | """Check prerequisites.
|
976 | a8083063 | Iustin Pop |
|
977 | a8083063 | Iustin Pop | This checks whether the cluster is empty.
|
978 | a8083063 | Iustin Pop |
|
979 | 5bbd3f7f | Michael Hanselmann | Any errors are signaled by raising errors.OpPrereqError.
|
980 | a8083063 | Iustin Pop |
|
981 | a8083063 | Iustin Pop | """
|
982 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
983 | a8083063 | Iustin Pop | |
984 | a8083063 | Iustin Pop | nodelist = self.cfg.GetNodeList()
|
985 | db915bd1 | Michael Hanselmann | if len(nodelist) != 1 or nodelist[0] != master: |
986 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("There are still %d node(s) in" |
987 | 5c983ee5 | Iustin Pop | " this cluster." % (len(nodelist) - 1), |
988 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
989 | db915bd1 | Michael Hanselmann | instancelist = self.cfg.GetInstanceList()
|
990 | db915bd1 | Michael Hanselmann | if instancelist:
|
991 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("There are still %d instance(s) in" |
992 | 5c983ee5 | Iustin Pop | " this cluster." % len(instancelist), |
993 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
994 | a8083063 | Iustin Pop | |
995 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
996 | a8083063 | Iustin Pop | """Destroys the cluster.
|
997 | a8083063 | Iustin Pop |
|
998 | a8083063 | Iustin Pop | """
|
999 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
1000 | b989b9d9 | Ken Wehr | modify_ssh_setup = self.cfg.GetClusterInfo().modify_ssh_setup
|
1001 | 3141ad3b | Luca Bigliardi | |
1002 | 3141ad3b | Luca Bigliardi | # Run post hooks on master node before it's removed
|
1003 | 3141ad3b | Luca Bigliardi | hm = self.proc.hmclass(self.rpc.call_hooks_runner, self) |
1004 | 3141ad3b | Luca Bigliardi | try:
|
1005 | 3141ad3b | Luca Bigliardi | hm.RunPhase(constants.HOOKS_PHASE_POST, [master]) |
1006 | 3141ad3b | Luca Bigliardi | except:
|
1007 | 7260cfbe | Iustin Pop | # pylint: disable-msg=W0702
|
1008 | 3141ad3b | Luca Bigliardi | self.LogWarning("Errors occurred running hooks on %s" % master) |
1009 | 3141ad3b | Luca Bigliardi | |
1010 | 781de953 | Iustin Pop | result = self.rpc.call_node_stop_master(master, False) |
1011 | 4c4e4e1e | Iustin Pop | result.Raise("Could not disable the master role")
|
1012 | b989b9d9 | Ken Wehr | |
1013 | b989b9d9 | Ken Wehr | if modify_ssh_setup:
|
1014 | b989b9d9 | Ken Wehr | priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS) |
1015 | b989b9d9 | Ken Wehr | utils.CreateBackup(priv_key) |
1016 | b989b9d9 | Ken Wehr | utils.CreateBackup(pub_key) |
1017 | b989b9d9 | Ken Wehr | |
1018 | 140aa4a8 | Iustin Pop | return master
|
1019 | a8083063 | Iustin Pop | |
1020 | a8083063 | Iustin Pop | |
1021 | b98bf262 | Michael Hanselmann | def _VerifyCertificateInner(filename, expired, not_before, not_after, now, |
1022 | b98bf262 | Michael Hanselmann | warn_days=constants.SSL_CERT_EXPIRATION_WARN, |
1023 | b98bf262 | Michael Hanselmann | error_days=constants.SSL_CERT_EXPIRATION_ERROR): |
1024 | b98bf262 | Michael Hanselmann | """Verifies certificate details for LUVerifyCluster.
|
1025 | b98bf262 | Michael Hanselmann |
|
1026 | b98bf262 | Michael Hanselmann | """
|
1027 | b98bf262 | Michael Hanselmann | if expired:
|
1028 | b98bf262 | Michael Hanselmann | msg = "Certificate %s is expired" % filename
|
1029 | b98bf262 | Michael Hanselmann | |
1030 | b98bf262 | Michael Hanselmann | if not_before is not None and not_after is not None: |
1031 | b98bf262 | Michael Hanselmann | msg += (" (valid from %s to %s)" %
|
1032 | b98bf262 | Michael Hanselmann | (_FormatTimestamp(not_before), |
1033 | b98bf262 | Michael Hanselmann | _FormatTimestamp(not_after))) |
1034 | b98bf262 | Michael Hanselmann | elif not_before is not None: |
1035 | b98bf262 | Michael Hanselmann | msg += " (valid from %s)" % _FormatTimestamp(not_before)
|
1036 | b98bf262 | Michael Hanselmann | elif not_after is not None: |
1037 | b98bf262 | Michael Hanselmann | msg += " (valid until %s)" % _FormatTimestamp(not_after)
|
1038 | b98bf262 | Michael Hanselmann | |
1039 | b98bf262 | Michael Hanselmann | return (LUVerifyCluster.ETYPE_ERROR, msg)
|
1040 | b98bf262 | Michael Hanselmann | |
1041 | b98bf262 | Michael Hanselmann | elif not_before is not None and not_before > now: |
1042 | b98bf262 | Michael Hanselmann | return (LUVerifyCluster.ETYPE_WARNING,
|
1043 | b98bf262 | Michael Hanselmann | "Certificate %s not yet valid (valid from %s)" %
|
1044 | b98bf262 | Michael Hanselmann | (filename, _FormatTimestamp(not_before))) |
1045 | b98bf262 | Michael Hanselmann | |
1046 | b98bf262 | Michael Hanselmann | elif not_after is not None: |
1047 | b98bf262 | Michael Hanselmann | remaining_days = int((not_after - now) / (24 * 3600)) |
1048 | b98bf262 | Michael Hanselmann | |
1049 | b98bf262 | Michael Hanselmann | msg = ("Certificate %s expires in %d days" % (filename, remaining_days))
|
1050 | b98bf262 | Michael Hanselmann | |
1051 | b98bf262 | Michael Hanselmann | if remaining_days <= error_days:
|
1052 | b98bf262 | Michael Hanselmann | return (LUVerifyCluster.ETYPE_ERROR, msg)
|
1053 | b98bf262 | Michael Hanselmann | |
1054 | b98bf262 | Michael Hanselmann | if remaining_days <= warn_days:
|
1055 | b98bf262 | Michael Hanselmann | return (LUVerifyCluster.ETYPE_WARNING, msg)
|
1056 | b98bf262 | Michael Hanselmann | |
1057 | b98bf262 | Michael Hanselmann | return (None, None) |
1058 | b98bf262 | Michael Hanselmann | |
1059 | b98bf262 | Michael Hanselmann | |
1060 | b98bf262 | Michael Hanselmann | def _VerifyCertificate(filename): |
1061 | b98bf262 | Michael Hanselmann | """Verifies a certificate for LUVerifyCluster.
|
1062 | b98bf262 | Michael Hanselmann |
|
1063 | b98bf262 | Michael Hanselmann | @type filename: string
|
1064 | b98bf262 | Michael Hanselmann | @param filename: Path to PEM file
|
1065 | b98bf262 | Michael Hanselmann |
|
1066 | b98bf262 | Michael Hanselmann | """
|
1067 | b98bf262 | Michael Hanselmann | try:
|
1068 | b98bf262 | Michael Hanselmann | cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, |
1069 | b98bf262 | Michael Hanselmann | utils.ReadFile(filename)) |
1070 | b98bf262 | Michael Hanselmann | except Exception, err: # pylint: disable-msg=W0703 |
1071 | b98bf262 | Michael Hanselmann | return (LUVerifyCluster.ETYPE_ERROR,
|
1072 | b98bf262 | Michael Hanselmann | "Failed to load X509 certificate %s: %s" % (filename, err))
|
1073 | b98bf262 | Michael Hanselmann | |
1074 | b98bf262 | Michael Hanselmann | # Depending on the pyOpenSSL version, this can just return (None, None)
|
1075 | b98bf262 | Michael Hanselmann | (not_before, not_after) = utils.GetX509CertValidity(cert) |
1076 | b98bf262 | Michael Hanselmann | |
1077 | b98bf262 | Michael Hanselmann | return _VerifyCertificateInner(filename, cert.has_expired(),
|
1078 | b98bf262 | Michael Hanselmann | not_before, not_after, time.time()) |
1079 | b98bf262 | Michael Hanselmann | |
1080 | b98bf262 | Michael Hanselmann | |
1081 | d8fff41c | Guido Trotter | class LUVerifyCluster(LogicalUnit): |
1082 | a8083063 | Iustin Pop | """Verifies the cluster status.
|
1083 | a8083063 | Iustin Pop |
|
1084 | a8083063 | Iustin Pop | """
|
1085 | d8fff41c | Guido Trotter | HPATH = "cluster-verify"
|
1086 | d8fff41c | Guido Trotter | HTYPE = constants.HTYPE_CLUSTER |
1087 | a0c9776a | Iustin Pop | _OP_REQP = ["skip_checks", "verbose", "error_codes", "debug_simulate_errors"] |
1088 | d4b9d97f | Guido Trotter | REQ_BGL = False
|
1089 | d4b9d97f | Guido Trotter | |
1090 | 7c874ee1 | Iustin Pop | TCLUSTER = "cluster"
|
1091 | 7c874ee1 | Iustin Pop | TNODE = "node"
|
1092 | 7c874ee1 | Iustin Pop | TINSTANCE = "instance"
|
1093 | 7c874ee1 | Iustin Pop | |
1094 | 7c874ee1 | Iustin Pop | ECLUSTERCFG = (TCLUSTER, "ECLUSTERCFG")
|
1095 | b98bf262 | Michael Hanselmann | ECLUSTERCERT = (TCLUSTER, "ECLUSTERCERT")
|
1096 | 7c874ee1 | Iustin Pop | EINSTANCEBADNODE = (TINSTANCE, "EINSTANCEBADNODE")
|
1097 | 7c874ee1 | Iustin Pop | EINSTANCEDOWN = (TINSTANCE, "EINSTANCEDOWN")
|
1098 | 7c874ee1 | Iustin Pop | EINSTANCELAYOUT = (TINSTANCE, "EINSTANCELAYOUT")
|
1099 | 7c874ee1 | Iustin Pop | EINSTANCEMISSINGDISK = (TINSTANCE, "EINSTANCEMISSINGDISK")
|
1100 | 7c874ee1 | Iustin Pop | EINSTANCEMISSINGDISK = (TINSTANCE, "EINSTANCEMISSINGDISK")
|
1101 | 7c874ee1 | Iustin Pop | EINSTANCEWRONGNODE = (TINSTANCE, "EINSTANCEWRONGNODE")
|
1102 | 7c874ee1 | Iustin Pop | ENODEDRBD = (TNODE, "ENODEDRBD")
|
1103 | 7c874ee1 | Iustin Pop | ENODEFILECHECK = (TNODE, "ENODEFILECHECK")
|
1104 | 7c874ee1 | Iustin Pop | ENODEHOOKS = (TNODE, "ENODEHOOKS")
|
1105 | 7c874ee1 | Iustin Pop | ENODEHV = (TNODE, "ENODEHV")
|
1106 | 7c874ee1 | Iustin Pop | ENODELVM = (TNODE, "ENODELVM")
|
1107 | 7c874ee1 | Iustin Pop | ENODEN1 = (TNODE, "ENODEN1")
|
1108 | 7c874ee1 | Iustin Pop | ENODENET = (TNODE, "ENODENET")
|
1109 | 7c874ee1 | Iustin Pop | ENODEORPHANINSTANCE = (TNODE, "ENODEORPHANINSTANCE")
|
1110 | 7c874ee1 | Iustin Pop | ENODEORPHANLV = (TNODE, "ENODEORPHANLV")
|
1111 | 7c874ee1 | Iustin Pop | ENODERPC = (TNODE, "ENODERPC")
|
1112 | 7c874ee1 | Iustin Pop | ENODESSH = (TNODE, "ENODESSH")
|
1113 | 7c874ee1 | Iustin Pop | ENODEVERSION = (TNODE, "ENODEVERSION")
|
1114 | 7c0aa8e9 | Iustin Pop | ENODESETUP = (TNODE, "ENODESETUP")
|
1115 | 313b2dd4 | Michael Hanselmann | ENODETIME = (TNODE, "ENODETIME")
|
1116 | 7c874ee1 | Iustin Pop | |
1117 | a0c9776a | Iustin Pop | ETYPE_FIELD = "code"
|
1118 | a0c9776a | Iustin Pop | ETYPE_ERROR = "ERROR"
|
1119 | a0c9776a | Iustin Pop | ETYPE_WARNING = "WARNING"
|
1120 | a0c9776a | Iustin Pop | |
1121 | 02c521e4 | Iustin Pop | class NodeImage(object): |
1122 | 02c521e4 | Iustin Pop | """A class representing the logical and physical status of a node.
|
1123 | 02c521e4 | Iustin Pop |
|
1124 | 02c521e4 | Iustin Pop | @ivar volumes: a structure as returned from
|
1125 | 3a488770 | Iustin Pop | L{ganeti.backend.GetVolumeList} (runtime)
|
1126 | 02c521e4 | Iustin Pop | @ivar instances: a list of running instances (runtime)
|
1127 | 02c521e4 | Iustin Pop | @ivar pinst: list of configured primary instances (config)
|
1128 | 02c521e4 | Iustin Pop | @ivar sinst: list of configured secondary instances (config)
|
1129 | 02c521e4 | Iustin Pop | @ivar sbp: diction of {secondary-node: list of instances} of all peers
|
1130 | 02c521e4 | Iustin Pop | of this node (config)
|
1131 | 02c521e4 | Iustin Pop | @ivar mfree: free memory, as reported by hypervisor (runtime)
|
1132 | 02c521e4 | Iustin Pop | @ivar dfree: free disk, as reported by the node (runtime)
|
1133 | 02c521e4 | Iustin Pop | @ivar offline: the offline status (config)
|
1134 | 02c521e4 | Iustin Pop | @type rpc_fail: boolean
|
1135 | 02c521e4 | Iustin Pop | @ivar rpc_fail: whether the RPC verify call was successfull (overall,
|
1136 | 02c521e4 | Iustin Pop | not whether the individual keys were correct) (runtime)
|
1137 | 02c521e4 | Iustin Pop | @type lvm_fail: boolean
|
1138 | 02c521e4 | Iustin Pop | @ivar lvm_fail: whether the RPC call didn't return valid LVM data
|
1139 | 02c521e4 | Iustin Pop | @type hyp_fail: boolean
|
1140 | 02c521e4 | Iustin Pop | @ivar hyp_fail: whether the RPC call didn't return the instance list
|
1141 | 02c521e4 | Iustin Pop | @type ghost: boolean
|
1142 | 02c521e4 | Iustin Pop | @ivar ghost: whether this is a known node or not (config)
|
1143 | 02c521e4 | Iustin Pop |
|
1144 | 02c521e4 | Iustin Pop | """
|
1145 | 02c521e4 | Iustin Pop | def __init__(self, offline=False): |
1146 | 02c521e4 | Iustin Pop | self.volumes = {}
|
1147 | 02c521e4 | Iustin Pop | self.instances = []
|
1148 | 02c521e4 | Iustin Pop | self.pinst = []
|
1149 | 02c521e4 | Iustin Pop | self.sinst = []
|
1150 | 02c521e4 | Iustin Pop | self.sbp = {}
|
1151 | 02c521e4 | Iustin Pop | self.mfree = 0 |
1152 | 02c521e4 | Iustin Pop | self.dfree = 0 |
1153 | 02c521e4 | Iustin Pop | self.offline = offline
|
1154 | 02c521e4 | Iustin Pop | self.rpc_fail = False |
1155 | 02c521e4 | Iustin Pop | self.lvm_fail = False |
1156 | 02c521e4 | Iustin Pop | self.hyp_fail = False |
1157 | 02c521e4 | Iustin Pop | self.ghost = False |
1158 | 02c521e4 | Iustin Pop | |
1159 | d4b9d97f | Guido Trotter | def ExpandNames(self): |
1160 | d4b9d97f | Guido Trotter | self.needed_locks = {
|
1161 | d4b9d97f | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET, |
1162 | d4b9d97f | Guido Trotter | locking.LEVEL_INSTANCE: locking.ALL_SET, |
1163 | d4b9d97f | Guido Trotter | } |
1164 | c772d142 | Michael Hanselmann | self.share_locks = dict.fromkeys(locking.LEVELS, 1) |
1165 | a8083063 | Iustin Pop | |
1166 | 7c874ee1 | Iustin Pop | def _Error(self, ecode, item, msg, *args, **kwargs): |
1167 | 7c874ee1 | Iustin Pop | """Format an error message.
|
1168 | 7c874ee1 | Iustin Pop |
|
1169 | 7c874ee1 | Iustin Pop | Based on the opcode's error_codes parameter, either format a
|
1170 | 7c874ee1 | Iustin Pop | parseable error code, or a simpler error string.
|
1171 | 7c874ee1 | Iustin Pop |
|
1172 | 7c874ee1 | Iustin Pop | This must be called only from Exec and functions called from Exec.
|
1173 | 7c874ee1 | Iustin Pop |
|
1174 | 7c874ee1 | Iustin Pop | """
|
1175 | a0c9776a | Iustin Pop | ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) |
1176 | 7c874ee1 | Iustin Pop | itype, etxt = ecode |
1177 | 7c874ee1 | Iustin Pop | # first complete the msg
|
1178 | 7c874ee1 | Iustin Pop | if args:
|
1179 | 7c874ee1 | Iustin Pop | msg = msg % args |
1180 | 7c874ee1 | Iustin Pop | # then format the whole message
|
1181 | 7c874ee1 | Iustin Pop | if self.op.error_codes: |
1182 | 7c874ee1 | Iustin Pop | msg = "%s:%s:%s:%s:%s" % (ltype, etxt, itype, item, msg)
|
1183 | 7c874ee1 | Iustin Pop | else:
|
1184 | 7c874ee1 | Iustin Pop | if item:
|
1185 | 7c874ee1 | Iustin Pop | item = " " + item
|
1186 | 7c874ee1 | Iustin Pop | else:
|
1187 | 7c874ee1 | Iustin Pop | item = ""
|
1188 | 7c874ee1 | Iustin Pop | msg = "%s: %s%s: %s" % (ltype, itype, item, msg)
|
1189 | 7c874ee1 | Iustin Pop | # and finally report it via the feedback_fn
|
1190 | 7c874ee1 | Iustin Pop | self._feedback_fn(" - %s" % msg) |
1191 | 7c874ee1 | Iustin Pop | |
1192 | a0c9776a | Iustin Pop | def _ErrorIf(self, cond, *args, **kwargs): |
1193 | a0c9776a | Iustin Pop | """Log an error message if the passed condition is True.
|
1194 | a0c9776a | Iustin Pop |
|
1195 | a0c9776a | Iustin Pop | """
|
1196 | a0c9776a | Iustin Pop | cond = bool(cond) or self.op.debug_simulate_errors |
1197 | a0c9776a | Iustin Pop | if cond:
|
1198 | a0c9776a | Iustin Pop | self._Error(*args, **kwargs)
|
1199 | a0c9776a | Iustin Pop | # do not mark the operation as failed for WARN cases only
|
1200 | a0c9776a | Iustin Pop | if kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) == self.ETYPE_ERROR: |
1201 | a0c9776a | Iustin Pop | self.bad = self.bad or cond |
1202 | a0c9776a | Iustin Pop | |
1203 | 02c521e4 | Iustin Pop | def _VerifyNode(self, ninfo, nresult): |
1204 | a8083063 | Iustin Pop | """Run multiple tests against a node.
|
1205 | a8083063 | Iustin Pop |
|
1206 | 112f18a5 | Iustin Pop | Test list:
|
1207 | e4376078 | Iustin Pop |
|
1208 | a8083063 | Iustin Pop | - compares ganeti version
|
1209 | 5bbd3f7f | Michael Hanselmann | - checks vg existence and size > 20G
|
1210 | a8083063 | Iustin Pop | - checks config file checksum
|
1211 | a8083063 | Iustin Pop | - checks ssh to other nodes
|
1212 | a8083063 | Iustin Pop |
|
1213 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1214 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1215 | 02c521e4 | Iustin Pop | @param nresult: the results from the node
|
1216 | 02c521e4 | Iustin Pop | @rtype: boolean
|
1217 | 02c521e4 | Iustin Pop | @return: whether overall this call was successful (and we can expect
|
1218 | 02c521e4 | Iustin Pop | reasonable values in the respose)
|
1219 | 098c0958 | Michael Hanselmann |
|
1220 | a8083063 | Iustin Pop | """
|
1221 | 02c521e4 | Iustin Pop | node = ninfo.name |
1222 | 7260cfbe | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1223 | 25361b9a | Iustin Pop | |
1224 | 02c521e4 | Iustin Pop | # main result, nresult should be a non-empty dict
|
1225 | 02c521e4 | Iustin Pop | test = not nresult or not isinstance(nresult, dict) |
1226 | a0c9776a | Iustin Pop | _ErrorIf(test, self.ENODERPC, node,
|
1227 | 7c874ee1 | Iustin Pop | "unable to verify node: no data returned")
|
1228 | a0c9776a | Iustin Pop | if test:
|
1229 | 02c521e4 | Iustin Pop | return False |
1230 | 25361b9a | Iustin Pop | |
1231 | a8083063 | Iustin Pop | # compares ganeti version
|
1232 | a8083063 | Iustin Pop | local_version = constants.PROTOCOL_VERSION |
1233 | 02c521e4 | Iustin Pop | remote_version = nresult.get("version", None) |
1234 | a0c9776a | Iustin Pop | test = not (remote_version and |
1235 | a0c9776a | Iustin Pop | isinstance(remote_version, (list, tuple)) and |
1236 | a0c9776a | Iustin Pop | len(remote_version) == 2) |
1237 | a0c9776a | Iustin Pop | _ErrorIf(test, self.ENODERPC, node,
|
1238 | a0c9776a | Iustin Pop | "connection to node returned invalid data")
|
1239 | a0c9776a | Iustin Pop | if test:
|
1240 | 02c521e4 | Iustin Pop | return False |
1241 | a0c9776a | Iustin Pop | |
1242 | a0c9776a | Iustin Pop | test = local_version != remote_version[0]
|
1243 | a0c9776a | Iustin Pop | _ErrorIf(test, self.ENODEVERSION, node,
|
1244 | a0c9776a | Iustin Pop | "incompatible protocol versions: master %s,"
|
1245 | a0c9776a | Iustin Pop | " node %s", local_version, remote_version[0]) |
1246 | a0c9776a | Iustin Pop | if test:
|
1247 | 02c521e4 | Iustin Pop | return False |
1248 | a8083063 | Iustin Pop | |
1249 | e9ce0a64 | Iustin Pop | # node seems compatible, we can actually try to look into its results
|
1250 | a8083063 | Iustin Pop | |
1251 | e9ce0a64 | Iustin Pop | # full package version
|
1252 | a0c9776a | Iustin Pop | self._ErrorIf(constants.RELEASE_VERSION != remote_version[1], |
1253 | a0c9776a | Iustin Pop | self.ENODEVERSION, node,
|
1254 | 7c874ee1 | Iustin Pop | "software version mismatch: master %s, node %s",
|
1255 | 7c874ee1 | Iustin Pop | constants.RELEASE_VERSION, remote_version[1],
|
1256 | a0c9776a | Iustin Pop | code=self.ETYPE_WARNING)
|
1257 | e9ce0a64 | Iustin Pop | |
1258 | 02c521e4 | Iustin Pop | hyp_result = nresult.get(constants.NV_HYPERVISOR, None)
|
1259 | 02c521e4 | Iustin Pop | if isinstance(hyp_result, dict): |
1260 | 02c521e4 | Iustin Pop | for hv_name, hv_result in hyp_result.iteritems(): |
1261 | 02c521e4 | Iustin Pop | test = hv_result is not None |
1262 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODEHV, node,
|
1263 | 02c521e4 | Iustin Pop | "hypervisor %s verify failure: '%s'", hv_name, hv_result)
|
1264 | a8083063 | Iustin Pop | |
1265 | a8083063 | Iustin Pop | |
1266 | 02c521e4 | Iustin Pop | test = nresult.get(constants.NV_NODESETUP, |
1267 | 02c521e4 | Iustin Pop | ["Missing NODESETUP results"])
|
1268 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODESETUP, node, "node setup error: %s", |
1269 | 02c521e4 | Iustin Pop | "; ".join(test))
|
1270 | 02c521e4 | Iustin Pop | |
1271 | 02c521e4 | Iustin Pop | return True |
1272 | 02c521e4 | Iustin Pop | |
1273 | 02c521e4 | Iustin Pop | def _VerifyNodeTime(self, ninfo, nresult, |
1274 | 02c521e4 | Iustin Pop | nvinfo_starttime, nvinfo_endtime): |
1275 | 02c521e4 | Iustin Pop | """Check the node time.
|
1276 | 02c521e4 | Iustin Pop |
|
1277 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1278 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1279 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1280 | 02c521e4 | Iustin Pop | @param nvinfo_starttime: the start time of the RPC call
|
1281 | 02c521e4 | Iustin Pop | @param nvinfo_endtime: the end time of the RPC call
|
1282 | 02c521e4 | Iustin Pop |
|
1283 | 02c521e4 | Iustin Pop | """
|
1284 | 02c521e4 | Iustin Pop | node = ninfo.name |
1285 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1286 | 02c521e4 | Iustin Pop | |
1287 | 02c521e4 | Iustin Pop | ntime = nresult.get(constants.NV_TIME, None)
|
1288 | 02c521e4 | Iustin Pop | try:
|
1289 | 02c521e4 | Iustin Pop | ntime_merged = utils.MergeTime(ntime) |
1290 | 02c521e4 | Iustin Pop | except (ValueError, TypeError): |
1291 | 02c521e4 | Iustin Pop | _ErrorIf(True, self.ENODETIME, node, "Node returned invalid time") |
1292 | 02c521e4 | Iustin Pop | return
|
1293 | 02c521e4 | Iustin Pop | |
1294 | 02c521e4 | Iustin Pop | if ntime_merged < (nvinfo_starttime - constants.NODE_MAX_CLOCK_SKEW):
|
1295 | 02c521e4 | Iustin Pop | ntime_diff = "%.01fs" % abs(nvinfo_starttime - ntime_merged) |
1296 | 02c521e4 | Iustin Pop | elif ntime_merged > (nvinfo_endtime + constants.NODE_MAX_CLOCK_SKEW):
|
1297 | 02c521e4 | Iustin Pop | ntime_diff = "%.01fs" % abs(ntime_merged - nvinfo_endtime) |
1298 | 02c521e4 | Iustin Pop | else:
|
1299 | 02c521e4 | Iustin Pop | ntime_diff = None
|
1300 | 02c521e4 | Iustin Pop | |
1301 | 02c521e4 | Iustin Pop | _ErrorIf(ntime_diff is not None, self.ENODETIME, node, |
1302 | 02c521e4 | Iustin Pop | "Node time diverges by at least %s from master node time",
|
1303 | 02c521e4 | Iustin Pop | ntime_diff) |
1304 | 02c521e4 | Iustin Pop | |
1305 | 02c521e4 | Iustin Pop | def _VerifyNodeLVM(self, ninfo, nresult, vg_name): |
1306 | 02c521e4 | Iustin Pop | """Check the node time.
|
1307 | 02c521e4 | Iustin Pop |
|
1308 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1309 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1310 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1311 | 02c521e4 | Iustin Pop | @param vg_name: the configured VG name
|
1312 | 02c521e4 | Iustin Pop |
|
1313 | 02c521e4 | Iustin Pop | """
|
1314 | 02c521e4 | Iustin Pop | if vg_name is None: |
1315 | 02c521e4 | Iustin Pop | return
|
1316 | 02c521e4 | Iustin Pop | |
1317 | 02c521e4 | Iustin Pop | node = ninfo.name |
1318 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1319 | 02c521e4 | Iustin Pop | |
1320 | 02c521e4 | Iustin Pop | # checks vg existence and size > 20G
|
1321 | 02c521e4 | Iustin Pop | vglist = nresult.get(constants.NV_VGLIST, None)
|
1322 | 02c521e4 | Iustin Pop | test = not vglist
|
1323 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODELVM, node, "unable to check volume groups") |
1324 | 02c521e4 | Iustin Pop | if not test: |
1325 | 02c521e4 | Iustin Pop | vgstatus = utils.CheckVolumeGroupSize(vglist, vg_name, |
1326 | 02c521e4 | Iustin Pop | constants.MIN_VG_SIZE) |
1327 | 02c521e4 | Iustin Pop | _ErrorIf(vgstatus, self.ENODELVM, node, vgstatus)
|
1328 | 02c521e4 | Iustin Pop | |
1329 | 02c521e4 | Iustin Pop | # check pv names
|
1330 | 02c521e4 | Iustin Pop | pvlist = nresult.get(constants.NV_PVLIST, None)
|
1331 | 02c521e4 | Iustin Pop | test = pvlist is None |
1332 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODELVM, node, "Can't get PV list from node") |
1333 | a0c9776a | Iustin Pop | if not test: |
1334 | 02c521e4 | Iustin Pop | # check that ':' is not present in PV names, since it's a
|
1335 | 02c521e4 | Iustin Pop | # special character for lvcreate (denotes the range of PEs to
|
1336 | 02c521e4 | Iustin Pop | # use on the PV)
|
1337 | 02c521e4 | Iustin Pop | for _, pvname, owner_vg in pvlist: |
1338 | 02c521e4 | Iustin Pop | test = ":" in pvname |
1339 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODELVM, node, "Invalid character ':' in PV" |
1340 | 02c521e4 | Iustin Pop | " '%s' of VG '%s'", pvname, owner_vg)
|
1341 | 02c521e4 | Iustin Pop | |
1342 | 02c521e4 | Iustin Pop | def _VerifyNodeNetwork(self, ninfo, nresult): |
1343 | 02c521e4 | Iustin Pop | """Check the node time.
|
1344 | 02c521e4 | Iustin Pop |
|
1345 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1346 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1347 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1348 | 02c521e4 | Iustin Pop |
|
1349 | 02c521e4 | Iustin Pop | """
|
1350 | 02c521e4 | Iustin Pop | node = ninfo.name |
1351 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1352 | 02c521e4 | Iustin Pop | |
1353 | 02c521e4 | Iustin Pop | test = constants.NV_NODELIST not in nresult |
1354 | a0c9776a | Iustin Pop | _ErrorIf(test, self.ENODESSH, node,
|
1355 | a0c9776a | Iustin Pop | "node hasn't returned node ssh connectivity data")
|
1356 | a0c9776a | Iustin Pop | if not test: |
1357 | 02c521e4 | Iustin Pop | if nresult[constants.NV_NODELIST]:
|
1358 | 02c521e4 | Iustin Pop | for a_node, a_msg in nresult[constants.NV_NODELIST].items(): |
1359 | a0c9776a | Iustin Pop | _ErrorIf(True, self.ENODESSH, node, |
1360 | a0c9776a | Iustin Pop | "ssh communication with node '%s': %s", a_node, a_msg)
|
1361 | 25361b9a | Iustin Pop | |
1362 | 02c521e4 | Iustin Pop | test = constants.NV_NODENETTEST not in nresult |
1363 | a0c9776a | Iustin Pop | _ErrorIf(test, self.ENODENET, node,
|
1364 | a0c9776a | Iustin Pop | "node hasn't returned node tcp connectivity data")
|
1365 | a0c9776a | Iustin Pop | if not test: |
1366 | 02c521e4 | Iustin Pop | if nresult[constants.NV_NODENETTEST]:
|
1367 | 02c521e4 | Iustin Pop | nlist = utils.NiceSort(nresult[constants.NV_NODENETTEST].keys()) |
1368 | 7c874ee1 | Iustin Pop | for anode in nlist: |
1369 | a0c9776a | Iustin Pop | _ErrorIf(True, self.ENODENET, node, |
1370 | a0c9776a | Iustin Pop | "tcp communication with node '%s': %s",
|
1371 | 02c521e4 | Iustin Pop | anode, nresult[constants.NV_NODENETTEST][anode]) |
1372 | a8083063 | Iustin Pop | |
1373 | 02c521e4 | Iustin Pop | def _VerifyInstance(self, instance, instanceconfig, node_image): |
1374 | a8083063 | Iustin Pop | """Verify an instance.
|
1375 | a8083063 | Iustin Pop |
|
1376 | a8083063 | Iustin Pop | This function checks to see if the required block devices are
|
1377 | a8083063 | Iustin Pop | available on the instance's node.
|
1378 | a8083063 | Iustin Pop |
|
1379 | a8083063 | Iustin Pop | """
|
1380 | 7260cfbe | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1381 | a8083063 | Iustin Pop | node_current = instanceconfig.primary_node |
1382 | a8083063 | Iustin Pop | |
1383 | a8083063 | Iustin Pop | node_vol_should = {} |
1384 | a8083063 | Iustin Pop | instanceconfig.MapLVsByNode(node_vol_should) |
1385 | a8083063 | Iustin Pop | |
1386 | a8083063 | Iustin Pop | for node in node_vol_should: |
1387 | 02c521e4 | Iustin Pop | n_img = node_image[node] |
1388 | 02c521e4 | Iustin Pop | if n_img.offline or n_img.rpc_fail or n_img.lvm_fail: |
1389 | 02c521e4 | Iustin Pop | # ignore missing volumes on offline or broken nodes
|
1390 | 0a66c968 | Iustin Pop | continue
|
1391 | a8083063 | Iustin Pop | for volume in node_vol_should[node]: |
1392 | 02c521e4 | Iustin Pop | test = volume not in n_img.volumes |
1393 | a0c9776a | Iustin Pop | _ErrorIf(test, self.EINSTANCEMISSINGDISK, instance,
|
1394 | a0c9776a | Iustin Pop | "volume %s missing on node %s", volume, node)
|
1395 | a8083063 | Iustin Pop | |
1396 | 0d68c45d | Iustin Pop | if instanceconfig.admin_up:
|
1397 | 02c521e4 | Iustin Pop | pri_img = node_image[node_current] |
1398 | 02c521e4 | Iustin Pop | test = instance not in pri_img.instances and not pri_img.offline |
1399 | a0c9776a | Iustin Pop | _ErrorIf(test, self.EINSTANCEDOWN, instance,
|
1400 | a0c9776a | Iustin Pop | "instance not running on its primary node %s",
|
1401 | a0c9776a | Iustin Pop | node_current) |
1402 | a8083063 | Iustin Pop | |
1403 | 02c521e4 | Iustin Pop | for node, n_img in node_image.items(): |
1404 | a8083063 | Iustin Pop | if (not node == node_current): |
1405 | 02c521e4 | Iustin Pop | test = instance in n_img.instances
|
1406 | a0c9776a | Iustin Pop | _ErrorIf(test, self.EINSTANCEWRONGNODE, instance,
|
1407 | a0c9776a | Iustin Pop | "instance should not run on node %s", node)
|
1408 | a8083063 | Iustin Pop | |
1409 | 02c521e4 | Iustin Pop | def _VerifyOrphanVolumes(self, node_vol_should, node_image): |
1410 | a8083063 | Iustin Pop | """Verify if there are any unknown volumes in the cluster.
|
1411 | a8083063 | Iustin Pop |
|
1412 | a8083063 | Iustin Pop | The .os, .swap and backup volumes are ignored. All other volumes are
|
1413 | a8083063 | Iustin Pop | reported as unknown.
|
1414 | a8083063 | Iustin Pop |
|
1415 | a8083063 | Iustin Pop | """
|
1416 | 02c521e4 | Iustin Pop | for node, n_img in node_image.items(): |
1417 | 02c521e4 | Iustin Pop | if n_img.offline or n_img.rpc_fail or n_img.lvm_fail: |
1418 | 02c521e4 | Iustin Pop | # skip non-healthy nodes
|
1419 | 02c521e4 | Iustin Pop | continue
|
1420 | 02c521e4 | Iustin Pop | for volume in n_img.volumes: |
1421 | a0c9776a | Iustin Pop | test = (node not in node_vol_should or |
1422 | a0c9776a | Iustin Pop | volume not in node_vol_should[node]) |
1423 | a0c9776a | Iustin Pop | self._ErrorIf(test, self.ENODEORPHANLV, node, |
1424 | 7c874ee1 | Iustin Pop | "volume %s is unknown", volume)
|
1425 | a8083063 | Iustin Pop | |
1426 | 02c521e4 | Iustin Pop | def _VerifyOrphanInstances(self, instancelist, node_image): |
1427 | a8083063 | Iustin Pop | """Verify the list of running instances.
|
1428 | a8083063 | Iustin Pop |
|
1429 | a8083063 | Iustin Pop | This checks what instances are running but unknown to the cluster.
|
1430 | a8083063 | Iustin Pop |
|
1431 | a8083063 | Iustin Pop | """
|
1432 | 02c521e4 | Iustin Pop | for node, n_img in node_image.items(): |
1433 | 02c521e4 | Iustin Pop | for o_inst in n_img.instances: |
1434 | a0c9776a | Iustin Pop | test = o_inst not in instancelist |
1435 | a0c9776a | Iustin Pop | self._ErrorIf(test, self.ENODEORPHANINSTANCE, node, |
1436 | 7c874ee1 | Iustin Pop | "instance %s on node %s should not exist", o_inst, node)
|
1437 | a8083063 | Iustin Pop | |
1438 | 02c521e4 | Iustin Pop | def _VerifyNPlusOneMemory(self, node_image, instance_cfg): |
1439 | 2b3b6ddd | Guido Trotter | """Verify N+1 Memory Resilience.
|
1440 | 2b3b6ddd | Guido Trotter |
|
1441 | 02c521e4 | Iustin Pop | Check that if one single node dies we can still start all the
|
1442 | 02c521e4 | Iustin Pop | instances it was primary for.
|
1443 | 2b3b6ddd | Guido Trotter |
|
1444 | 2b3b6ddd | Guido Trotter | """
|
1445 | 02c521e4 | Iustin Pop | for node, n_img in node_image.items(): |
1446 | 02c521e4 | Iustin Pop | # This code checks that every node which is now listed as
|
1447 | 02c521e4 | Iustin Pop | # secondary has enough memory to host all instances it is
|
1448 | 02c521e4 | Iustin Pop | # supposed to should a single other node in the cluster fail.
|
1449 | 2b3b6ddd | Guido Trotter | # FIXME: not ready for failover to an arbitrary node
|
1450 | 2b3b6ddd | Guido Trotter | # FIXME: does not support file-backed instances
|
1451 | 02c521e4 | Iustin Pop | # WARNING: we currently take into account down instances as well
|
1452 | 02c521e4 | Iustin Pop | # as up ones, considering that even if they're down someone
|
1453 | 02c521e4 | Iustin Pop | # might want to start them even in the event of a node failure.
|
1454 | 02c521e4 | Iustin Pop | for prinode, instances in n_img.sbp.items(): |
1455 | 2b3b6ddd | Guido Trotter | needed_mem = 0
|
1456 | 2b3b6ddd | Guido Trotter | for instance in instances: |
1457 | 338e51e8 | Iustin Pop | bep = self.cfg.GetClusterInfo().FillBE(instance_cfg[instance])
|
1458 | c0f2b229 | Iustin Pop | if bep[constants.BE_AUTO_BALANCE]:
|
1459 | 3924700f | Iustin Pop | needed_mem += bep[constants.BE_MEMORY] |
1460 | 02c521e4 | Iustin Pop | test = n_img.mfree < needed_mem |
1461 | a0c9776a | Iustin Pop | self._ErrorIf(test, self.ENODEN1, node, |
1462 | 7c874ee1 | Iustin Pop | "not enough memory on to accommodate"
|
1463 | 7c874ee1 | Iustin Pop | " failovers should peer node %s fail", prinode)
|
1464 | 2b3b6ddd | Guido Trotter | |
1465 | 02c521e4 | Iustin Pop | def _VerifyNodeFiles(self, ninfo, nresult, file_list, local_cksum, |
1466 | 02c521e4 | Iustin Pop | master_files): |
1467 | 02c521e4 | Iustin Pop | """Verifies and computes the node required file checksums.
|
1468 | 02c521e4 | Iustin Pop |
|
1469 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1470 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1471 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1472 | 02c521e4 | Iustin Pop | @param file_list: required list of files
|
1473 | 02c521e4 | Iustin Pop | @param local_cksum: dictionary of local files and their checksums
|
1474 | 02c521e4 | Iustin Pop | @param master_files: list of files that only masters should have
|
1475 | 02c521e4 | Iustin Pop |
|
1476 | 02c521e4 | Iustin Pop | """
|
1477 | 02c521e4 | Iustin Pop | node = ninfo.name |
1478 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1479 | 02c521e4 | Iustin Pop | |
1480 | 02c521e4 | Iustin Pop | remote_cksum = nresult.get(constants.NV_FILELIST, None)
|
1481 | 02c521e4 | Iustin Pop | test = not isinstance(remote_cksum, dict) |
1482 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODEFILECHECK, node,
|
1483 | 02c521e4 | Iustin Pop | "node hasn't returned file checksum data")
|
1484 | 02c521e4 | Iustin Pop | if test:
|
1485 | 02c521e4 | Iustin Pop | return
|
1486 | 02c521e4 | Iustin Pop | |
1487 | 02c521e4 | Iustin Pop | for file_name in file_list: |
1488 | 02c521e4 | Iustin Pop | node_is_mc = ninfo.master_candidate |
1489 | 02c521e4 | Iustin Pop | must_have = (file_name not in master_files) or node_is_mc |
1490 | 02c521e4 | Iustin Pop | # missing
|
1491 | 02c521e4 | Iustin Pop | test1 = file_name not in remote_cksum |
1492 | 02c521e4 | Iustin Pop | # invalid checksum
|
1493 | 02c521e4 | Iustin Pop | test2 = not test1 and remote_cksum[file_name] != local_cksum[file_name] |
1494 | 02c521e4 | Iustin Pop | # existing and good
|
1495 | 02c521e4 | Iustin Pop | test3 = not test1 and remote_cksum[file_name] == local_cksum[file_name] |
1496 | 02c521e4 | Iustin Pop | _ErrorIf(test1 and must_have, self.ENODEFILECHECK, node, |
1497 | 02c521e4 | Iustin Pop | "file '%s' missing", file_name)
|
1498 | 02c521e4 | Iustin Pop | _ErrorIf(test2 and must_have, self.ENODEFILECHECK, node, |
1499 | 02c521e4 | Iustin Pop | "file '%s' has wrong checksum", file_name)
|
1500 | 02c521e4 | Iustin Pop | # not candidate and this is not a must-have file
|
1501 | 02c521e4 | Iustin Pop | _ErrorIf(test2 and not must_have, self.ENODEFILECHECK, node, |
1502 | 02c521e4 | Iustin Pop | "file '%s' should not exist on non master"
|
1503 | 02c521e4 | Iustin Pop | " candidates (and the file is outdated)", file_name)
|
1504 | 02c521e4 | Iustin Pop | # all good, except non-master/non-must have combination
|
1505 | 02c521e4 | Iustin Pop | _ErrorIf(test3 and not must_have, self.ENODEFILECHECK, node, |
1506 | 02c521e4 | Iustin Pop | "file '%s' should not exist"
|
1507 | 02c521e4 | Iustin Pop | " on non master candidates", file_name)
|
1508 | 02c521e4 | Iustin Pop | |
1509 | 02c521e4 | Iustin Pop | def _VerifyNodeDrbd(self, ninfo, nresult, instanceinfo, drbd_map): |
1510 | 02c521e4 | Iustin Pop | """Verifies and the node DRBD status.
|
1511 | 02c521e4 | Iustin Pop |
|
1512 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1513 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1514 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1515 | 02c521e4 | Iustin Pop | @param instanceinfo: the dict of instances
|
1516 | 02c521e4 | Iustin Pop | @param drbd_map: the DRBD map as returned by
|
1517 | 02c521e4 | Iustin Pop | L{ganeti.config.ConfigWriter.ComputeDRBDMap}
|
1518 | 02c521e4 | Iustin Pop |
|
1519 | 02c521e4 | Iustin Pop | """
|
1520 | 02c521e4 | Iustin Pop | node = ninfo.name |
1521 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1522 | 02c521e4 | Iustin Pop | |
1523 | 02c521e4 | Iustin Pop | # compute the DRBD minors
|
1524 | 02c521e4 | Iustin Pop | node_drbd = {} |
1525 | 02c521e4 | Iustin Pop | for minor, instance in drbd_map[node].items(): |
1526 | 02c521e4 | Iustin Pop | test = instance not in instanceinfo |
1527 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ECLUSTERCFG, None, |
1528 | 02c521e4 | Iustin Pop | "ghost instance '%s' in temporary DRBD map", instance)
|
1529 | 02c521e4 | Iustin Pop | # ghost instance should not be running, but otherwise we
|
1530 | 02c521e4 | Iustin Pop | # don't give double warnings (both ghost instance and
|
1531 | 02c521e4 | Iustin Pop | # unallocated minor in use)
|
1532 | 02c521e4 | Iustin Pop | if test:
|
1533 | 02c521e4 | Iustin Pop | node_drbd[minor] = (instance, False)
|
1534 | 02c521e4 | Iustin Pop | else:
|
1535 | 02c521e4 | Iustin Pop | instance = instanceinfo[instance] |
1536 | 02c521e4 | Iustin Pop | node_drbd[minor] = (instance.name, instance.admin_up) |
1537 | 02c521e4 | Iustin Pop | |
1538 | 02c521e4 | Iustin Pop | # and now check them
|
1539 | 02c521e4 | Iustin Pop | used_minors = nresult.get(constants.NV_DRBDLIST, []) |
1540 | 02c521e4 | Iustin Pop | test = not isinstance(used_minors, (tuple, list)) |
1541 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODEDRBD, node,
|
1542 | 02c521e4 | Iustin Pop | "cannot parse drbd status file: %s", str(used_minors)) |
1543 | 02c521e4 | Iustin Pop | if test:
|
1544 | 02c521e4 | Iustin Pop | # we cannot check drbd status
|
1545 | 02c521e4 | Iustin Pop | return
|
1546 | 02c521e4 | Iustin Pop | |
1547 | 02c521e4 | Iustin Pop | for minor, (iname, must_exist) in node_drbd.items(): |
1548 | 02c521e4 | Iustin Pop | test = minor not in used_minors and must_exist |
1549 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODEDRBD, node,
|
1550 | 02c521e4 | Iustin Pop | "drbd minor %d of instance %s is not active", minor, iname)
|
1551 | 02c521e4 | Iustin Pop | for minor in used_minors: |
1552 | 02c521e4 | Iustin Pop | test = minor not in node_drbd |
1553 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODEDRBD, node,
|
1554 | 02c521e4 | Iustin Pop | "unallocated drbd minor %d is in use", minor)
|
1555 | 02c521e4 | Iustin Pop | |
1556 | 02c521e4 | Iustin Pop | def _UpdateNodeVolumes(self, ninfo, nresult, nimg, vg_name): |
1557 | 02c521e4 | Iustin Pop | """Verifies and updates the node volume data.
|
1558 | 02c521e4 | Iustin Pop |
|
1559 | 02c521e4 | Iustin Pop | This function will update a L{NodeImage}'s internal structures
|
1560 | 02c521e4 | Iustin Pop | with data from the remote call.
|
1561 | 02c521e4 | Iustin Pop |
|
1562 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1563 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1564 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1565 | 02c521e4 | Iustin Pop | @param nimg: the node image object
|
1566 | 02c521e4 | Iustin Pop | @param vg_name: the configured VG name
|
1567 | 02c521e4 | Iustin Pop |
|
1568 | 02c521e4 | Iustin Pop | """
|
1569 | 02c521e4 | Iustin Pop | node = ninfo.name |
1570 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1571 | 02c521e4 | Iustin Pop | |
1572 | 02c521e4 | Iustin Pop | nimg.lvm_fail = True
|
1573 | 02c521e4 | Iustin Pop | lvdata = nresult.get(constants.NV_LVLIST, "Missing LV data")
|
1574 | 02c521e4 | Iustin Pop | if vg_name is None: |
1575 | 02c521e4 | Iustin Pop | pass
|
1576 | 02c521e4 | Iustin Pop | elif isinstance(lvdata, basestring): |
1577 | 02c521e4 | Iustin Pop | _ErrorIf(True, self.ENODELVM, node, "LVM problem on node: %s", |
1578 | 02c521e4 | Iustin Pop | utils.SafeEncode(lvdata)) |
1579 | 02c521e4 | Iustin Pop | elif not isinstance(lvdata, dict): |
1580 | 02c521e4 | Iustin Pop | _ErrorIf(True, self.ENODELVM, node, "rpc call to node failed (lvlist)") |
1581 | 02c521e4 | Iustin Pop | else:
|
1582 | 02c521e4 | Iustin Pop | nimg.volumes = lvdata |
1583 | 02c521e4 | Iustin Pop | nimg.lvm_fail = False
|
1584 | 02c521e4 | Iustin Pop | |
1585 | 02c521e4 | Iustin Pop | def _UpdateNodeInstances(self, ninfo, nresult, nimg): |
1586 | 02c521e4 | Iustin Pop | """Verifies and updates the node instance list.
|
1587 | 02c521e4 | Iustin Pop |
|
1588 | 02c521e4 | Iustin Pop | If the listing was successful, then updates this node's instance
|
1589 | 02c521e4 | Iustin Pop | list. Otherwise, it marks the RPC call as failed for the instance
|
1590 | 02c521e4 | Iustin Pop | list key.
|
1591 | 02c521e4 | Iustin Pop |
|
1592 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1593 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1594 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1595 | 02c521e4 | Iustin Pop | @param nimg: the node image object
|
1596 | 02c521e4 | Iustin Pop |
|
1597 | 02c521e4 | Iustin Pop | """
|
1598 | 02c521e4 | Iustin Pop | idata = nresult.get(constants.NV_INSTANCELIST, None)
|
1599 | 02c521e4 | Iustin Pop | test = not isinstance(idata, list) |
1600 | 02c521e4 | Iustin Pop | self._ErrorIf(test, self.ENODEHV, ninfo.name, "rpc call to node failed" |
1601 | 02c521e4 | Iustin Pop | " (instancelist): %s", utils.SafeEncode(str(idata))) |
1602 | 02c521e4 | Iustin Pop | if test:
|
1603 | 02c521e4 | Iustin Pop | nimg.hyp_fail = True
|
1604 | 02c521e4 | Iustin Pop | else:
|
1605 | 02c521e4 | Iustin Pop | nimg.instances = idata |
1606 | 02c521e4 | Iustin Pop | |
1607 | 02c521e4 | Iustin Pop | def _UpdateNodeInfo(self, ninfo, nresult, nimg, vg_name): |
1608 | 02c521e4 | Iustin Pop | """Verifies and computes a node information map
|
1609 | 02c521e4 | Iustin Pop |
|
1610 | 02c521e4 | Iustin Pop | @type ninfo: L{objects.Node}
|
1611 | 02c521e4 | Iustin Pop | @param ninfo: the node to check
|
1612 | 02c521e4 | Iustin Pop | @param nresult: the remote results for the node
|
1613 | 02c521e4 | Iustin Pop | @param nimg: the node image object
|
1614 | 02c521e4 | Iustin Pop | @param vg_name: the configured VG name
|
1615 | 02c521e4 | Iustin Pop |
|
1616 | 02c521e4 | Iustin Pop | """
|
1617 | 02c521e4 | Iustin Pop | node = ninfo.name |
1618 | 02c521e4 | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1619 | 02c521e4 | Iustin Pop | |
1620 | 02c521e4 | Iustin Pop | # try to read free memory (from the hypervisor)
|
1621 | 02c521e4 | Iustin Pop | hv_info = nresult.get(constants.NV_HVINFO, None)
|
1622 | 02c521e4 | Iustin Pop | test = not isinstance(hv_info, dict) or "memory_free" not in hv_info |
1623 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODEHV, node, "rpc call to node failed (hvinfo)") |
1624 | 02c521e4 | Iustin Pop | if not test: |
1625 | 02c521e4 | Iustin Pop | try:
|
1626 | 02c521e4 | Iustin Pop | nimg.mfree = int(hv_info["memory_free"]) |
1627 | 02c521e4 | Iustin Pop | except (ValueError, TypeError): |
1628 | 02c521e4 | Iustin Pop | _ErrorIf(True, self.ENODERPC, node, |
1629 | 02c521e4 | Iustin Pop | "node returned invalid nodeinfo, check hypervisor")
|
1630 | 02c521e4 | Iustin Pop | |
1631 | 02c521e4 | Iustin Pop | # FIXME: devise a free space model for file based instances as well
|
1632 | 02c521e4 | Iustin Pop | if vg_name is not None: |
1633 | 02c521e4 | Iustin Pop | test = (constants.NV_VGLIST not in nresult or |
1634 | 02c521e4 | Iustin Pop | vg_name not in nresult[constants.NV_VGLIST]) |
1635 | 02c521e4 | Iustin Pop | _ErrorIf(test, self.ENODELVM, node,
|
1636 | 02c521e4 | Iustin Pop | "node didn't return data for the volume group '%s'"
|
1637 | 02c521e4 | Iustin Pop | " - it is either missing or broken", vg_name)
|
1638 | 02c521e4 | Iustin Pop | if not test: |
1639 | 02c521e4 | Iustin Pop | try:
|
1640 | 02c521e4 | Iustin Pop | nimg.dfree = int(nresult[constants.NV_VGLIST][vg_name])
|
1641 | 02c521e4 | Iustin Pop | except (ValueError, TypeError): |
1642 | 02c521e4 | Iustin Pop | _ErrorIf(True, self.ENODERPC, node, |
1643 | 02c521e4 | Iustin Pop | "node returned invalid LVM info, check LVM status")
|
1644 | 02c521e4 | Iustin Pop | |
1645 | a8083063 | Iustin Pop | def CheckPrereq(self): |
1646 | a8083063 | Iustin Pop | """Check prerequisites.
|
1647 | a8083063 | Iustin Pop |
|
1648 | e54c4c5e | Guido Trotter | Transform the list of checks we're going to skip into a set and check that
|
1649 | e54c4c5e | Guido Trotter | all its members are valid.
|
1650 | a8083063 | Iustin Pop |
|
1651 | a8083063 | Iustin Pop | """
|
1652 | e54c4c5e | Guido Trotter | self.skip_set = frozenset(self.op.skip_checks) |
1653 | e54c4c5e | Guido Trotter | if not constants.VERIFY_OPTIONAL_CHECKS.issuperset(self.skip_set): |
1654 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid checks to be skipped specified", |
1655 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
1656 | a8083063 | Iustin Pop | |
1657 | d8fff41c | Guido Trotter | def BuildHooksEnv(self): |
1658 | d8fff41c | Guido Trotter | """Build hooks env.
|
1659 | d8fff41c | Guido Trotter |
|
1660 | 5bbd3f7f | Michael Hanselmann | Cluster-Verify hooks just ran in the post phase and their failure makes
|
1661 | d8fff41c | Guido Trotter | the output be logged in the verify output and the verification to fail.
|
1662 | d8fff41c | Guido Trotter |
|
1663 | d8fff41c | Guido Trotter | """
|
1664 | d8fff41c | Guido Trotter | all_nodes = self.cfg.GetNodeList()
|
1665 | 35e994e9 | Iustin Pop | env = { |
1666 | 35e994e9 | Iustin Pop | "CLUSTER_TAGS": " ".join(self.cfg.GetClusterInfo().GetTags()) |
1667 | 35e994e9 | Iustin Pop | } |
1668 | 35e994e9 | Iustin Pop | for node in self.cfg.GetAllNodesInfo().values(): |
1669 | 35e994e9 | Iustin Pop | env["NODE_TAGS_%s" % node.name] = " ".join(node.GetTags()) |
1670 | 35e994e9 | Iustin Pop | |
1671 | d8fff41c | Guido Trotter | return env, [], all_nodes
|
1672 | d8fff41c | Guido Trotter | |
1673 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1674 | a8083063 | Iustin Pop | """Verify integrity of cluster, performing various test on nodes.
|
1675 | a8083063 | Iustin Pop |
|
1676 | a8083063 | Iustin Pop | """
|
1677 | a0c9776a | Iustin Pop | self.bad = False |
1678 | 7260cfbe | Iustin Pop | _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103 |
1679 | 7c874ee1 | Iustin Pop | verbose = self.op.verbose
|
1680 | 7c874ee1 | Iustin Pop | self._feedback_fn = feedback_fn
|
1681 | a8083063 | Iustin Pop | feedback_fn("* Verifying global settings")
|
1682 | 8522ceeb | Iustin Pop | for msg in self.cfg.VerifyConfig(): |
1683 | a0c9776a | Iustin Pop | _ErrorIf(True, self.ECLUSTERCFG, None, msg) |
1684 | a8083063 | Iustin Pop | |
1685 | b98bf262 | Michael Hanselmann | # Check the cluster certificates
|
1686 | b98bf262 | Michael Hanselmann | for cert_filename in constants.ALL_CERT_FILES: |
1687 | b98bf262 | Michael Hanselmann | (errcode, msg) = _VerifyCertificate(cert_filename) |
1688 | b98bf262 | Michael Hanselmann | _ErrorIf(errcode, self.ECLUSTERCERT, None, msg, code=errcode) |
1689 | b98bf262 | Michael Hanselmann | |
1690 | a8083063 | Iustin Pop | vg_name = self.cfg.GetVGName()
|
1691 | e69d05fd | Iustin Pop | hypervisors = self.cfg.GetClusterInfo().enabled_hypervisors
|
1692 | 58385fad | Iustin Pop | cluster = self.cfg.GetClusterInfo()
|
1693 | a8083063 | Iustin Pop | nodelist = utils.NiceSort(self.cfg.GetNodeList())
|
1694 | 9d4bfc96 | Iustin Pop | nodeinfo = [self.cfg.GetNodeInfo(nname) for nname in nodelist] |
1695 | a8083063 | Iustin Pop | instancelist = utils.NiceSort(self.cfg.GetInstanceList())
|
1696 | 6d2e83d5 | Iustin Pop | instanceinfo = dict((iname, self.cfg.GetInstanceInfo(iname)) |
1697 | 6d2e83d5 | Iustin Pop | for iname in instancelist) |
1698 | 93e4c50b | Guido Trotter | i_non_redundant = [] # Non redundant instances
|
1699 | 3924700f | Iustin Pop | i_non_a_balanced = [] # Non auto-balanced instances
|
1700 | 02c521e4 | Iustin Pop | n_offline = 0 # Count of offline nodes |
1701 | 02c521e4 | Iustin Pop | n_drained = 0 # Count of nodes being drained |
1702 | 02c521e4 | Iustin Pop | node_vol_should = {} |
1703 | a8083063 | Iustin Pop | |
1704 | a8083063 | Iustin Pop | # FIXME: verify OS list
|
1705 | a8083063 | Iustin Pop | # do local checksums
|
1706 | 112f18a5 | Iustin Pop | master_files = [constants.CLUSTER_CONF_FILE] |
1707 | 112f18a5 | Iustin Pop | |
1708 | 112f18a5 | Iustin Pop | file_names = ssconf.SimpleStore().GetFileList() |
1709 | d3100055 | Michael Hanselmann | file_names.extend(constants.ALL_CERT_FILES) |
1710 | 112f18a5 | Iustin Pop | file_names.extend(master_files) |
1711 | 58385fad | Iustin Pop | if cluster.modify_etc_hosts:
|
1712 | 58385fad | Iustin Pop | file_names.append(constants.ETC_HOSTS) |
1713 | 112f18a5 | Iustin Pop | |
1714 | a8083063 | Iustin Pop | local_checksums = utils.FingerprintFiles(file_names) |
1715 | a8083063 | Iustin Pop | |
1716 | a8083063 | Iustin Pop | feedback_fn("* Gathering data (%d nodes)" % len(nodelist)) |
1717 | a8083063 | Iustin Pop | node_verify_param = { |
1718 | 25361b9a | Iustin Pop | constants.NV_FILELIST: file_names, |
1719 | 82e37788 | Iustin Pop | constants.NV_NODELIST: [node.name for node in nodeinfo |
1720 | 82e37788 | Iustin Pop | if not node.offline], |
1721 | 25361b9a | Iustin Pop | constants.NV_HYPERVISOR: hypervisors, |
1722 | 25361b9a | Iustin Pop | constants.NV_NODENETTEST: [(node.name, node.primary_ip, |
1723 | 82e37788 | Iustin Pop | node.secondary_ip) for node in nodeinfo |
1724 | 82e37788 | Iustin Pop | if not node.offline], |
1725 | 25361b9a | Iustin Pop | constants.NV_INSTANCELIST: hypervisors, |
1726 | 25361b9a | Iustin Pop | constants.NV_VERSION: None,
|
1727 | 25361b9a | Iustin Pop | constants.NV_HVINFO: self.cfg.GetHypervisorType(),
|
1728 | 7c0aa8e9 | Iustin Pop | constants.NV_NODESETUP: None,
|
1729 | 313b2dd4 | Michael Hanselmann | constants.NV_TIME: None,
|
1730 | a8083063 | Iustin Pop | } |
1731 | 313b2dd4 | Michael Hanselmann | |
1732 | cc9e1230 | Guido Trotter | if vg_name is not None: |
1733 | cc9e1230 | Guido Trotter | node_verify_param[constants.NV_VGLIST] = None
|
1734 | cc9e1230 | Guido Trotter | node_verify_param[constants.NV_LVLIST] = vg_name |
1735 | d091393e | Iustin Pop | node_verify_param[constants.NV_PVLIST] = [vg_name] |
1736 | cc9e1230 | Guido Trotter | node_verify_param[constants.NV_DRBDLIST] = None
|
1737 | 313b2dd4 | Michael Hanselmann | |
1738 | 02c521e4 | Iustin Pop | # Build our expected cluster state
|
1739 | 02c521e4 | Iustin Pop | node_image = dict((node.name, self.NodeImage(offline=node.offline)) |
1740 | 02c521e4 | Iustin Pop | for node in nodeinfo) |
1741 | 02c521e4 | Iustin Pop | |
1742 | 02c521e4 | Iustin Pop | for instance in instancelist: |
1743 | 02c521e4 | Iustin Pop | inst_config = instanceinfo[instance] |
1744 | 02c521e4 | Iustin Pop | |
1745 | 02c521e4 | Iustin Pop | for nname in inst_config.all_nodes: |
1746 | 02c521e4 | Iustin Pop | if nname not in node_image: |
1747 | 02c521e4 | Iustin Pop | # ghost node
|
1748 | 02c521e4 | Iustin Pop | gnode = self.NodeImage()
|
1749 | 02c521e4 | Iustin Pop | gnode.ghost = True
|
1750 | 02c521e4 | Iustin Pop | node_image[nname] = gnode |
1751 | 02c521e4 | Iustin Pop | |
1752 | 02c521e4 | Iustin Pop | inst_config.MapLVsByNode(node_vol_should) |
1753 | 02c521e4 | Iustin Pop | |
1754 | 02c521e4 | Iustin Pop | pnode = inst_config.primary_node |
1755 | 02c521e4 | Iustin Pop | node_image[pnode].pinst.append(instance) |
1756 | 02c521e4 | Iustin Pop | |
1757 | 02c521e4 | Iustin Pop | for snode in inst_config.secondary_nodes: |
1758 | 02c521e4 | Iustin Pop | nimg = node_image[snode] |
1759 | 02c521e4 | Iustin Pop | nimg.sinst.append(instance) |
1760 | 02c521e4 | Iustin Pop | if pnode not in nimg.sbp: |
1761 | 02c521e4 | Iustin Pop | nimg.sbp[pnode] = [] |
1762 | 02c521e4 | Iustin Pop | nimg.sbp[pnode].append(instance) |
1763 | 02c521e4 | Iustin Pop | |
1764 | 02c521e4 | Iustin Pop | # At this point, we have the in-memory data structures complete,
|
1765 | 02c521e4 | Iustin Pop | # except for the runtime information, which we'll gather next
|
1766 | 02c521e4 | Iustin Pop | |
1767 | 313b2dd4 | Michael Hanselmann | # Due to the way our RPC system works, exact response times cannot be
|
1768 | 313b2dd4 | Michael Hanselmann | # guaranteed (e.g. a broken node could run into a timeout). By keeping the
|
1769 | 313b2dd4 | Michael Hanselmann | # time before and after executing the request, we can at least have a time
|
1770 | 313b2dd4 | Michael Hanselmann | # window.
|
1771 | 313b2dd4 | Michael Hanselmann | nvinfo_starttime = time.time() |
1772 | 72737a7f | Iustin Pop | all_nvinfo = self.rpc.call_node_verify(nodelist, node_verify_param,
|
1773 | 72737a7f | Iustin Pop | self.cfg.GetClusterName())
|
1774 | 313b2dd4 | Michael Hanselmann | nvinfo_endtime = time.time() |
1775 | a8083063 | Iustin Pop | |
1776 | 112f18a5 | Iustin Pop | master_node = self.cfg.GetMasterNode()
|
1777 | 6d2e83d5 | Iustin Pop | all_drbd_map = self.cfg.ComputeDRBDMap()
|
1778 | 6d2e83d5 | Iustin Pop | |
1779 | 7c874ee1 | Iustin Pop | feedback_fn("* Verifying node status")
|
1780 | 112f18a5 | Iustin Pop | for node_i in nodeinfo: |
1781 | 112f18a5 | Iustin Pop | node = node_i.name |
1782 | 02c521e4 | Iustin Pop | nimg = node_image[node] |
1783 | 25361b9a | Iustin Pop | |
1784 | 0a66c968 | Iustin Pop | if node_i.offline:
|
1785 | 7c874ee1 | Iustin Pop | if verbose:
|
1786 | 7c874ee1 | Iustin Pop | feedback_fn("* Skipping offline node %s" % (node,))
|
1787 | 02c521e4 | Iustin Pop | n_offline += 1
|
1788 | 0a66c968 | Iustin Pop | continue
|
1789 | 0a66c968 | Iustin Pop | |
1790 | 112f18a5 | Iustin Pop | if node == master_node:
|
1791 | 25361b9a | Iustin Pop | ntype = "master"
|
1792 | 112f18a5 | Iustin Pop | elif node_i.master_candidate:
|
1793 | 25361b9a | Iustin Pop | ntype = "master candidate"
|
1794 | 22f0f71d | Iustin Pop | elif node_i.drained:
|
1795 | 22f0f71d | Iustin Pop | ntype = "drained"
|
1796 | 02c521e4 | Iustin Pop | n_drained += 1
|
1797 | 112f18a5 | Iustin Pop | else:
|
1798 | 25361b9a | Iustin Pop | ntype = "regular"
|
1799 | 7c874ee1 | Iustin Pop | if verbose:
|
1800 | 7c874ee1 | Iustin Pop | feedback_fn("* Verifying node %s (%s)" % (node, ntype))
|
1801 | 25361b9a | Iustin Pop | |
1802 | 4c4e4e1e | Iustin Pop | msg = all_nvinfo[node].fail_msg |
1803 | a0c9776a | Iustin Pop | _ErrorIf(msg, self.ENODERPC, node, "while contacting node: %s", msg) |
1804 | 6f68a739 | Iustin Pop | if msg:
|
1805 | 02c521e4 | Iustin Pop | nimg.rpc_fail = True
|
1806 | 25361b9a | Iustin Pop | continue
|
1807 | 25361b9a | Iustin Pop | |
1808 | 6f68a739 | Iustin Pop | nresult = all_nvinfo[node].payload |
1809 | a8083063 | Iustin Pop | |
1810 | 02c521e4 | Iustin Pop | nimg.call_ok = self._VerifyNode(node_i, nresult)
|
1811 | 02c521e4 | Iustin Pop | self._VerifyNodeNetwork(node_i, nresult)
|
1812 | 02c521e4 | Iustin Pop | self._VerifyNodeLVM(node_i, nresult, vg_name)
|
1813 | 02c521e4 | Iustin Pop | self._VerifyNodeFiles(node_i, nresult, file_names, local_checksums,
|
1814 | 02c521e4 | Iustin Pop | master_files) |
1815 | 02c521e4 | Iustin Pop | self._VerifyNodeDrbd(node_i, nresult, instanceinfo, all_drbd_map)
|
1816 | 02c521e4 | Iustin Pop | self._VerifyNodeTime(node_i, nresult, nvinfo_starttime, nvinfo_endtime)
|
1817 | a8083063 | Iustin Pop | |
1818 | 02c521e4 | Iustin Pop | self._UpdateNodeVolumes(node_i, nresult, nimg, vg_name)
|
1819 | 02c521e4 | Iustin Pop | self._UpdateNodeInstances(node_i, nresult, nimg)
|
1820 | 02c521e4 | Iustin Pop | self._UpdateNodeInfo(node_i, nresult, nimg, vg_name)
|
1821 | a8083063 | Iustin Pop | |
1822 | 7c874ee1 | Iustin Pop | feedback_fn("* Verifying instance status")
|
1823 | a8083063 | Iustin Pop | for instance in instancelist: |
1824 | 7c874ee1 | Iustin Pop | if verbose:
|
1825 | 7c874ee1 | Iustin Pop | feedback_fn("* Verifying instance %s" % instance)
|
1826 | 6d2e83d5 | Iustin Pop | inst_config = instanceinfo[instance] |
1827 | 02c521e4 | Iustin Pop | self._VerifyInstance(instance, inst_config, node_image)
|
1828 | 832261fd | Iustin Pop | inst_nodes_offline = [] |
1829 | a8083063 | Iustin Pop | |
1830 | 93e4c50b | Guido Trotter | pnode = inst_config.primary_node |
1831 | 02c521e4 | Iustin Pop | pnode_img = node_image[pnode] |
1832 | 02c521e4 | Iustin Pop | _ErrorIf(pnode_img.rpc_fail and not pnode_img.offline, |
1833 | a0c9776a | Iustin Pop | self.ENODERPC, pnode, "instance %s, connection to" |
1834 | a0c9776a | Iustin Pop | " primary node failed", instance)
|
1835 | 93e4c50b | Guido Trotter | |
1836 | 02c521e4 | Iustin Pop | if pnode_img.offline:
|
1837 | 832261fd | Iustin Pop | inst_nodes_offline.append(pnode) |
1838 | 832261fd | Iustin Pop | |
1839 | 93e4c50b | Guido Trotter | # If the instance is non-redundant we cannot survive losing its primary
|
1840 | 93e4c50b | Guido Trotter | # node, so we are not N+1 compliant. On the other hand we have no disk
|
1841 | 93e4c50b | Guido Trotter | # templates with more than one secondary so that situation is not well
|
1842 | 93e4c50b | Guido Trotter | # supported either.
|
1843 | 93e4c50b | Guido Trotter | # FIXME: does not support file-backed instances
|
1844 | 02c521e4 | Iustin Pop | if not inst_config.secondary_nodes: |
1845 | 93e4c50b | Guido Trotter | i_non_redundant.append(instance) |
1846 | 02c521e4 | Iustin Pop | _ErrorIf(len(inst_config.secondary_nodes) > 1, self.EINSTANCELAYOUT, |
1847 | 02c521e4 | Iustin Pop | instance, "instance has multiple secondary nodes: %s",
|
1848 | 02c521e4 | Iustin Pop | utils.CommaJoin(inst_config.secondary_nodes), |
1849 | 02c521e4 | Iustin Pop | code=self.ETYPE_WARNING)
|
1850 | 93e4c50b | Guido Trotter | |
1851 | c0f2b229 | Iustin Pop | if not cluster.FillBE(inst_config)[constants.BE_AUTO_BALANCE]: |
1852 | 3924700f | Iustin Pop | i_non_a_balanced.append(instance) |
1853 | 3924700f | Iustin Pop | |
1854 | 93e4c50b | Guido Trotter | for snode in inst_config.secondary_nodes: |
1855 | 02c521e4 | Iustin Pop | s_img = node_image[snode] |
1856 | 02c521e4 | Iustin Pop | _ErrorIf(s_img.rpc_fail and not s_img.offline, self.ENODERPC, snode, |
1857 | 02c521e4 | Iustin Pop | "instance %s, connection to secondary node failed", instance)
|
1858 | 02c521e4 | Iustin Pop | |
1859 | 02c521e4 | Iustin Pop | if s_img.offline:
|
1860 | 832261fd | Iustin Pop | inst_nodes_offline.append(snode) |
1861 | 832261fd | Iustin Pop | |
1862 | a0c9776a | Iustin Pop | # warn that the instance lives on offline nodes
|
1863 | a0c9776a | Iustin Pop | _ErrorIf(inst_nodes_offline, self.EINSTANCEBADNODE, instance,
|
1864 | a0c9776a | Iustin Pop | "instance lives on offline node(s) %s",
|
1865 | 1f864b60 | Iustin Pop | utils.CommaJoin(inst_nodes_offline)) |
1866 | 02c521e4 | Iustin Pop | # ... or ghost nodes
|
1867 | 02c521e4 | Iustin Pop | for node in inst_config.all_nodes: |
1868 | 02c521e4 | Iustin Pop | _ErrorIf(node_image[node].ghost, self.EINSTANCEBADNODE, instance,
|
1869 | 02c521e4 | Iustin Pop | "instance lives on ghost node %s", node)
|
1870 | 93e4c50b | Guido Trotter | |
1871 | a8083063 | Iustin Pop | feedback_fn("* Verifying orphan volumes")
|
1872 | 02c521e4 | Iustin Pop | self._VerifyOrphanVolumes(node_vol_should, node_image)
|
1873 | a8083063 | Iustin Pop | |
1874 | 02c521e4 | Iustin Pop | feedback_fn("* Verifying oprhan instances")
|
1875 | 02c521e4 | Iustin Pop | self._VerifyOrphanInstances(instancelist, node_image)
|
1876 | a8083063 | Iustin Pop | |
1877 | e54c4c5e | Guido Trotter | if constants.VERIFY_NPLUSONE_MEM not in self.skip_set: |
1878 | e54c4c5e | Guido Trotter | feedback_fn("* Verifying N+1 Memory redundancy")
|
1879 | 02c521e4 | Iustin Pop | self._VerifyNPlusOneMemory(node_image, instanceinfo)
|
1880 | 2b3b6ddd | Guido Trotter | |
1881 | 2b3b6ddd | Guido Trotter | feedback_fn("* Other Notes")
|
1882 | 2b3b6ddd | Guido Trotter | if i_non_redundant:
|
1883 | 2b3b6ddd | Guido Trotter | feedback_fn(" - NOTICE: %d non-redundant instance(s) found."
|
1884 | 2b3b6ddd | Guido Trotter | % len(i_non_redundant))
|
1885 | 2b3b6ddd | Guido Trotter | |
1886 | 3924700f | Iustin Pop | if i_non_a_balanced:
|
1887 | 3924700f | Iustin Pop | feedback_fn(" - NOTICE: %d non-auto-balanced instance(s) found."
|
1888 | 3924700f | Iustin Pop | % len(i_non_a_balanced))
|
1889 | 3924700f | Iustin Pop | |
1890 | 0a66c968 | Iustin Pop | if n_offline:
|
1891 | 02c521e4 | Iustin Pop | feedback_fn(" - NOTICE: %d offline node(s) found." % n_offline)
|
1892 | 0a66c968 | Iustin Pop | |
1893 | 22f0f71d | Iustin Pop | if n_drained:
|
1894 | 02c521e4 | Iustin Pop | feedback_fn(" - NOTICE: %d drained node(s) found." % n_drained)
|
1895 | 22f0f71d | Iustin Pop | |
1896 | a0c9776a | Iustin Pop | return not self.bad |
1897 | a8083063 | Iustin Pop | |
1898 | d8fff41c | Guido Trotter | def HooksCallBack(self, phase, hooks_results, feedback_fn, lu_result): |
1899 | 5bbd3f7f | Michael Hanselmann | """Analyze the post-hooks' result
|
1900 | e4376078 | Iustin Pop |
|
1901 | e4376078 | Iustin Pop | This method analyses the hook result, handles it, and sends some
|
1902 | d8fff41c | Guido Trotter | nicely-formatted feedback back to the user.
|
1903 | d8fff41c | Guido Trotter |
|
1904 | e4376078 | Iustin Pop | @param phase: one of L{constants.HOOKS_PHASE_POST} or
|
1905 | e4376078 | Iustin Pop | L{constants.HOOKS_PHASE_PRE}; it denotes the hooks phase
|
1906 | e4376078 | Iustin Pop | @param hooks_results: the results of the multi-node hooks rpc call
|
1907 | e4376078 | Iustin Pop | @param feedback_fn: function used send feedback back to the caller
|
1908 | e4376078 | Iustin Pop | @param lu_result: previous Exec result
|
1909 | e4376078 | Iustin Pop | @return: the new Exec result, based on the previous result
|
1910 | e4376078 | Iustin Pop | and hook results
|
1911 | d8fff41c | Guido Trotter |
|
1912 | d8fff41c | Guido Trotter | """
|
1913 | 38206f3c | Iustin Pop | # We only really run POST phase hooks, and are only interested in
|
1914 | 38206f3c | Iustin Pop | # their results
|
1915 | d8fff41c | Guido Trotter | if phase == constants.HOOKS_PHASE_POST:
|
1916 | d8fff41c | Guido Trotter | # Used to change hooks' output to proper indentation
|
1917 | d8fff41c | Guido Trotter | indent_re = re.compile('^', re.M)
|
1918 | d8fff41c | Guido Trotter | feedback_fn("* Hooks Results")
|
1919 | 7c874ee1 | Iustin Pop | assert hooks_results, "invalid result from hooks" |
1920 | 7c874ee1 | Iustin Pop | |
1921 | 7c874ee1 | Iustin Pop | for node_name in hooks_results: |
1922 | 7c874ee1 | Iustin Pop | res = hooks_results[node_name] |
1923 | 7c874ee1 | Iustin Pop | msg = res.fail_msg |
1924 | a0c9776a | Iustin Pop | test = msg and not res.offline |
1925 | a0c9776a | Iustin Pop | self._ErrorIf(test, self.ENODEHOOKS, node_name, |
1926 | 7c874ee1 | Iustin Pop | "Communication failure in hooks execution: %s", msg)
|
1927 | dd9e9f9c | Michael Hanselmann | if res.offline or msg: |
1928 | dd9e9f9c | Michael Hanselmann | # No need to investigate payload if node is offline or gave an error.
|
1929 | a0c9776a | Iustin Pop | # override manually lu_result here as _ErrorIf only
|
1930 | a0c9776a | Iustin Pop | # overrides self.bad
|
1931 | 7c874ee1 | Iustin Pop | lu_result = 1
|
1932 | 7c874ee1 | Iustin Pop | continue
|
1933 | 7c874ee1 | Iustin Pop | for script, hkr, output in res.payload: |
1934 | a0c9776a | Iustin Pop | test = hkr == constants.HKR_FAIL |
1935 | a0c9776a | Iustin Pop | self._ErrorIf(test, self.ENODEHOOKS, node_name, |
1936 | 7c874ee1 | Iustin Pop | "Script %s failed, output:", script)
|
1937 | a0c9776a | Iustin Pop | if test:
|
1938 | 7c874ee1 | Iustin Pop | output = indent_re.sub(' ', output)
|
1939 | 7c874ee1 | Iustin Pop | feedback_fn("%s" % output)
|
1940 | 6d7b472a | Iustin Pop | lu_result = 0
|
1941 | d8fff41c | Guido Trotter | |
1942 | d8fff41c | Guido Trotter | return lu_result
|
1943 | d8fff41c | Guido Trotter | |
1944 | a8083063 | Iustin Pop | |
1945 | 2c95a8d4 | Iustin Pop | class LUVerifyDisks(NoHooksLU): |
1946 | 2c95a8d4 | Iustin Pop | """Verifies the cluster disks status.
|
1947 | 2c95a8d4 | Iustin Pop |
|
1948 | 2c95a8d4 | Iustin Pop | """
|
1949 | 2c95a8d4 | Iustin Pop | _OP_REQP = [] |
1950 | d4b9d97f | Guido Trotter | REQ_BGL = False
|
1951 | d4b9d97f | Guido Trotter | |
1952 | d4b9d97f | Guido Trotter | def ExpandNames(self): |
1953 | d4b9d97f | Guido Trotter | self.needed_locks = {
|
1954 | d4b9d97f | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET, |
1955 | d4b9d97f | Guido Trotter | locking.LEVEL_INSTANCE: locking.ALL_SET, |
1956 | d4b9d97f | Guido Trotter | } |
1957 | c772d142 | Michael Hanselmann | self.share_locks = dict.fromkeys(locking.LEVELS, 1) |
1958 | 2c95a8d4 | Iustin Pop | |
1959 | 2c95a8d4 | Iustin Pop | def CheckPrereq(self): |
1960 | 2c95a8d4 | Iustin Pop | """Check prerequisites.
|
1961 | 2c95a8d4 | Iustin Pop |
|
1962 | 2c95a8d4 | Iustin Pop | This has no prerequisites.
|
1963 | 2c95a8d4 | Iustin Pop |
|
1964 | 2c95a8d4 | Iustin Pop | """
|
1965 | 2c95a8d4 | Iustin Pop | pass
|
1966 | 2c95a8d4 | Iustin Pop | |
1967 | 2c95a8d4 | Iustin Pop | def Exec(self, feedback_fn): |
1968 | 2c95a8d4 | Iustin Pop | """Verify integrity of cluster disks.
|
1969 | 2c95a8d4 | Iustin Pop |
|
1970 | 29d376ec | Iustin Pop | @rtype: tuple of three items
|
1971 | 29d376ec | Iustin Pop | @return: a tuple of (dict of node-to-node_error, list of instances
|
1972 | 29d376ec | Iustin Pop | which need activate-disks, dict of instance: (node, volume) for
|
1973 | 29d376ec | Iustin Pop | missing volumes
|
1974 | 29d376ec | Iustin Pop |
|
1975 | 2c95a8d4 | Iustin Pop | """
|
1976 | 29d376ec | Iustin Pop | result = res_nodes, res_instances, res_missing = {}, [], {} |
1977 | 2c95a8d4 | Iustin Pop | |
1978 | 2c95a8d4 | Iustin Pop | vg_name = self.cfg.GetVGName()
|
1979 | 2c95a8d4 | Iustin Pop | nodes = utils.NiceSort(self.cfg.GetNodeList())
|
1980 | 2c95a8d4 | Iustin Pop | instances = [self.cfg.GetInstanceInfo(name)
|
1981 | 2c95a8d4 | Iustin Pop | for name in self.cfg.GetInstanceList()] |
1982 | 2c95a8d4 | Iustin Pop | |
1983 | 2c95a8d4 | Iustin Pop | nv_dict = {} |
1984 | 2c95a8d4 | Iustin Pop | for inst in instances: |
1985 | 2c95a8d4 | Iustin Pop | inst_lvs = {} |
1986 | 0d68c45d | Iustin Pop | if (not inst.admin_up or |
1987 | 2c95a8d4 | Iustin Pop | inst.disk_template not in constants.DTS_NET_MIRROR): |
1988 | 2c95a8d4 | Iustin Pop | continue
|
1989 | 2c95a8d4 | Iustin Pop | inst.MapLVsByNode(inst_lvs) |
1990 | 2c95a8d4 | Iustin Pop | # transform { iname: {node: [vol,],},} to {(node, vol): iname}
|
1991 | 2c95a8d4 | Iustin Pop | for node, vol_list in inst_lvs.iteritems(): |
1992 | 2c95a8d4 | Iustin Pop | for vol in vol_list: |
1993 | 2c95a8d4 | Iustin Pop | nv_dict[(node, vol)] = inst |
1994 | 2c95a8d4 | Iustin Pop | |
1995 | 2c95a8d4 | Iustin Pop | if not nv_dict: |
1996 | 2c95a8d4 | Iustin Pop | return result
|
1997 | 2c95a8d4 | Iustin Pop | |
1998 | b2a6ccd4 | Iustin Pop | node_lvs = self.rpc.call_lv_list(nodes, vg_name)
|
1999 | 2c95a8d4 | Iustin Pop | |
2000 | 2c95a8d4 | Iustin Pop | for node in nodes: |
2001 | 2c95a8d4 | Iustin Pop | # node_volume
|
2002 | 29d376ec | Iustin Pop | node_res = node_lvs[node] |
2003 | 29d376ec | Iustin Pop | if node_res.offline:
|
2004 | ea9ddc07 | Iustin Pop | continue
|
2005 | 4c4e4e1e | Iustin Pop | msg = node_res.fail_msg |
2006 | 29d376ec | Iustin Pop | if msg:
|
2007 | 29d376ec | Iustin Pop | logging.warning("Error enumerating LVs on node %s: %s", node, msg)
|
2008 | 29d376ec | Iustin Pop | res_nodes[node] = msg |
2009 | 2c95a8d4 | Iustin Pop | continue
|
2010 | 2c95a8d4 | Iustin Pop | |
2011 | 29d376ec | Iustin Pop | lvs = node_res.payload |
2012 | 1122eb25 | Iustin Pop | for lv_name, (_, _, lv_online) in lvs.items(): |
2013 | b63ed789 | Iustin Pop | inst = nv_dict.pop((node, lv_name), None)
|
2014 | b63ed789 | Iustin Pop | if (not lv_online and inst is not None |
2015 | b63ed789 | Iustin Pop | and inst.name not in res_instances): |
2016 | b08d5a87 | Iustin Pop | res_instances.append(inst.name) |
2017 | 2c95a8d4 | Iustin Pop | |
2018 | b63ed789 | Iustin Pop | # any leftover items in nv_dict are missing LVs, let's arrange the
|
2019 | b63ed789 | Iustin Pop | # data better
|
2020 | b63ed789 | Iustin Pop | for key, inst in nv_dict.iteritems(): |
2021 | b63ed789 | Iustin Pop | if inst.name not in res_missing: |
2022 | b63ed789 | Iustin Pop | res_missing[inst.name] = [] |
2023 | b63ed789 | Iustin Pop | res_missing[inst.name].append(key) |
2024 | b63ed789 | Iustin Pop | |
2025 | 2c95a8d4 | Iustin Pop | return result
|
2026 | 2c95a8d4 | Iustin Pop | |
2027 | 2c95a8d4 | Iustin Pop | |
2028 | 60975797 | Iustin Pop | class LURepairDiskSizes(NoHooksLU): |
2029 | 60975797 | Iustin Pop | """Verifies the cluster disks sizes.
|
2030 | 60975797 | Iustin Pop |
|
2031 | 60975797 | Iustin Pop | """
|
2032 | 60975797 | Iustin Pop | _OP_REQP = ["instances"]
|
2033 | 60975797 | Iustin Pop | REQ_BGL = False
|
2034 | 60975797 | Iustin Pop | |
2035 | 60975797 | Iustin Pop | def ExpandNames(self): |
2036 | 60975797 | Iustin Pop | if not isinstance(self.op.instances, list): |
2037 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid argument type 'instances'", |
2038 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2039 | 60975797 | Iustin Pop | |
2040 | 60975797 | Iustin Pop | if self.op.instances: |
2041 | 60975797 | Iustin Pop | self.wanted_names = []
|
2042 | 60975797 | Iustin Pop | for name in self.op.instances: |
2043 | cf26a87a | Iustin Pop | full_name = _ExpandInstanceName(self.cfg, name)
|
2044 | 60975797 | Iustin Pop | self.wanted_names.append(full_name)
|
2045 | 60975797 | Iustin Pop | self.needed_locks = {
|
2046 | 60975797 | Iustin Pop | locking.LEVEL_NODE: [], |
2047 | 60975797 | Iustin Pop | locking.LEVEL_INSTANCE: self.wanted_names,
|
2048 | 60975797 | Iustin Pop | } |
2049 | 60975797 | Iustin Pop | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
2050 | 60975797 | Iustin Pop | else:
|
2051 | 60975797 | Iustin Pop | self.wanted_names = None |
2052 | 60975797 | Iustin Pop | self.needed_locks = {
|
2053 | 60975797 | Iustin Pop | locking.LEVEL_NODE: locking.ALL_SET, |
2054 | 60975797 | Iustin Pop | locking.LEVEL_INSTANCE: locking.ALL_SET, |
2055 | 60975797 | Iustin Pop | } |
2056 | 60975797 | Iustin Pop | self.share_locks = dict(((i, 1) for i in locking.LEVELS)) |
2057 | 60975797 | Iustin Pop | |
2058 | 60975797 | Iustin Pop | def DeclareLocks(self, level): |
2059 | 60975797 | Iustin Pop | if level == locking.LEVEL_NODE and self.wanted_names is not None: |
2060 | 60975797 | Iustin Pop | self._LockInstancesNodes(primary_only=True) |
2061 | 60975797 | Iustin Pop | |
2062 | 60975797 | Iustin Pop | def CheckPrereq(self): |
2063 | 60975797 | Iustin Pop | """Check prerequisites.
|
2064 | 60975797 | Iustin Pop |
|
2065 | 60975797 | Iustin Pop | This only checks the optional instance list against the existing names.
|
2066 | 60975797 | Iustin Pop |
|
2067 | 60975797 | Iustin Pop | """
|
2068 | 60975797 | Iustin Pop | if self.wanted_names is None: |
2069 | 60975797 | Iustin Pop | self.wanted_names = self.acquired_locks[locking.LEVEL_INSTANCE] |
2070 | 60975797 | Iustin Pop | |
2071 | 60975797 | Iustin Pop | self.wanted_instances = [self.cfg.GetInstanceInfo(name) for name |
2072 | 60975797 | Iustin Pop | in self.wanted_names] |
2073 | 60975797 | Iustin Pop | |
2074 | b775c337 | Iustin Pop | def _EnsureChildSizes(self, disk): |
2075 | b775c337 | Iustin Pop | """Ensure children of the disk have the needed disk size.
|
2076 | b775c337 | Iustin Pop |
|
2077 | b775c337 | Iustin Pop | This is valid mainly for DRBD8 and fixes an issue where the
|
2078 | b775c337 | Iustin Pop | children have smaller disk size.
|
2079 | b775c337 | Iustin Pop |
|
2080 | b775c337 | Iustin Pop | @param disk: an L{ganeti.objects.Disk} object
|
2081 | b775c337 | Iustin Pop |
|
2082 | b775c337 | Iustin Pop | """
|
2083 | b775c337 | Iustin Pop | if disk.dev_type == constants.LD_DRBD8:
|
2084 | b775c337 | Iustin Pop | assert disk.children, "Empty children for DRBD8?" |
2085 | b775c337 | Iustin Pop | fchild = disk.children[0]
|
2086 | b775c337 | Iustin Pop | mismatch = fchild.size < disk.size |
2087 | b775c337 | Iustin Pop | if mismatch:
|
2088 | b775c337 | Iustin Pop | self.LogInfo("Child disk has size %d, parent %d, fixing", |
2089 | b775c337 | Iustin Pop | fchild.size, disk.size) |
2090 | b775c337 | Iustin Pop | fchild.size = disk.size |
2091 | b775c337 | Iustin Pop | |
2092 | b775c337 | Iustin Pop | # and we recurse on this child only, not on the metadev
|
2093 | b775c337 | Iustin Pop | return self._EnsureChildSizes(fchild) or mismatch |
2094 | b775c337 | Iustin Pop | else:
|
2095 | b775c337 | Iustin Pop | return False |
2096 | b775c337 | Iustin Pop | |
2097 | 60975797 | Iustin Pop | def Exec(self, feedback_fn): |
2098 | 60975797 | Iustin Pop | """Verify the size of cluster disks.
|
2099 | 60975797 | Iustin Pop |
|
2100 | 60975797 | Iustin Pop | """
|
2101 | 60975797 | Iustin Pop | # TODO: check child disks too
|
2102 | 60975797 | Iustin Pop | # TODO: check differences in size between primary/secondary nodes
|
2103 | 60975797 | Iustin Pop | per_node_disks = {} |
2104 | 60975797 | Iustin Pop | for instance in self.wanted_instances: |
2105 | 60975797 | Iustin Pop | pnode = instance.primary_node |
2106 | 60975797 | Iustin Pop | if pnode not in per_node_disks: |
2107 | 60975797 | Iustin Pop | per_node_disks[pnode] = [] |
2108 | 60975797 | Iustin Pop | for idx, disk in enumerate(instance.disks): |
2109 | 60975797 | Iustin Pop | per_node_disks[pnode].append((instance, idx, disk)) |
2110 | 60975797 | Iustin Pop | |
2111 | 60975797 | Iustin Pop | changed = [] |
2112 | 60975797 | Iustin Pop | for node, dskl in per_node_disks.items(): |
2113 | 4d9e6835 | Iustin Pop | newl = [v[2].Copy() for v in dskl] |
2114 | 4d9e6835 | Iustin Pop | for dsk in newl: |
2115 | 4d9e6835 | Iustin Pop | self.cfg.SetDiskID(dsk, node)
|
2116 | 4d9e6835 | Iustin Pop | result = self.rpc.call_blockdev_getsizes(node, newl)
|
2117 | 3cebe102 | Michael Hanselmann | if result.fail_msg:
|
2118 | 60975797 | Iustin Pop | self.LogWarning("Failure in blockdev_getsizes call to node" |
2119 | 60975797 | Iustin Pop | " %s, ignoring", node)
|
2120 | 60975797 | Iustin Pop | continue
|
2121 | 60975797 | Iustin Pop | if len(result.data) != len(dskl): |
2122 | 60975797 | Iustin Pop | self.LogWarning("Invalid result from node %s, ignoring node results", |
2123 | 60975797 | Iustin Pop | node) |
2124 | 60975797 | Iustin Pop | continue
|
2125 | 60975797 | Iustin Pop | for ((instance, idx, disk), size) in zip(dskl, result.data): |
2126 | 60975797 | Iustin Pop | if size is None: |
2127 | 60975797 | Iustin Pop | self.LogWarning("Disk %d of instance %s did not return size" |
2128 | 60975797 | Iustin Pop | " information, ignoring", idx, instance.name)
|
2129 | 60975797 | Iustin Pop | continue
|
2130 | 60975797 | Iustin Pop | if not isinstance(size, (int, long)): |
2131 | 60975797 | Iustin Pop | self.LogWarning("Disk %d of instance %s did not return valid" |
2132 | 60975797 | Iustin Pop | " size information, ignoring", idx, instance.name)
|
2133 | 60975797 | Iustin Pop | continue
|
2134 | 60975797 | Iustin Pop | size = size >> 20
|
2135 | 60975797 | Iustin Pop | if size != disk.size:
|
2136 | 60975797 | Iustin Pop | self.LogInfo("Disk %d of instance %s has mismatched size," |
2137 | 60975797 | Iustin Pop | " correcting: recorded %d, actual %d", idx,
|
2138 | 60975797 | Iustin Pop | instance.name, disk.size, size) |
2139 | 60975797 | Iustin Pop | disk.size = size |
2140 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, feedback_fn)
|
2141 | 60975797 | Iustin Pop | changed.append((instance.name, idx, size)) |
2142 | b775c337 | Iustin Pop | if self._EnsureChildSizes(disk): |
2143 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, feedback_fn)
|
2144 | b775c337 | Iustin Pop | changed.append((instance.name, idx, disk.size)) |
2145 | 60975797 | Iustin Pop | return changed
|
2146 | 60975797 | Iustin Pop | |
2147 | 60975797 | Iustin Pop | |
2148 | 07bd8a51 | Iustin Pop | class LURenameCluster(LogicalUnit): |
2149 | 07bd8a51 | Iustin Pop | """Rename the cluster.
|
2150 | 07bd8a51 | Iustin Pop |
|
2151 | 07bd8a51 | Iustin Pop | """
|
2152 | 07bd8a51 | Iustin Pop | HPATH = "cluster-rename"
|
2153 | 07bd8a51 | Iustin Pop | HTYPE = constants.HTYPE_CLUSTER |
2154 | 07bd8a51 | Iustin Pop | _OP_REQP = ["name"]
|
2155 | 07bd8a51 | Iustin Pop | |
2156 | 07bd8a51 | Iustin Pop | def BuildHooksEnv(self): |
2157 | 07bd8a51 | Iustin Pop | """Build hooks env.
|
2158 | 07bd8a51 | Iustin Pop |
|
2159 | 07bd8a51 | Iustin Pop | """
|
2160 | 07bd8a51 | Iustin Pop | env = { |
2161 | d6a02168 | Michael Hanselmann | "OP_TARGET": self.cfg.GetClusterName(), |
2162 | 07bd8a51 | Iustin Pop | "NEW_NAME": self.op.name, |
2163 | 07bd8a51 | Iustin Pop | } |
2164 | d6a02168 | Michael Hanselmann | mn = self.cfg.GetMasterNode()
|
2165 | 47a72f18 | Iustin Pop | all_nodes = self.cfg.GetNodeList()
|
2166 | 47a72f18 | Iustin Pop | return env, [mn], all_nodes
|
2167 | 07bd8a51 | Iustin Pop | |
2168 | 07bd8a51 | Iustin Pop | def CheckPrereq(self): |
2169 | 07bd8a51 | Iustin Pop | """Verify that the passed name is a valid one.
|
2170 | 07bd8a51 | Iustin Pop |
|
2171 | 07bd8a51 | Iustin Pop | """
|
2172 | 104f4ca1 | Iustin Pop | hostname = utils.GetHostInfo(self.op.name)
|
2173 | 07bd8a51 | Iustin Pop | |
2174 | bcf043c9 | Iustin Pop | new_name = hostname.name |
2175 | bcf043c9 | Iustin Pop | self.ip = new_ip = hostname.ip
|
2176 | d6a02168 | Michael Hanselmann | old_name = self.cfg.GetClusterName()
|
2177 | d6a02168 | Michael Hanselmann | old_ip = self.cfg.GetMasterIP()
|
2178 | 07bd8a51 | Iustin Pop | if new_name == old_name and new_ip == old_ip: |
2179 | 07bd8a51 | Iustin Pop | raise errors.OpPrereqError("Neither the name nor the IP address of the" |
2180 | 5c983ee5 | Iustin Pop | " cluster has changed",
|
2181 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2182 | 07bd8a51 | Iustin Pop | if new_ip != old_ip:
|
2183 | 937f983d | Guido Trotter | if utils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
|
2184 | 07bd8a51 | Iustin Pop | raise errors.OpPrereqError("The given cluster IP address (%s) is" |
2185 | 07bd8a51 | Iustin Pop | " reachable on the network. Aborting." %
|
2186 | 5c983ee5 | Iustin Pop | new_ip, errors.ECODE_NOTUNIQUE) |
2187 | 07bd8a51 | Iustin Pop | |
2188 | 07bd8a51 | Iustin Pop | self.op.name = new_name
|
2189 | 07bd8a51 | Iustin Pop | |
2190 | 07bd8a51 | Iustin Pop | def Exec(self, feedback_fn): |
2191 | 07bd8a51 | Iustin Pop | """Rename the cluster.
|
2192 | 07bd8a51 | Iustin Pop |
|
2193 | 07bd8a51 | Iustin Pop | """
|
2194 | 07bd8a51 | Iustin Pop | clustername = self.op.name
|
2195 | 07bd8a51 | Iustin Pop | ip = self.ip
|
2196 | 07bd8a51 | Iustin Pop | |
2197 | 07bd8a51 | Iustin Pop | # shutdown the master IP
|
2198 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
2199 | 781de953 | Iustin Pop | result = self.rpc.call_node_stop_master(master, False) |
2200 | 4c4e4e1e | Iustin Pop | result.Raise("Could not disable the master role")
|
2201 | 07bd8a51 | Iustin Pop | |
2202 | 07bd8a51 | Iustin Pop | try:
|
2203 | 55cf7d83 | Iustin Pop | cluster = self.cfg.GetClusterInfo()
|
2204 | 55cf7d83 | Iustin Pop | cluster.cluster_name = clustername |
2205 | 55cf7d83 | Iustin Pop | cluster.master_ip = ip |
2206 | a4eae71f | Michael Hanselmann | self.cfg.Update(cluster, feedback_fn)
|
2207 | ec85e3d5 | Iustin Pop | |
2208 | ec85e3d5 | Iustin Pop | # update the known hosts file
|
2209 | ec85e3d5 | Iustin Pop | ssh.WriteKnownHostsFile(self.cfg, constants.SSH_KNOWN_HOSTS_FILE)
|
2210 | ec85e3d5 | Iustin Pop | node_list = self.cfg.GetNodeList()
|
2211 | ec85e3d5 | Iustin Pop | try:
|
2212 | ec85e3d5 | Iustin Pop | node_list.remove(master) |
2213 | ec85e3d5 | Iustin Pop | except ValueError: |
2214 | ec85e3d5 | Iustin Pop | pass
|
2215 | ec85e3d5 | Iustin Pop | result = self.rpc.call_upload_file(node_list,
|
2216 | ec85e3d5 | Iustin Pop | constants.SSH_KNOWN_HOSTS_FILE) |
2217 | ec85e3d5 | Iustin Pop | for to_node, to_result in result.iteritems(): |
2218 | 6f7d4e75 | Iustin Pop | msg = to_result.fail_msg |
2219 | 6f7d4e75 | Iustin Pop | if msg:
|
2220 | 6f7d4e75 | Iustin Pop | msg = ("Copy of file %s to node %s failed: %s" %
|
2221 | 6f7d4e75 | Iustin Pop | (constants.SSH_KNOWN_HOSTS_FILE, to_node, msg)) |
2222 | 6f7d4e75 | Iustin Pop | self.proc.LogWarning(msg)
|
2223 | ec85e3d5 | Iustin Pop | |
2224 | 07bd8a51 | Iustin Pop | finally:
|
2225 | 3583908a | Guido Trotter | result = self.rpc.call_node_start_master(master, False, False) |
2226 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
2227 | b726aff0 | Iustin Pop | if msg:
|
2228 | 86d9d3bb | Iustin Pop | self.LogWarning("Could not re-enable the master role on" |
2229 | b726aff0 | Iustin Pop | " the master, please restart manually: %s", msg)
|
2230 | 07bd8a51 | Iustin Pop | |
2231 | 07bd8a51 | Iustin Pop | |
2232 | 8084f9f6 | Manuel Franceschini | def _RecursiveCheckIfLVMBased(disk): |
2233 | 8084f9f6 | Manuel Franceschini | """Check if the given disk or its children are lvm-based.
|
2234 | 8084f9f6 | Manuel Franceschini |
|
2235 | e4376078 | Iustin Pop | @type disk: L{objects.Disk}
|
2236 | e4376078 | Iustin Pop | @param disk: the disk to check
|
2237 | 5bbd3f7f | Michael Hanselmann | @rtype: boolean
|
2238 | e4376078 | Iustin Pop | @return: boolean indicating whether a LD_LV dev_type was found or not
|
2239 | 8084f9f6 | Manuel Franceschini |
|
2240 | 8084f9f6 | Manuel Franceschini | """
|
2241 | 8084f9f6 | Manuel Franceschini | if disk.children:
|
2242 | 8084f9f6 | Manuel Franceschini | for chdisk in disk.children: |
2243 | 8084f9f6 | Manuel Franceschini | if _RecursiveCheckIfLVMBased(chdisk):
|
2244 | 8084f9f6 | Manuel Franceschini | return True |
2245 | 8084f9f6 | Manuel Franceschini | return disk.dev_type == constants.LD_LV
|
2246 | 8084f9f6 | Manuel Franceschini | |
2247 | 8084f9f6 | Manuel Franceschini | |
2248 | 8084f9f6 | Manuel Franceschini | class LUSetClusterParams(LogicalUnit): |
2249 | 8084f9f6 | Manuel Franceschini | """Change the parameters of the cluster.
|
2250 | 8084f9f6 | Manuel Franceschini |
|
2251 | 8084f9f6 | Manuel Franceschini | """
|
2252 | 8084f9f6 | Manuel Franceschini | HPATH = "cluster-modify"
|
2253 | 8084f9f6 | Manuel Franceschini | HTYPE = constants.HTYPE_CLUSTER |
2254 | 8084f9f6 | Manuel Franceschini | _OP_REQP = [] |
2255 | c53279cf | Guido Trotter | REQ_BGL = False
|
2256 | c53279cf | Guido Trotter | |
2257 | 3994f455 | Iustin Pop | def CheckArguments(self): |
2258 | 4b7735f9 | Iustin Pop | """Check parameters
|
2259 | 4b7735f9 | Iustin Pop |
|
2260 | 4b7735f9 | Iustin Pop | """
|
2261 | 96d1a0c5 | Iustin Pop | for attr in ["candidate_pool_size", |
2262 | 96d1a0c5 | Iustin Pop | "uid_pool", "add_uids", "remove_uids"]: |
2263 | 96d1a0c5 | Iustin Pop | if not hasattr(self.op, attr): |
2264 | 96d1a0c5 | Iustin Pop | setattr(self.op, attr, None) |
2265 | 96d1a0c5 | Iustin Pop | |
2266 | 4b7735f9 | Iustin Pop | if self.op.candidate_pool_size is not None: |
2267 | 4b7735f9 | Iustin Pop | try:
|
2268 | 4b7735f9 | Iustin Pop | self.op.candidate_pool_size = int(self.op.candidate_pool_size) |
2269 | 3994f455 | Iustin Pop | except (ValueError, TypeError), err: |
2270 | 4b7735f9 | Iustin Pop | raise errors.OpPrereqError("Invalid candidate_pool_size value: %s" % |
2271 | 5c983ee5 | Iustin Pop | str(err), errors.ECODE_INVAL)
|
2272 | 4b7735f9 | Iustin Pop | if self.op.candidate_pool_size < 1: |
2273 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("At least one master candidate needed", |
2274 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2275 | 1338f2b4 | Balazs Lecz | |
2276 | 3953242f | Iustin Pop | _CheckBooleanOpField(self.op, "maintain_node_health") |
2277 | 4b7735f9 | Iustin Pop | |
2278 | 1338f2b4 | Balazs Lecz | if self.op.uid_pool: |
2279 | 1338f2b4 | Balazs Lecz | uidpool.CheckUidPool(self.op.uid_pool)
|
2280 | 1338f2b4 | Balazs Lecz | |
2281 | fdad8c4d | Balazs Lecz | if self.op.add_uids: |
2282 | fdad8c4d | Balazs Lecz | uidpool.CheckUidPool(self.op.add_uids)
|
2283 | fdad8c4d | Balazs Lecz | |
2284 | fdad8c4d | Balazs Lecz | if self.op.remove_uids: |
2285 | fdad8c4d | Balazs Lecz | uidpool.CheckUidPool(self.op.remove_uids)
|
2286 | fdad8c4d | Balazs Lecz | |
2287 | c53279cf | Guido Trotter | def ExpandNames(self): |
2288 | c53279cf | Guido Trotter | # FIXME: in the future maybe other cluster params won't require checking on
|
2289 | c53279cf | Guido Trotter | # all nodes to be modified.
|
2290 | c53279cf | Guido Trotter | self.needed_locks = {
|
2291 | c53279cf | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET, |
2292 | c53279cf | Guido Trotter | } |
2293 | c53279cf | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
2294 | 8084f9f6 | Manuel Franceschini | |
2295 | 8084f9f6 | Manuel Franceschini | def BuildHooksEnv(self): |
2296 | 8084f9f6 | Manuel Franceschini | """Build hooks env.
|
2297 | 8084f9f6 | Manuel Franceschini |
|
2298 | 8084f9f6 | Manuel Franceschini | """
|
2299 | 8084f9f6 | Manuel Franceschini | env = { |
2300 | d6a02168 | Michael Hanselmann | "OP_TARGET": self.cfg.GetClusterName(), |
2301 | 8084f9f6 | Manuel Franceschini | "NEW_VG_NAME": self.op.vg_name, |
2302 | 8084f9f6 | Manuel Franceschini | } |
2303 | d6a02168 | Michael Hanselmann | mn = self.cfg.GetMasterNode()
|
2304 | 8084f9f6 | Manuel Franceschini | return env, [mn], [mn]
|
2305 | 8084f9f6 | Manuel Franceschini | |
2306 | 8084f9f6 | Manuel Franceschini | def CheckPrereq(self): |
2307 | 8084f9f6 | Manuel Franceschini | """Check prerequisites.
|
2308 | 8084f9f6 | Manuel Franceschini |
|
2309 | 8084f9f6 | Manuel Franceschini | This checks whether the given params don't conflict and
|
2310 | 5f83e263 | Iustin Pop | if the given volume group is valid.
|
2311 | 8084f9f6 | Manuel Franceschini |
|
2312 | 8084f9f6 | Manuel Franceschini | """
|
2313 | 779c15bb | Iustin Pop | if self.op.vg_name is not None and not self.op.vg_name: |
2314 | c53279cf | Guido Trotter | instances = self.cfg.GetAllInstancesInfo().values()
|
2315 | 8084f9f6 | Manuel Franceschini | for inst in instances: |
2316 | 8084f9f6 | Manuel Franceschini | for disk in inst.disks: |
2317 | 8084f9f6 | Manuel Franceschini | if _RecursiveCheckIfLVMBased(disk):
|
2318 | 8084f9f6 | Manuel Franceschini | raise errors.OpPrereqError("Cannot disable lvm storage while" |
2319 | 5c983ee5 | Iustin Pop | " lvm-based instances exist",
|
2320 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2321 | 8084f9f6 | Manuel Franceschini | |
2322 | 779c15bb | Iustin Pop | node_list = self.acquired_locks[locking.LEVEL_NODE]
|
2323 | 779c15bb | Iustin Pop | |
2324 | 8084f9f6 | Manuel Franceschini | # if vg_name not None, checks given volume group on all nodes
|
2325 | 8084f9f6 | Manuel Franceschini | if self.op.vg_name: |
2326 | 72737a7f | Iustin Pop | vglist = self.rpc.call_vg_list(node_list)
|
2327 | 8084f9f6 | Manuel Franceschini | for node in node_list: |
2328 | 4c4e4e1e | Iustin Pop | msg = vglist[node].fail_msg |
2329 | e480923b | Iustin Pop | if msg:
|
2330 | 781de953 | Iustin Pop | # ignoring down node
|
2331 | e480923b | Iustin Pop | self.LogWarning("Error while gathering data on node %s" |
2332 | e480923b | Iustin Pop | " (ignoring node): %s", node, msg)
|
2333 | 781de953 | Iustin Pop | continue
|
2334 | e480923b | Iustin Pop | vgstatus = utils.CheckVolumeGroupSize(vglist[node].payload, |
2335 | 781de953 | Iustin Pop | self.op.vg_name,
|
2336 | 8d1a2a64 | Michael Hanselmann | constants.MIN_VG_SIZE) |
2337 | 8084f9f6 | Manuel Franceschini | if vgstatus:
|
2338 | 8084f9f6 | Manuel Franceschini | raise errors.OpPrereqError("Error on node '%s': %s" % |
2339 | 5c983ee5 | Iustin Pop | (node, vgstatus), errors.ECODE_ENVIRON) |
2340 | 8084f9f6 | Manuel Franceschini | |
2341 | 779c15bb | Iustin Pop | self.cluster = cluster = self.cfg.GetClusterInfo() |
2342 | 5af3da74 | Guido Trotter | # validate params changes
|
2343 | 779c15bb | Iustin Pop | if self.op.beparams: |
2344 | a5728081 | Guido Trotter | utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
|
2345 | abe609b2 | Guido Trotter | self.new_beparams = objects.FillDict(
|
2346 | 4ef7f423 | Guido Trotter | cluster.beparams[constants.PP_DEFAULT], self.op.beparams)
|
2347 | 779c15bb | Iustin Pop | |
2348 | 5af3da74 | Guido Trotter | if self.op.nicparams: |
2349 | 5af3da74 | Guido Trotter | utils.ForceDictType(self.op.nicparams, constants.NICS_PARAMETER_TYPES)
|
2350 | 5af3da74 | Guido Trotter | self.new_nicparams = objects.FillDict(
|
2351 | 5af3da74 | Guido Trotter | cluster.nicparams[constants.PP_DEFAULT], self.op.nicparams)
|
2352 | 5af3da74 | Guido Trotter | objects.NIC.CheckParameterSyntax(self.new_nicparams)
|
2353 | 90b704a1 | Guido Trotter | nic_errors = [] |
2354 | 90b704a1 | Guido Trotter | |
2355 | 90b704a1 | Guido Trotter | # check all instances for consistency
|
2356 | 90b704a1 | Guido Trotter | for instance in self.cfg.GetAllInstancesInfo().values(): |
2357 | 90b704a1 | Guido Trotter | for nic_idx, nic in enumerate(instance.nics): |
2358 | 90b704a1 | Guido Trotter | params_copy = copy.deepcopy(nic.nicparams) |
2359 | 90b704a1 | Guido Trotter | params_filled = objects.FillDict(self.new_nicparams, params_copy)
|
2360 | 90b704a1 | Guido Trotter | |
2361 | 90b704a1 | Guido Trotter | # check parameter syntax
|
2362 | 90b704a1 | Guido Trotter | try:
|
2363 | 90b704a1 | Guido Trotter | objects.NIC.CheckParameterSyntax(params_filled) |
2364 | 90b704a1 | Guido Trotter | except errors.ConfigurationError, err:
|
2365 | 90b704a1 | Guido Trotter | nic_errors.append("Instance %s, nic/%d: %s" %
|
2366 | 90b704a1 | Guido Trotter | (instance.name, nic_idx, err)) |
2367 | 90b704a1 | Guido Trotter | |
2368 | 90b704a1 | Guido Trotter | # if we're moving instances to routed, check that they have an ip
|
2369 | 90b704a1 | Guido Trotter | target_mode = params_filled[constants.NIC_MODE] |
2370 | 90b704a1 | Guido Trotter | if target_mode == constants.NIC_MODE_ROUTED and not nic.ip: |
2371 | 90b704a1 | Guido Trotter | nic_errors.append("Instance %s, nic/%d: routed nick with no ip" %
|
2372 | 90b704a1 | Guido Trotter | (instance.name, nic_idx)) |
2373 | 90b704a1 | Guido Trotter | if nic_errors:
|
2374 | 90b704a1 | Guido Trotter | raise errors.OpPrereqError("Cannot apply the change, errors:\n%s" % |
2375 | 90b704a1 | Guido Trotter | "\n".join(nic_errors))
|
2376 | 5af3da74 | Guido Trotter | |
2377 | 779c15bb | Iustin Pop | # hypervisor list/parameters
|
2378 | 9f3ac970 | Iustin Pop | self.new_hvparams = new_hvp = objects.FillDict(cluster.hvparams, {})
|
2379 | 779c15bb | Iustin Pop | if self.op.hvparams: |
2380 | 779c15bb | Iustin Pop | if not isinstance(self.op.hvparams, dict): |
2381 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid 'hvparams' parameter on input", |
2382 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2383 | 779c15bb | Iustin Pop | for hv_name, hv_dict in self.op.hvparams.items(): |
2384 | 779c15bb | Iustin Pop | if hv_name not in self.new_hvparams: |
2385 | 779c15bb | Iustin Pop | self.new_hvparams[hv_name] = hv_dict
|
2386 | 779c15bb | Iustin Pop | else:
|
2387 | 779c15bb | Iustin Pop | self.new_hvparams[hv_name].update(hv_dict)
|
2388 | 779c15bb | Iustin Pop | |
2389 | 17463d22 | René Nussbaumer | # os hypervisor parameters
|
2390 | 17463d22 | René Nussbaumer | self.new_os_hvp = objects.FillDict(cluster.os_hvp, {})
|
2391 | 17463d22 | René Nussbaumer | if self.op.os_hvp: |
2392 | 17463d22 | René Nussbaumer | if not isinstance(self.op.os_hvp, dict): |
2393 | 17463d22 | René Nussbaumer | raise errors.OpPrereqError("Invalid 'os_hvp' parameter on input", |
2394 | 17463d22 | René Nussbaumer | errors.ECODE_INVAL) |
2395 | 17463d22 | René Nussbaumer | for os_name, hvs in self.op.os_hvp.items(): |
2396 | 17463d22 | René Nussbaumer | if not isinstance(hvs, dict): |
2397 | 17463d22 | René Nussbaumer | raise errors.OpPrereqError(("Invalid 'os_hvp' parameter on" |
2398 | 17463d22 | René Nussbaumer | " input"), errors.ECODE_INVAL)
|
2399 | 17463d22 | René Nussbaumer | if os_name not in self.new_os_hvp: |
2400 | 17463d22 | René Nussbaumer | self.new_os_hvp[os_name] = hvs
|
2401 | 17463d22 | René Nussbaumer | else:
|
2402 | 17463d22 | René Nussbaumer | for hv_name, hv_dict in hvs.items(): |
2403 | 17463d22 | René Nussbaumer | if hv_name not in self.new_os_hvp[os_name]: |
2404 | 17463d22 | René Nussbaumer | self.new_os_hvp[os_name][hv_name] = hv_dict
|
2405 | 17463d22 | René Nussbaumer | else:
|
2406 | 17463d22 | René Nussbaumer | self.new_os_hvp[os_name][hv_name].update(hv_dict)
|
2407 | 17463d22 | René Nussbaumer | |
2408 | 9f3ac970 | Iustin Pop | # changes to the hypervisor list
|
2409 | 779c15bb | Iustin Pop | if self.op.enabled_hypervisors is not None: |
2410 | 779c15bb | Iustin Pop | self.hv_list = self.op.enabled_hypervisors |
2411 | b119bccb | Guido Trotter | if not self.hv_list: |
2412 | b119bccb | Guido Trotter | raise errors.OpPrereqError("Enabled hypervisors list must contain at" |
2413 | 5c983ee5 | Iustin Pop | " least one member",
|
2414 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2415 | b119bccb | Guido Trotter | invalid_hvs = set(self.hv_list) - constants.HYPER_TYPES |
2416 | b119bccb | Guido Trotter | if invalid_hvs:
|
2417 | b119bccb | Guido Trotter | raise errors.OpPrereqError("Enabled hypervisors contains invalid" |
2418 | ab3e6da8 | Iustin Pop | " entries: %s" %
|
2419 | ab3e6da8 | Iustin Pop | utils.CommaJoin(invalid_hvs), |
2420 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2421 | 9f3ac970 | Iustin Pop | for hv in self.hv_list: |
2422 | 9f3ac970 | Iustin Pop | # if the hypervisor doesn't already exist in the cluster
|
2423 | 9f3ac970 | Iustin Pop | # hvparams, we initialize it to empty, and then (in both
|
2424 | 9f3ac970 | Iustin Pop | # cases) we make sure to fill the defaults, as we might not
|
2425 | 9f3ac970 | Iustin Pop | # have a complete defaults list if the hypervisor wasn't
|
2426 | 9f3ac970 | Iustin Pop | # enabled before
|
2427 | 9f3ac970 | Iustin Pop | if hv not in new_hvp: |
2428 | 9f3ac970 | Iustin Pop | new_hvp[hv] = {} |
2429 | 9f3ac970 | Iustin Pop | new_hvp[hv] = objects.FillDict(constants.HVC_DEFAULTS[hv], new_hvp[hv]) |
2430 | 9f3ac970 | Iustin Pop | utils.ForceDictType(new_hvp[hv], constants.HVS_PARAMETER_TYPES) |
2431 | 779c15bb | Iustin Pop | else:
|
2432 | 779c15bb | Iustin Pop | self.hv_list = cluster.enabled_hypervisors
|
2433 | 779c15bb | Iustin Pop | |
2434 | 779c15bb | Iustin Pop | if self.op.hvparams or self.op.enabled_hypervisors is not None: |
2435 | 779c15bb | Iustin Pop | # either the enabled list has changed, or the parameters have, validate
|
2436 | 779c15bb | Iustin Pop | for hv_name, hv_params in self.new_hvparams.items(): |
2437 | 779c15bb | Iustin Pop | if ((self.op.hvparams and hv_name in self.op.hvparams) or |
2438 | 779c15bb | Iustin Pop | (self.op.enabled_hypervisors and |
2439 | 779c15bb | Iustin Pop | hv_name in self.op.enabled_hypervisors)): |
2440 | 779c15bb | Iustin Pop | # either this is a new hypervisor, or its parameters have changed
|
2441 | 779c15bb | Iustin Pop | hv_class = hypervisor.GetHypervisor(hv_name) |
2442 | a5728081 | Guido Trotter | utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES) |
2443 | 779c15bb | Iustin Pop | hv_class.CheckParameterSyntax(hv_params) |
2444 | 779c15bb | Iustin Pop | _CheckHVParams(self, node_list, hv_name, hv_params)
|
2445 | 779c15bb | Iustin Pop | |
2446 | cced4c39 | Iustin Pop | if self.op.os_hvp: |
2447 | cced4c39 | Iustin Pop | # no need to check any newly-enabled hypervisors, since the
|
2448 | cced4c39 | Iustin Pop | # defaults have already been checked in the above code-block
|
2449 | cced4c39 | Iustin Pop | for os_name, os_hvp in self.new_os_hvp.items(): |
2450 | cced4c39 | Iustin Pop | for hv_name, hv_params in os_hvp.items(): |
2451 | cced4c39 | Iustin Pop | utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES) |
2452 | cced4c39 | Iustin Pop | # we need to fill in the new os_hvp on top of the actual hv_p
|
2453 | cced4c39 | Iustin Pop | cluster_defaults = self.new_hvparams.get(hv_name, {})
|
2454 | cced4c39 | Iustin Pop | new_osp = objects.FillDict(cluster_defaults, hv_params) |
2455 | cced4c39 | Iustin Pop | hv_class = hypervisor.GetHypervisor(hv_name) |
2456 | cced4c39 | Iustin Pop | hv_class.CheckParameterSyntax(new_osp) |
2457 | cced4c39 | Iustin Pop | _CheckHVParams(self, node_list, hv_name, new_osp)
|
2458 | cced4c39 | Iustin Pop | |
2459 | cced4c39 | Iustin Pop | |
2460 | 8084f9f6 | Manuel Franceschini | def Exec(self, feedback_fn): |
2461 | 8084f9f6 | Manuel Franceschini | """Change the parameters of the cluster.
|
2462 | 8084f9f6 | Manuel Franceschini |
|
2463 | 8084f9f6 | Manuel Franceschini | """
|
2464 | 779c15bb | Iustin Pop | if self.op.vg_name is not None: |
2465 | b2482333 | Guido Trotter | new_volume = self.op.vg_name
|
2466 | b2482333 | Guido Trotter | if not new_volume: |
2467 | b2482333 | Guido Trotter | new_volume = None
|
2468 | b2482333 | Guido Trotter | if new_volume != self.cfg.GetVGName(): |
2469 | b2482333 | Guido Trotter | self.cfg.SetVGName(new_volume)
|
2470 | 779c15bb | Iustin Pop | else:
|
2471 | 779c15bb | Iustin Pop | feedback_fn("Cluster LVM configuration already in desired"
|
2472 | 779c15bb | Iustin Pop | " state, not changing")
|
2473 | 779c15bb | Iustin Pop | if self.op.hvparams: |
2474 | 779c15bb | Iustin Pop | self.cluster.hvparams = self.new_hvparams |
2475 | 17463d22 | René Nussbaumer | if self.op.os_hvp: |
2476 | 17463d22 | René Nussbaumer | self.cluster.os_hvp = self.new_os_hvp |
2477 | 779c15bb | Iustin Pop | if self.op.enabled_hypervisors is not None: |
2478 | 9f3ac970 | Iustin Pop | self.cluster.hvparams = self.new_hvparams |
2479 | 779c15bb | Iustin Pop | self.cluster.enabled_hypervisors = self.op.enabled_hypervisors |
2480 | 779c15bb | Iustin Pop | if self.op.beparams: |
2481 | 4ef7f423 | Guido Trotter | self.cluster.beparams[constants.PP_DEFAULT] = self.new_beparams |
2482 | 5af3da74 | Guido Trotter | if self.op.nicparams: |
2483 | 5af3da74 | Guido Trotter | self.cluster.nicparams[constants.PP_DEFAULT] = self.new_nicparams |
2484 | 5af3da74 | Guido Trotter | |
2485 | 4b7735f9 | Iustin Pop | if self.op.candidate_pool_size is not None: |
2486 | 4b7735f9 | Iustin Pop | self.cluster.candidate_pool_size = self.op.candidate_pool_size |
2487 | 75e914fb | Iustin Pop | # we need to update the pool size here, otherwise the save will fail
|
2488 | 44485f49 | Guido Trotter | _AdjustCandidatePool(self, [])
|
2489 | 4b7735f9 | Iustin Pop | |
2490 | 3953242f | Iustin Pop | if self.op.maintain_node_health is not None: |
2491 | 3953242f | Iustin Pop | self.cluster.maintain_node_health = self.op.maintain_node_health |
2492 | 3953242f | Iustin Pop | |
2493 | fdad8c4d | Balazs Lecz | if self.op.add_uids is not None: |
2494 | fdad8c4d | Balazs Lecz | uidpool.AddToUidPool(self.cluster.uid_pool, self.op.add_uids) |
2495 | fdad8c4d | Balazs Lecz | |
2496 | fdad8c4d | Balazs Lecz | if self.op.remove_uids is not None: |
2497 | fdad8c4d | Balazs Lecz | uidpool.RemoveFromUidPool(self.cluster.uid_pool, self.op.remove_uids) |
2498 | fdad8c4d | Balazs Lecz | |
2499 | 1338f2b4 | Balazs Lecz | if self.op.uid_pool is not None: |
2500 | 1338f2b4 | Balazs Lecz | self.cluster.uid_pool = self.op.uid_pool |
2501 | 1338f2b4 | Balazs Lecz | |
2502 | a4eae71f | Michael Hanselmann | self.cfg.Update(self.cluster, feedback_fn) |
2503 | 8084f9f6 | Manuel Franceschini | |
2504 | 8084f9f6 | Manuel Franceschini | |
2505 | 28eddce5 | Guido Trotter | def _RedistributeAncillaryFiles(lu, additional_nodes=None): |
2506 | 28eddce5 | Guido Trotter | """Distribute additional files which are part of the cluster configuration.
|
2507 | 28eddce5 | Guido Trotter |
|
2508 | 28eddce5 | Guido Trotter | ConfigWriter takes care of distributing the config and ssconf files, but
|
2509 | 28eddce5 | Guido Trotter | there are more files which should be distributed to all nodes. This function
|
2510 | 28eddce5 | Guido Trotter | makes sure those are copied.
|
2511 | 28eddce5 | Guido Trotter |
|
2512 | 28eddce5 | Guido Trotter | @param lu: calling logical unit
|
2513 | 28eddce5 | Guido Trotter | @param additional_nodes: list of nodes not in the config to distribute to
|
2514 | 28eddce5 | Guido Trotter |
|
2515 | 28eddce5 | Guido Trotter | """
|
2516 | 28eddce5 | Guido Trotter | # 1. Gather target nodes
|
2517 | 28eddce5 | Guido Trotter | myself = lu.cfg.GetNodeInfo(lu.cfg.GetMasterNode()) |
2518 | 6819dc49 | Iustin Pop | dist_nodes = lu.cfg.GetOnlineNodeList() |
2519 | 28eddce5 | Guido Trotter | if additional_nodes is not None: |
2520 | 28eddce5 | Guido Trotter | dist_nodes.extend(additional_nodes) |
2521 | 28eddce5 | Guido Trotter | if myself.name in dist_nodes: |
2522 | 28eddce5 | Guido Trotter | dist_nodes.remove(myself.name) |
2523 | a4eae71f | Michael Hanselmann | |
2524 | 28eddce5 | Guido Trotter | # 2. Gather files to distribute
|
2525 | 28eddce5 | Guido Trotter | dist_files = set([constants.ETC_HOSTS,
|
2526 | 28eddce5 | Guido Trotter | constants.SSH_KNOWN_HOSTS_FILE, |
2527 | 28eddce5 | Guido Trotter | constants.RAPI_CERT_FILE, |
2528 | 28eddce5 | Guido Trotter | constants.RAPI_USERS_FILE, |
2529 | 6b7d5878 | Michael Hanselmann | constants.CONFD_HMAC_KEY, |
2530 | 28eddce5 | Guido Trotter | ]) |
2531 | e1b8653f | Guido Trotter | |
2532 | e1b8653f | Guido Trotter | enabled_hypervisors = lu.cfg.GetClusterInfo().enabled_hypervisors |
2533 | e1b8653f | Guido Trotter | for hv_name in enabled_hypervisors: |
2534 | e1b8653f | Guido Trotter | hv_class = hypervisor.GetHypervisor(hv_name) |
2535 | e1b8653f | Guido Trotter | dist_files.update(hv_class.GetAncillaryFiles()) |
2536 | e1b8653f | Guido Trotter | |
2537 | 28eddce5 | Guido Trotter | # 3. Perform the files upload
|
2538 | 28eddce5 | Guido Trotter | for fname in dist_files: |
2539 | 28eddce5 | Guido Trotter | if os.path.exists(fname):
|
2540 | 28eddce5 | Guido Trotter | result = lu.rpc.call_upload_file(dist_nodes, fname) |
2541 | 28eddce5 | Guido Trotter | for to_node, to_result in result.items(): |
2542 | 6f7d4e75 | Iustin Pop | msg = to_result.fail_msg |
2543 | 6f7d4e75 | Iustin Pop | if msg:
|
2544 | 6f7d4e75 | Iustin Pop | msg = ("Copy of file %s to node %s failed: %s" %
|
2545 | 6f7d4e75 | Iustin Pop | (fname, to_node, msg)) |
2546 | 6f7d4e75 | Iustin Pop | lu.proc.LogWarning(msg) |
2547 | 28eddce5 | Guido Trotter | |
2548 | 28eddce5 | Guido Trotter | |
2549 | afee0879 | Iustin Pop | class LURedistributeConfig(NoHooksLU): |
2550 | afee0879 | Iustin Pop | """Force the redistribution of cluster configuration.
|
2551 | afee0879 | Iustin Pop |
|
2552 | afee0879 | Iustin Pop | This is a very simple LU.
|
2553 | afee0879 | Iustin Pop |
|
2554 | afee0879 | Iustin Pop | """
|
2555 | afee0879 | Iustin Pop | _OP_REQP = [] |
2556 | afee0879 | Iustin Pop | REQ_BGL = False
|
2557 | afee0879 | Iustin Pop | |
2558 | afee0879 | Iustin Pop | def ExpandNames(self): |
2559 | afee0879 | Iustin Pop | self.needed_locks = {
|
2560 | afee0879 | Iustin Pop | locking.LEVEL_NODE: locking.ALL_SET, |
2561 | afee0879 | Iustin Pop | } |
2562 | afee0879 | Iustin Pop | self.share_locks[locking.LEVEL_NODE] = 1 |
2563 | afee0879 | Iustin Pop | |
2564 | afee0879 | Iustin Pop | def CheckPrereq(self): |
2565 | afee0879 | Iustin Pop | """Check prerequisites.
|
2566 | afee0879 | Iustin Pop |
|
2567 | afee0879 | Iustin Pop | """
|
2568 | afee0879 | Iustin Pop | |
2569 | afee0879 | Iustin Pop | def Exec(self, feedback_fn): |
2570 | afee0879 | Iustin Pop | """Redistribute the configuration.
|
2571 | afee0879 | Iustin Pop |
|
2572 | afee0879 | Iustin Pop | """
|
2573 | a4eae71f | Michael Hanselmann | self.cfg.Update(self.cfg.GetClusterInfo(), feedback_fn) |
2574 | 28eddce5 | Guido Trotter | _RedistributeAncillaryFiles(self)
|
2575 | afee0879 | Iustin Pop | |
2576 | afee0879 | Iustin Pop | |
2577 | b6c07b79 | Michael Hanselmann | def _WaitForSync(lu, instance, oneshot=False): |
2578 | a8083063 | Iustin Pop | """Sleep and poll for an instance's disk to sync.
|
2579 | a8083063 | Iustin Pop |
|
2580 | a8083063 | Iustin Pop | """
|
2581 | a8083063 | Iustin Pop | if not instance.disks: |
2582 | a8083063 | Iustin Pop | return True |
2583 | a8083063 | Iustin Pop | |
2584 | a8083063 | Iustin Pop | if not oneshot: |
2585 | b9bddb6b | Iustin Pop | lu.proc.LogInfo("Waiting for instance %s to sync disks." % instance.name)
|
2586 | a8083063 | Iustin Pop | |
2587 | a8083063 | Iustin Pop | node = instance.primary_node |
2588 | a8083063 | Iustin Pop | |
2589 | a8083063 | Iustin Pop | for dev in instance.disks: |
2590 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(dev, node) |
2591 | a8083063 | Iustin Pop | |
2592 | 6bcb1446 | Michael Hanselmann | # TODO: Convert to utils.Retry
|
2593 | 6bcb1446 | Michael Hanselmann | |
2594 | a8083063 | Iustin Pop | retries = 0
|
2595 | fbafd7a8 | Iustin Pop | degr_retries = 10 # in seconds, as we sleep 1 second each time |
2596 | a8083063 | Iustin Pop | while True: |
2597 | a8083063 | Iustin Pop | max_time = 0
|
2598 | a8083063 | Iustin Pop | done = True
|
2599 | a8083063 | Iustin Pop | cumul_degraded = False
|
2600 | 72737a7f | Iustin Pop | rstats = lu.rpc.call_blockdev_getmirrorstatus(node, instance.disks) |
2601 | 4c4e4e1e | Iustin Pop | msg = rstats.fail_msg |
2602 | 3efa9051 | Iustin Pop | if msg:
|
2603 | 3efa9051 | Iustin Pop | lu.LogWarning("Can't get any data from node %s: %s", node, msg)
|
2604 | a8083063 | Iustin Pop | retries += 1
|
2605 | a8083063 | Iustin Pop | if retries >= 10: |
2606 | 3ecf6786 | Iustin Pop | raise errors.RemoteError("Can't contact node %s for mirror data," |
2607 | 3ecf6786 | Iustin Pop | " aborting." % node)
|
2608 | a8083063 | Iustin Pop | time.sleep(6)
|
2609 | a8083063 | Iustin Pop | continue
|
2610 | 3efa9051 | Iustin Pop | rstats = rstats.payload |
2611 | a8083063 | Iustin Pop | retries = 0
|
2612 | 1492cca7 | Iustin Pop | for i, mstat in enumerate(rstats): |
2613 | a8083063 | Iustin Pop | if mstat is None: |
2614 | 86d9d3bb | Iustin Pop | lu.LogWarning("Can't compute data for node %s/%s",
|
2615 | 86d9d3bb | Iustin Pop | node, instance.disks[i].iv_name) |
2616 | a8083063 | Iustin Pop | continue
|
2617 | 36145b12 | Michael Hanselmann | |
2618 | 36145b12 | Michael Hanselmann | cumul_degraded = (cumul_degraded or
|
2619 | 36145b12 | Michael Hanselmann | (mstat.is_degraded and mstat.sync_percent is None)) |
2620 | 36145b12 | Michael Hanselmann | if mstat.sync_percent is not None: |
2621 | a8083063 | Iustin Pop | done = False
|
2622 | 36145b12 | Michael Hanselmann | if mstat.estimated_time is not None: |
2623 | 36145b12 | Michael Hanselmann | rem_time = "%d estimated seconds remaining" % mstat.estimated_time
|
2624 | 36145b12 | Michael Hanselmann | max_time = mstat.estimated_time |
2625 | a8083063 | Iustin Pop | else:
|
2626 | a8083063 | Iustin Pop | rem_time = "no time estimate"
|
2627 | b9bddb6b | Iustin Pop | lu.proc.LogInfo("- device %s: %5.2f%% done, %s" %
|
2628 | 4d4a651d | Michael Hanselmann | (instance.disks[i].iv_name, mstat.sync_percent, |
2629 | 4d4a651d | Michael Hanselmann | rem_time)) |
2630 | fbafd7a8 | Iustin Pop | |
2631 | fbafd7a8 | Iustin Pop | # if we're done but degraded, let's do a few small retries, to
|
2632 | fbafd7a8 | Iustin Pop | # make sure we see a stable and not transient situation; therefore
|
2633 | fbafd7a8 | Iustin Pop | # we force restart of the loop
|
2634 | fbafd7a8 | Iustin Pop | if (done or oneshot) and cumul_degraded and degr_retries > 0: |
2635 | fbafd7a8 | Iustin Pop | logging.info("Degraded disks found, %d retries left", degr_retries)
|
2636 | fbafd7a8 | Iustin Pop | degr_retries -= 1
|
2637 | fbafd7a8 | Iustin Pop | time.sleep(1)
|
2638 | fbafd7a8 | Iustin Pop | continue
|
2639 | fbafd7a8 | Iustin Pop | |
2640 | a8083063 | Iustin Pop | if done or oneshot: |
2641 | a8083063 | Iustin Pop | break
|
2642 | a8083063 | Iustin Pop | |
2643 | d4fa5c23 | Iustin Pop | time.sleep(min(60, max_time)) |
2644 | a8083063 | Iustin Pop | |
2645 | a8083063 | Iustin Pop | if done:
|
2646 | b9bddb6b | Iustin Pop | lu.proc.LogInfo("Instance %s's disks are in sync." % instance.name)
|
2647 | a8083063 | Iustin Pop | return not cumul_degraded |
2648 | a8083063 | Iustin Pop | |
2649 | a8083063 | Iustin Pop | |
2650 | b9bddb6b | Iustin Pop | def _CheckDiskConsistency(lu, dev, node, on_primary, ldisk=False): |
2651 | a8083063 | Iustin Pop | """Check that mirrors are not degraded.
|
2652 | a8083063 | Iustin Pop |
|
2653 | 0834c866 | Iustin Pop | The ldisk parameter, if True, will change the test from the
|
2654 | 0834c866 | Iustin Pop | is_degraded attribute (which represents overall non-ok status for
|
2655 | 0834c866 | Iustin Pop | the device(s)) to the ldisk (representing the local storage status).
|
2656 | 0834c866 | Iustin Pop |
|
2657 | a8083063 | Iustin Pop | """
|
2658 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(dev, node) |
2659 | a8083063 | Iustin Pop | |
2660 | a8083063 | Iustin Pop | result = True
|
2661 | 96acbc09 | Michael Hanselmann | |
2662 | a8083063 | Iustin Pop | if on_primary or dev.AssembleOnSecondary(): |
2663 | 72737a7f | Iustin Pop | rstats = lu.rpc.call_blockdev_find(node, dev) |
2664 | 4c4e4e1e | Iustin Pop | msg = rstats.fail_msg |
2665 | 23829f6f | Iustin Pop | if msg:
|
2666 | 23829f6f | Iustin Pop | lu.LogWarning("Can't find disk on node %s: %s", node, msg)
|
2667 | 23829f6f | Iustin Pop | result = False
|
2668 | 23829f6f | Iustin Pop | elif not rstats.payload: |
2669 | 23829f6f | Iustin Pop | lu.LogWarning("Can't find disk on node %s", node)
|
2670 | a8083063 | Iustin Pop | result = False
|
2671 | a8083063 | Iustin Pop | else:
|
2672 | 96acbc09 | Michael Hanselmann | if ldisk:
|
2673 | f208978a | Michael Hanselmann | result = result and rstats.payload.ldisk_status == constants.LDS_OKAY
|
2674 | 96acbc09 | Michael Hanselmann | else:
|
2675 | 96acbc09 | Michael Hanselmann | result = result and not rstats.payload.is_degraded |
2676 | 96acbc09 | Michael Hanselmann | |
2677 | a8083063 | Iustin Pop | if dev.children:
|
2678 | a8083063 | Iustin Pop | for child in dev.children: |
2679 | b9bddb6b | Iustin Pop | result = result and _CheckDiskConsistency(lu, child, node, on_primary)
|
2680 | a8083063 | Iustin Pop | |
2681 | a8083063 | Iustin Pop | return result
|
2682 | a8083063 | Iustin Pop | |
2683 | a8083063 | Iustin Pop | |
2684 | a8083063 | Iustin Pop | class LUDiagnoseOS(NoHooksLU): |
2685 | a8083063 | Iustin Pop | """Logical unit for OS diagnose/query.
|
2686 | a8083063 | Iustin Pop |
|
2687 | a8083063 | Iustin Pop | """
|
2688 | 1f9430d6 | Iustin Pop | _OP_REQP = ["output_fields", "names"] |
2689 | 6bf01bbb | Guido Trotter | REQ_BGL = False
|
2690 | a2d2e1a7 | Iustin Pop | _FIELDS_STATIC = utils.FieldSet() |
2691 | 1e288a26 | Guido Trotter | _FIELDS_DYNAMIC = utils.FieldSet("name", "valid", "node_status", "variants") |
2692 | 1e288a26 | Guido Trotter | # Fields that need calculation of global os validity
|
2693 | 1e288a26 | Guido Trotter | _FIELDS_NEEDVALID = frozenset(["valid", "variants"]) |
2694 | a8083063 | Iustin Pop | |
2695 | 6bf01bbb | Guido Trotter | def ExpandNames(self): |
2696 | 1f9430d6 | Iustin Pop | if self.op.names: |
2697 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Selective OS query not supported", |
2698 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2699 | 1f9430d6 | Iustin Pop | |
2700 | 31bf511f | Iustin Pop | _CheckOutputFields(static=self._FIELDS_STATIC,
|
2701 | 31bf511f | Iustin Pop | dynamic=self._FIELDS_DYNAMIC,
|
2702 | 1f9430d6 | Iustin Pop | selected=self.op.output_fields)
|
2703 | 1f9430d6 | Iustin Pop | |
2704 | 6bf01bbb | Guido Trotter | # Lock all nodes, in shared mode
|
2705 | a6ab004b | Iustin Pop | # Temporary removal of locks, should be reverted later
|
2706 | a6ab004b | Iustin Pop | # TODO: reintroduce locks when they are lighter-weight
|
2707 | 6bf01bbb | Guido Trotter | self.needed_locks = {}
|
2708 | a6ab004b | Iustin Pop | #self.share_locks[locking.LEVEL_NODE] = 1
|
2709 | a6ab004b | Iustin Pop | #self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
2710 | 6bf01bbb | Guido Trotter | |
2711 | 6bf01bbb | Guido Trotter | def CheckPrereq(self): |
2712 | 6bf01bbb | Guido Trotter | """Check prerequisites.
|
2713 | 6bf01bbb | Guido Trotter |
|
2714 | 6bf01bbb | Guido Trotter | """
|
2715 | 6bf01bbb | Guido Trotter | |
2716 | 1f9430d6 | Iustin Pop | @staticmethod
|
2717 | 857121ad | Iustin Pop | def _DiagnoseByOS(rlist): |
2718 | 1f9430d6 | Iustin Pop | """Remaps a per-node return list into an a per-os per-node dictionary
|
2719 | 1f9430d6 | Iustin Pop |
|
2720 | e4376078 | Iustin Pop | @param rlist: a map with node names as keys and OS objects as values
|
2721 | 1f9430d6 | Iustin Pop |
|
2722 | e4376078 | Iustin Pop | @rtype: dict
|
2723 | 5fcc718f | Iustin Pop | @return: a dictionary with osnames as keys and as value another map, with
|
2724 | 255dcebd | Iustin Pop | nodes as keys and tuples of (path, status, diagnose) as values, eg::
|
2725 | e4376078 | Iustin Pop |
|
2726 | 255dcebd | Iustin Pop | {"debian-etch": {"node1": [(/usr/lib/..., True, ""),
|
2727 | 255dcebd | Iustin Pop | (/srv/..., False, "invalid api")],
|
2728 | 255dcebd | Iustin Pop | "node2": [(/srv/..., True, "")]}
|
2729 | e4376078 | Iustin Pop | }
|
2730 | 1f9430d6 | Iustin Pop |
|
2731 | 1f9430d6 | Iustin Pop | """
|
2732 | 1f9430d6 | Iustin Pop | all_os = {} |
2733 | a6ab004b | Iustin Pop | # we build here the list of nodes that didn't fail the RPC (at RPC
|
2734 | a6ab004b | Iustin Pop | # level), so that nodes with a non-responding node daemon don't
|
2735 | a6ab004b | Iustin Pop | # make all OSes invalid
|
2736 | a6ab004b | Iustin Pop | good_nodes = [node_name for node_name in rlist |
2737 | 4c4e4e1e | Iustin Pop | if not rlist[node_name].fail_msg] |
2738 | 83d92ad8 | Iustin Pop | for node_name, nr in rlist.items(): |
2739 | 4c4e4e1e | Iustin Pop | if nr.fail_msg or not nr.payload: |
2740 | 1f9430d6 | Iustin Pop | continue
|
2741 | ba00557a | Guido Trotter | for name, path, status, diagnose, variants in nr.payload: |
2742 | 255dcebd | Iustin Pop | if name not in all_os: |
2743 | 1f9430d6 | Iustin Pop | # build a list of nodes for this os containing empty lists
|
2744 | 1f9430d6 | Iustin Pop | # for each node in node_list
|
2745 | 255dcebd | Iustin Pop | all_os[name] = {} |
2746 | a6ab004b | Iustin Pop | for nname in good_nodes: |
2747 | 255dcebd | Iustin Pop | all_os[name][nname] = [] |
2748 | ba00557a | Guido Trotter | all_os[name][node_name].append((path, status, diagnose, variants)) |
2749 | 1f9430d6 | Iustin Pop | return all_os
|
2750 | a8083063 | Iustin Pop | |
2751 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
2752 | a8083063 | Iustin Pop | """Compute the list of OSes.
|
2753 | a8083063 | Iustin Pop |
|
2754 | a8083063 | Iustin Pop | """
|
2755 | a6ab004b | Iustin Pop | valid_nodes = [node for node in self.cfg.GetOnlineNodeList()] |
2756 | 94a02bb5 | Iustin Pop | node_data = self.rpc.call_os_diagnose(valid_nodes)
|
2757 | 857121ad | Iustin Pop | pol = self._DiagnoseByOS(node_data)
|
2758 | 1f9430d6 | Iustin Pop | output = [] |
2759 | 1e288a26 | Guido Trotter | calc_valid = self._FIELDS_NEEDVALID.intersection(self.op.output_fields) |
2760 | 1e288a26 | Guido Trotter | calc_variants = "variants" in self.op.output_fields |
2761 | 1e288a26 | Guido Trotter | |
2762 | 83d92ad8 | Iustin Pop | for os_name, os_data in pol.items(): |
2763 | 1f9430d6 | Iustin Pop | row = [] |
2764 | 1e288a26 | Guido Trotter | if calc_valid:
|
2765 | 1e288a26 | Guido Trotter | valid = True
|
2766 | 1e288a26 | Guido Trotter | variants = None
|
2767 | 1e288a26 | Guido Trotter | for osl in os_data.values(): |
2768 | 1e288a26 | Guido Trotter | valid = valid and osl and osl[0][1] |
2769 | 1e288a26 | Guido Trotter | if not valid: |
2770 | 1e288a26 | Guido Trotter | variants = None
|
2771 | 1e288a26 | Guido Trotter | break
|
2772 | 1e288a26 | Guido Trotter | if calc_variants:
|
2773 | 1e288a26 | Guido Trotter | node_variants = osl[0][3] |
2774 | 1e288a26 | Guido Trotter | if variants is None: |
2775 | 1e288a26 | Guido Trotter | variants = node_variants |
2776 | 1e288a26 | Guido Trotter | else:
|
2777 | 1e288a26 | Guido Trotter | variants = [v for v in variants if v in node_variants] |
2778 | 1e288a26 | Guido Trotter | |
2779 | 1f9430d6 | Iustin Pop | for field in self.op.output_fields: |
2780 | 1f9430d6 | Iustin Pop | if field == "name": |
2781 | 1f9430d6 | Iustin Pop | val = os_name |
2782 | 1f9430d6 | Iustin Pop | elif field == "valid": |
2783 | 1e288a26 | Guido Trotter | val = valid |
2784 | 1f9430d6 | Iustin Pop | elif field == "node_status": |
2785 | 255dcebd | Iustin Pop | # this is just a copy of the dict
|
2786 | 1f9430d6 | Iustin Pop | val = {} |
2787 | 255dcebd | Iustin Pop | for node_name, nos_list in os_data.items(): |
2788 | 255dcebd | Iustin Pop | val[node_name] = nos_list |
2789 | 1e288a26 | Guido Trotter | elif field == "variants": |
2790 | 1e288a26 | Guido Trotter | val = variants |
2791 | 1f9430d6 | Iustin Pop | else:
|
2792 | 1f9430d6 | Iustin Pop | raise errors.ParameterError(field)
|
2793 | 1f9430d6 | Iustin Pop | row.append(val) |
2794 | 1f9430d6 | Iustin Pop | output.append(row) |
2795 | 1f9430d6 | Iustin Pop | |
2796 | 1f9430d6 | Iustin Pop | return output
|
2797 | a8083063 | Iustin Pop | |
2798 | a8083063 | Iustin Pop | |
2799 | a8083063 | Iustin Pop | class LURemoveNode(LogicalUnit): |
2800 | a8083063 | Iustin Pop | """Logical unit for removing a node.
|
2801 | a8083063 | Iustin Pop |
|
2802 | a8083063 | Iustin Pop | """
|
2803 | a8083063 | Iustin Pop | HPATH = "node-remove"
|
2804 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_NODE |
2805 | a8083063 | Iustin Pop | _OP_REQP = ["node_name"]
|
2806 | a8083063 | Iustin Pop | |
2807 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
2808 | a8083063 | Iustin Pop | """Build hooks env.
|
2809 | a8083063 | Iustin Pop |
|
2810 | a8083063 | Iustin Pop | This doesn't run on the target node in the pre phase as a failed
|
2811 | d08869ee | Guido Trotter | node would then be impossible to remove.
|
2812 | a8083063 | Iustin Pop |
|
2813 | a8083063 | Iustin Pop | """
|
2814 | 396e1b78 | Michael Hanselmann | env = { |
2815 | 0e137c28 | Iustin Pop | "OP_TARGET": self.op.node_name, |
2816 | 396e1b78 | Michael Hanselmann | "NODE_NAME": self.op.node_name, |
2817 | 396e1b78 | Michael Hanselmann | } |
2818 | a8083063 | Iustin Pop | all_nodes = self.cfg.GetNodeList()
|
2819 | 9bb31ea8 | Iustin Pop | try:
|
2820 | cd46f3b4 | Luca Bigliardi | all_nodes.remove(self.op.node_name)
|
2821 | 9bb31ea8 | Iustin Pop | except ValueError: |
2822 | 9bb31ea8 | Iustin Pop | logging.warning("Node %s which is about to be removed not found"
|
2823 | 9bb31ea8 | Iustin Pop | " in the all nodes list", self.op.node_name) |
2824 | 396e1b78 | Michael Hanselmann | return env, all_nodes, all_nodes
|
2825 | a8083063 | Iustin Pop | |
2826 | a8083063 | Iustin Pop | def CheckPrereq(self): |
2827 | a8083063 | Iustin Pop | """Check prerequisites.
|
2828 | a8083063 | Iustin Pop |
|
2829 | a8083063 | Iustin Pop | This checks:
|
2830 | a8083063 | Iustin Pop | - the node exists in the configuration
|
2831 | a8083063 | Iustin Pop | - it does not have primary or secondary instances
|
2832 | a8083063 | Iustin Pop | - it's not the master
|
2833 | a8083063 | Iustin Pop |
|
2834 | 5bbd3f7f | Michael Hanselmann | Any errors are signaled by raising errors.OpPrereqError.
|
2835 | a8083063 | Iustin Pop |
|
2836 | a8083063 | Iustin Pop | """
|
2837 | cf26a87a | Iustin Pop | self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name) |
2838 | cf26a87a | Iustin Pop | node = self.cfg.GetNodeInfo(self.op.node_name) |
2839 | cf26a87a | Iustin Pop | assert node is not None |
2840 | a8083063 | Iustin Pop | |
2841 | a8083063 | Iustin Pop | instance_list = self.cfg.GetInstanceList()
|
2842 | a8083063 | Iustin Pop | |
2843 | d6a02168 | Michael Hanselmann | masternode = self.cfg.GetMasterNode()
|
2844 | a8083063 | Iustin Pop | if node.name == masternode:
|
2845 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Node is the master node," |
2846 | 5c983ee5 | Iustin Pop | " you need to failover first.",
|
2847 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2848 | a8083063 | Iustin Pop | |
2849 | a8083063 | Iustin Pop | for instance_name in instance_list: |
2850 | a8083063 | Iustin Pop | instance = self.cfg.GetInstanceInfo(instance_name)
|
2851 | 6b12959c | Iustin Pop | if node.name in instance.all_nodes: |
2852 | 6b12959c | Iustin Pop | raise errors.OpPrereqError("Instance %s is still running on the node," |
2853 | 5c983ee5 | Iustin Pop | " please remove first." % instance_name,
|
2854 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
2855 | a8083063 | Iustin Pop | self.op.node_name = node.name
|
2856 | a8083063 | Iustin Pop | self.node = node
|
2857 | a8083063 | Iustin Pop | |
2858 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
2859 | a8083063 | Iustin Pop | """Removes the node from the cluster.
|
2860 | a8083063 | Iustin Pop |
|
2861 | a8083063 | Iustin Pop | """
|
2862 | a8083063 | Iustin Pop | node = self.node
|
2863 | 9a4f63d1 | Iustin Pop | logging.info("Stopping the node daemon and removing configs from node %s",
|
2864 | 9a4f63d1 | Iustin Pop | node.name) |
2865 | a8083063 | Iustin Pop | |
2866 | b989b9d9 | Ken Wehr | modify_ssh_setup = self.cfg.GetClusterInfo().modify_ssh_setup
|
2867 | b989b9d9 | Ken Wehr | |
2868 | 44485f49 | Guido Trotter | # Promote nodes to master candidate as needed
|
2869 | 44485f49 | Guido Trotter | _AdjustCandidatePool(self, exceptions=[node.name])
|
2870 | d8470559 | Michael Hanselmann | self.context.RemoveNode(node.name)
|
2871 | a8083063 | Iustin Pop | |
2872 | cd46f3b4 | Luca Bigliardi | # Run post hooks on the node before it's removed
|
2873 | cd46f3b4 | Luca Bigliardi | hm = self.proc.hmclass(self.rpc.call_hooks_runner, self) |
2874 | cd46f3b4 | Luca Bigliardi | try:
|
2875 | 1122eb25 | Iustin Pop | hm.RunPhase(constants.HOOKS_PHASE_POST, [node.name]) |
2876 | 3cb5c1e3 | Luca Bigliardi | except:
|
2877 | 7260cfbe | Iustin Pop | # pylint: disable-msg=W0702
|
2878 | 3cb5c1e3 | Luca Bigliardi | self.LogWarning("Errors occurred running hooks on %s" % node.name) |
2879 | cd46f3b4 | Luca Bigliardi | |
2880 | b989b9d9 | Ken Wehr | result = self.rpc.call_node_leave_cluster(node.name, modify_ssh_setup)
|
2881 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
2882 | 0623d351 | Iustin Pop | if msg:
|
2883 | 0623d351 | Iustin Pop | self.LogWarning("Errors encountered on the remote node while leaving" |
2884 | 0623d351 | Iustin Pop | " the cluster: %s", msg)
|
2885 | c8a0948f | Michael Hanselmann | |
2886 | a8083063 | Iustin Pop | |
2887 | a8083063 | Iustin Pop | class LUQueryNodes(NoHooksLU): |
2888 | a8083063 | Iustin Pop | """Logical unit for querying nodes.
|
2889 | a8083063 | Iustin Pop |
|
2890 | a8083063 | Iustin Pop | """
|
2891 | 7260cfbe | Iustin Pop | # pylint: disable-msg=W0142
|
2892 | bc8e4a1a | Iustin Pop | _OP_REQP = ["output_fields", "names", "use_locking"] |
2893 | 35705d8f | Guido Trotter | REQ_BGL = False
|
2894 | 19bed813 | Iustin Pop | |
2895 | 19bed813 | Iustin Pop | _SIMPLE_FIELDS = ["name", "serial_no", "ctime", "mtime", "uuid", |
2896 | 19bed813 | Iustin Pop | "master_candidate", "offline", "drained"] |
2897 | 19bed813 | Iustin Pop | |
2898 | a2d2e1a7 | Iustin Pop | _FIELDS_DYNAMIC = utils.FieldSet( |
2899 | 31bf511f | Iustin Pop | "dtotal", "dfree", |
2900 | 31bf511f | Iustin Pop | "mtotal", "mnode", "mfree", |
2901 | 31bf511f | Iustin Pop | "bootid",
|
2902 | 0105bad3 | Iustin Pop | "ctotal", "cnodes", "csockets", |
2903 | 31bf511f | Iustin Pop | ) |
2904 | 31bf511f | Iustin Pop | |
2905 | 19bed813 | Iustin Pop | _FIELDS_STATIC = utils.FieldSet(*[ |
2906 | 19bed813 | Iustin Pop | "pinst_cnt", "sinst_cnt", |
2907 | 31bf511f | Iustin Pop | "pinst_list", "sinst_list", |
2908 | 31bf511f | Iustin Pop | "pip", "sip", "tags", |
2909 | 0e67cdbe | Iustin Pop | "master",
|
2910 | 19bed813 | Iustin Pop | "role"] + _SIMPLE_FIELDS
|
2911 | 31bf511f | Iustin Pop | ) |
2912 | a8083063 | Iustin Pop | |
2913 | 35705d8f | Guido Trotter | def ExpandNames(self): |
2914 | 31bf511f | Iustin Pop | _CheckOutputFields(static=self._FIELDS_STATIC,
|
2915 | 31bf511f | Iustin Pop | dynamic=self._FIELDS_DYNAMIC,
|
2916 | dcb93971 | Michael Hanselmann | selected=self.op.output_fields)
|
2917 | a8083063 | Iustin Pop | |
2918 | 35705d8f | Guido Trotter | self.needed_locks = {}
|
2919 | 35705d8f | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
2920 | c8d8b4c8 | Iustin Pop | |
2921 | c8d8b4c8 | Iustin Pop | if self.op.names: |
2922 | c8d8b4c8 | Iustin Pop | self.wanted = _GetWantedNodes(self, self.op.names) |
2923 | 35705d8f | Guido Trotter | else:
|
2924 | c8d8b4c8 | Iustin Pop | self.wanted = locking.ALL_SET
|
2925 | c8d8b4c8 | Iustin Pop | |
2926 | bc8e4a1a | Iustin Pop | self.do_node_query = self._FIELDS_STATIC.NonMatching(self.op.output_fields) |
2927 | bc8e4a1a | Iustin Pop | self.do_locking = self.do_node_query and self.op.use_locking |
2928 | c8d8b4c8 | Iustin Pop | if self.do_locking: |
2929 | c8d8b4c8 | Iustin Pop | # if we don't request only static fields, we need to lock the nodes
|
2930 | c8d8b4c8 | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = self.wanted |
2931 | c8d8b4c8 | Iustin Pop | |
2932 | 35705d8f | Guido Trotter | def CheckPrereq(self): |
2933 | 35705d8f | Guido Trotter | """Check prerequisites.
|
2934 | 35705d8f | Guido Trotter |
|
2935 | 35705d8f | Guido Trotter | """
|
2936 | c8d8b4c8 | Iustin Pop | # The validation of the node list is done in the _GetWantedNodes,
|
2937 | c8d8b4c8 | Iustin Pop | # if non empty, and if empty, there's no validation to do
|
2938 | c8d8b4c8 | Iustin Pop | pass
|
2939 | a8083063 | Iustin Pop | |
2940 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
2941 | a8083063 | Iustin Pop | """Computes the list of nodes and their attributes.
|
2942 | a8083063 | Iustin Pop |
|
2943 | a8083063 | Iustin Pop | """
|
2944 | c8d8b4c8 | Iustin Pop | all_info = self.cfg.GetAllNodesInfo()
|
2945 | c8d8b4c8 | Iustin Pop | if self.do_locking: |
2946 | c8d8b4c8 | Iustin Pop | nodenames = self.acquired_locks[locking.LEVEL_NODE]
|
2947 | 3fa93523 | Guido Trotter | elif self.wanted != locking.ALL_SET: |
2948 | 3fa93523 | Guido Trotter | nodenames = self.wanted
|
2949 | 3fa93523 | Guido Trotter | missing = set(nodenames).difference(all_info.keys())
|
2950 | 3fa93523 | Guido Trotter | if missing:
|
2951 | 7b3a8fb5 | Iustin Pop | raise errors.OpExecError(
|
2952 | 3fa93523 | Guido Trotter | "Some nodes were removed before retrieving their data: %s" % missing)
|
2953 | c8d8b4c8 | Iustin Pop | else:
|
2954 | c8d8b4c8 | Iustin Pop | nodenames = all_info.keys() |
2955 | c1f1cbb2 | Iustin Pop | |
2956 | c1f1cbb2 | Iustin Pop | nodenames = utils.NiceSort(nodenames) |
2957 | c8d8b4c8 | Iustin Pop | nodelist = [all_info[name] for name in nodenames] |
2958 | a8083063 | Iustin Pop | |
2959 | a8083063 | Iustin Pop | # begin data gathering
|
2960 | a8083063 | Iustin Pop | |
2961 | bc8e4a1a | Iustin Pop | if self.do_node_query: |
2962 | a8083063 | Iustin Pop | live_data = {} |
2963 | 72737a7f | Iustin Pop | node_data = self.rpc.call_node_info(nodenames, self.cfg.GetVGName(), |
2964 | 72737a7f | Iustin Pop | self.cfg.GetHypervisorType())
|
2965 | a8083063 | Iustin Pop | for name in nodenames: |
2966 | 781de953 | Iustin Pop | nodeinfo = node_data[name] |
2967 | 4c4e4e1e | Iustin Pop | if not nodeinfo.fail_msg and nodeinfo.payload: |
2968 | 070e998b | Iustin Pop | nodeinfo = nodeinfo.payload |
2969 | d599d686 | Iustin Pop | fn = utils.TryConvert |
2970 | a8083063 | Iustin Pop | live_data[name] = { |
2971 | d599d686 | Iustin Pop | "mtotal": fn(int, nodeinfo.get('memory_total', None)), |
2972 | d599d686 | Iustin Pop | "mnode": fn(int, nodeinfo.get('memory_dom0', None)), |
2973 | d599d686 | Iustin Pop | "mfree": fn(int, nodeinfo.get('memory_free', None)), |
2974 | d599d686 | Iustin Pop | "dtotal": fn(int, nodeinfo.get('vg_size', None)), |
2975 | d599d686 | Iustin Pop | "dfree": fn(int, nodeinfo.get('vg_free', None)), |
2976 | d599d686 | Iustin Pop | "ctotal": fn(int, nodeinfo.get('cpu_total', None)), |
2977 | d599d686 | Iustin Pop | "bootid": nodeinfo.get('bootid', None), |
2978 | 0105bad3 | Iustin Pop | "cnodes": fn(int, nodeinfo.get('cpu_nodes', None)), |
2979 | 0105bad3 | Iustin Pop | "csockets": fn(int, nodeinfo.get('cpu_sockets', None)), |
2980 | a8083063 | Iustin Pop | } |
2981 | a8083063 | Iustin Pop | else:
|
2982 | a8083063 | Iustin Pop | live_data[name] = {} |
2983 | a8083063 | Iustin Pop | else:
|
2984 | a8083063 | Iustin Pop | live_data = dict.fromkeys(nodenames, {})
|
2985 | a8083063 | Iustin Pop | |
2986 | ec223efb | Iustin Pop | node_to_primary = dict([(name, set()) for name in nodenames]) |
2987 | ec223efb | Iustin Pop | node_to_secondary = dict([(name, set()) for name in nodenames]) |
2988 | a8083063 | Iustin Pop | |
2989 | ec223efb | Iustin Pop | inst_fields = frozenset(("pinst_cnt", "pinst_list", |
2990 | ec223efb | Iustin Pop | "sinst_cnt", "sinst_list")) |
2991 | ec223efb | Iustin Pop | if inst_fields & frozenset(self.op.output_fields): |
2992 | 4dfd6266 | Iustin Pop | inst_data = self.cfg.GetAllInstancesInfo()
|
2993 | a8083063 | Iustin Pop | |
2994 | 1122eb25 | Iustin Pop | for inst in inst_data.values(): |
2995 | ec223efb | Iustin Pop | if inst.primary_node in node_to_primary: |
2996 | ec223efb | Iustin Pop | node_to_primary[inst.primary_node].add(inst.name) |
2997 | ec223efb | Iustin Pop | for secnode in inst.secondary_nodes: |
2998 | ec223efb | Iustin Pop | if secnode in node_to_secondary: |
2999 | ec223efb | Iustin Pop | node_to_secondary[secnode].add(inst.name) |
3000 | a8083063 | Iustin Pop | |
3001 | 0e67cdbe | Iustin Pop | master_node = self.cfg.GetMasterNode()
|
3002 | 0e67cdbe | Iustin Pop | |
3003 | a8083063 | Iustin Pop | # end data gathering
|
3004 | a8083063 | Iustin Pop | |
3005 | a8083063 | Iustin Pop | output = [] |
3006 | a8083063 | Iustin Pop | for node in nodelist: |
3007 | a8083063 | Iustin Pop | node_output = [] |
3008 | a8083063 | Iustin Pop | for field in self.op.output_fields: |
3009 | 19bed813 | Iustin Pop | if field in self._SIMPLE_FIELDS: |
3010 | 19bed813 | Iustin Pop | val = getattr(node, field)
|
3011 | ec223efb | Iustin Pop | elif field == "pinst_list": |
3012 | ec223efb | Iustin Pop | val = list(node_to_primary[node.name])
|
3013 | ec223efb | Iustin Pop | elif field == "sinst_list": |
3014 | ec223efb | Iustin Pop | val = list(node_to_secondary[node.name])
|
3015 | ec223efb | Iustin Pop | elif field == "pinst_cnt": |
3016 | ec223efb | Iustin Pop | val = len(node_to_primary[node.name])
|
3017 | ec223efb | Iustin Pop | elif field == "sinst_cnt": |
3018 | ec223efb | Iustin Pop | val = len(node_to_secondary[node.name])
|
3019 | a8083063 | Iustin Pop | elif field == "pip": |
3020 | a8083063 | Iustin Pop | val = node.primary_ip |
3021 | a8083063 | Iustin Pop | elif field == "sip": |
3022 | a8083063 | Iustin Pop | val = node.secondary_ip |
3023 | 130a6a6f | Iustin Pop | elif field == "tags": |
3024 | 130a6a6f | Iustin Pop | val = list(node.GetTags())
|
3025 | 0e67cdbe | Iustin Pop | elif field == "master": |
3026 | 0e67cdbe | Iustin Pop | val = node.name == master_node |
3027 | 31bf511f | Iustin Pop | elif self._FIELDS_DYNAMIC.Matches(field): |
3028 | ec223efb | Iustin Pop | val = live_data[node.name].get(field, None)
|
3029 | c120ff34 | Iustin Pop | elif field == "role": |
3030 | c120ff34 | Iustin Pop | if node.name == master_node:
|
3031 | c120ff34 | Iustin Pop | val = "M"
|
3032 | c120ff34 | Iustin Pop | elif node.master_candidate:
|
3033 | c120ff34 | Iustin Pop | val = "C"
|
3034 | c120ff34 | Iustin Pop | elif node.drained:
|
3035 | c120ff34 | Iustin Pop | val = "D"
|
3036 | c120ff34 | Iustin Pop | elif node.offline:
|
3037 | c120ff34 | Iustin Pop | val = "O"
|
3038 | c120ff34 | Iustin Pop | else:
|
3039 | c120ff34 | Iustin Pop | val = "R"
|
3040 | a8083063 | Iustin Pop | else:
|
3041 | 3ecf6786 | Iustin Pop | raise errors.ParameterError(field)
|
3042 | a8083063 | Iustin Pop | node_output.append(val) |
3043 | a8083063 | Iustin Pop | output.append(node_output) |
3044 | a8083063 | Iustin Pop | |
3045 | a8083063 | Iustin Pop | return output
|
3046 | a8083063 | Iustin Pop | |
3047 | a8083063 | Iustin Pop | |
3048 | dcb93971 | Michael Hanselmann | class LUQueryNodeVolumes(NoHooksLU): |
3049 | dcb93971 | Michael Hanselmann | """Logical unit for getting volumes on node(s).
|
3050 | dcb93971 | Michael Hanselmann |
|
3051 | dcb93971 | Michael Hanselmann | """
|
3052 | dcb93971 | Michael Hanselmann | _OP_REQP = ["nodes", "output_fields"] |
3053 | 21a15682 | Guido Trotter | REQ_BGL = False
|
3054 | a2d2e1a7 | Iustin Pop | _FIELDS_DYNAMIC = utils.FieldSet("phys", "vg", "name", "size", "instance") |
3055 | a2d2e1a7 | Iustin Pop | _FIELDS_STATIC = utils.FieldSet("node")
|
3056 | 21a15682 | Guido Trotter | |
3057 | 21a15682 | Guido Trotter | def ExpandNames(self): |
3058 | 31bf511f | Iustin Pop | _CheckOutputFields(static=self._FIELDS_STATIC,
|
3059 | 31bf511f | Iustin Pop | dynamic=self._FIELDS_DYNAMIC,
|
3060 | 21a15682 | Guido Trotter | selected=self.op.output_fields)
|
3061 | 21a15682 | Guido Trotter | |
3062 | 21a15682 | Guido Trotter | self.needed_locks = {}
|
3063 | 21a15682 | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
3064 | 21a15682 | Guido Trotter | if not self.op.nodes: |
3065 | e310b019 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
3066 | 21a15682 | Guido Trotter | else:
|
3067 | 21a15682 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = \
|
3068 | 21a15682 | Guido Trotter | _GetWantedNodes(self, self.op.nodes) |
3069 | dcb93971 | Michael Hanselmann | |
3070 | dcb93971 | Michael Hanselmann | def CheckPrereq(self): |
3071 | dcb93971 | Michael Hanselmann | """Check prerequisites.
|
3072 | dcb93971 | Michael Hanselmann |
|
3073 | dcb93971 | Michael Hanselmann | This checks that the fields required are valid output fields.
|
3074 | dcb93971 | Michael Hanselmann |
|
3075 | dcb93971 | Michael Hanselmann | """
|
3076 | 21a15682 | Guido Trotter | self.nodes = self.acquired_locks[locking.LEVEL_NODE] |
3077 | dcb93971 | Michael Hanselmann | |
3078 | dcb93971 | Michael Hanselmann | def Exec(self, feedback_fn): |
3079 | dcb93971 | Michael Hanselmann | """Computes the list of nodes and their attributes.
|
3080 | dcb93971 | Michael Hanselmann |
|
3081 | dcb93971 | Michael Hanselmann | """
|
3082 | a7ba5e53 | Iustin Pop | nodenames = self.nodes
|
3083 | 72737a7f | Iustin Pop | volumes = self.rpc.call_node_volumes(nodenames)
|
3084 | dcb93971 | Michael Hanselmann | |
3085 | dcb93971 | Michael Hanselmann | ilist = [self.cfg.GetInstanceInfo(iname) for iname |
3086 | dcb93971 | Michael Hanselmann | in self.cfg.GetInstanceList()] |
3087 | dcb93971 | Michael Hanselmann | |
3088 | dcb93971 | Michael Hanselmann | lv_by_node = dict([(inst, inst.MapLVsByNode()) for inst in ilist]) |
3089 | dcb93971 | Michael Hanselmann | |
3090 | dcb93971 | Michael Hanselmann | output = [] |
3091 | dcb93971 | Michael Hanselmann | for node in nodenames: |
3092 | 10bfe6cb | Iustin Pop | nresult = volumes[node] |
3093 | 10bfe6cb | Iustin Pop | if nresult.offline:
|
3094 | 10bfe6cb | Iustin Pop | continue
|
3095 | 4c4e4e1e | Iustin Pop | msg = nresult.fail_msg |
3096 | 10bfe6cb | Iustin Pop | if msg:
|
3097 | 10bfe6cb | Iustin Pop | self.LogWarning("Can't compute volume data on node %s: %s", node, msg) |
3098 | 37d19eb2 | Michael Hanselmann | continue
|
3099 | 37d19eb2 | Michael Hanselmann | |
3100 | 10bfe6cb | Iustin Pop | node_vols = nresult.payload[:] |
3101 | dcb93971 | Michael Hanselmann | node_vols.sort(key=lambda vol: vol['dev']) |
3102 | dcb93971 | Michael Hanselmann | |
3103 | dcb93971 | Michael Hanselmann | for vol in node_vols: |
3104 | dcb93971 | Michael Hanselmann | node_output = [] |
3105 | dcb93971 | Michael Hanselmann | for field in self.op.output_fields: |
3106 | dcb93971 | Michael Hanselmann | if field == "node": |
3107 | dcb93971 | Michael Hanselmann | val = node |
3108 | dcb93971 | Michael Hanselmann | elif field == "phys": |
3109 | dcb93971 | Michael Hanselmann | val = vol['dev']
|
3110 | dcb93971 | Michael Hanselmann | elif field == "vg": |
3111 | dcb93971 | Michael Hanselmann | val = vol['vg']
|
3112 | dcb93971 | Michael Hanselmann | elif field == "name": |
3113 | dcb93971 | Michael Hanselmann | val = vol['name']
|
3114 | dcb93971 | Michael Hanselmann | elif field == "size": |
3115 | dcb93971 | Michael Hanselmann | val = int(float(vol['size'])) |
3116 | dcb93971 | Michael Hanselmann | elif field == "instance": |
3117 | dcb93971 | Michael Hanselmann | for inst in ilist: |
3118 | dcb93971 | Michael Hanselmann | if node not in lv_by_node[inst]: |
3119 | dcb93971 | Michael Hanselmann | continue
|
3120 | dcb93971 | Michael Hanselmann | if vol['name'] in lv_by_node[inst][node]: |
3121 | dcb93971 | Michael Hanselmann | val = inst.name |
3122 | dcb93971 | Michael Hanselmann | break
|
3123 | dcb93971 | Michael Hanselmann | else:
|
3124 | dcb93971 | Michael Hanselmann | val = '-'
|
3125 | dcb93971 | Michael Hanselmann | else:
|
3126 | 3ecf6786 | Iustin Pop | raise errors.ParameterError(field)
|
3127 | dcb93971 | Michael Hanselmann | node_output.append(str(val))
|
3128 | dcb93971 | Michael Hanselmann | |
3129 | dcb93971 | Michael Hanselmann | output.append(node_output) |
3130 | dcb93971 | Michael Hanselmann | |
3131 | dcb93971 | Michael Hanselmann | return output
|
3132 | dcb93971 | Michael Hanselmann | |
3133 | dcb93971 | Michael Hanselmann | |
3134 | 9e5442ce | Michael Hanselmann | class LUQueryNodeStorage(NoHooksLU): |
3135 | 9e5442ce | Michael Hanselmann | """Logical unit for getting information on storage units on node(s).
|
3136 | 9e5442ce | Michael Hanselmann |
|
3137 | 9e5442ce | Michael Hanselmann | """
|
3138 | 9e5442ce | Michael Hanselmann | _OP_REQP = ["nodes", "storage_type", "output_fields"] |
3139 | 9e5442ce | Michael Hanselmann | REQ_BGL = False
|
3140 | 620a85fd | Iustin Pop | _FIELDS_STATIC = utils.FieldSet(constants.SF_NODE) |
3141 | 9e5442ce | Michael Hanselmann | |
3142 | 0e3baaf3 | Iustin Pop | def CheckArguments(self): |
3143 | 0e3baaf3 | Iustin Pop | _CheckStorageType(self.op.storage_type)
|
3144 | 9e5442ce | Michael Hanselmann | |
3145 | 9e5442ce | Michael Hanselmann | _CheckOutputFields(static=self._FIELDS_STATIC,
|
3146 | 620a85fd | Iustin Pop | dynamic=utils.FieldSet(*constants.VALID_STORAGE_FIELDS), |
3147 | 9e5442ce | Michael Hanselmann | selected=self.op.output_fields)
|
3148 | 9e5442ce | Michael Hanselmann | |
3149 | 0e3baaf3 | Iustin Pop | def ExpandNames(self): |
3150 | 9e5442ce | Michael Hanselmann | self.needed_locks = {}
|
3151 | 9e5442ce | Michael Hanselmann | self.share_locks[locking.LEVEL_NODE] = 1 |
3152 | 9e5442ce | Michael Hanselmann | |
3153 | 9e5442ce | Michael Hanselmann | if self.op.nodes: |
3154 | 9e5442ce | Michael Hanselmann | self.needed_locks[locking.LEVEL_NODE] = \
|
3155 | 9e5442ce | Michael Hanselmann | _GetWantedNodes(self, self.op.nodes) |
3156 | 9e5442ce | Michael Hanselmann | else:
|
3157 | 9e5442ce | Michael Hanselmann | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
3158 | 9e5442ce | Michael Hanselmann | |
3159 | 9e5442ce | Michael Hanselmann | def CheckPrereq(self): |
3160 | 9e5442ce | Michael Hanselmann | """Check prerequisites.
|
3161 | 9e5442ce | Michael Hanselmann |
|
3162 | 9e5442ce | Michael Hanselmann | This checks that the fields required are valid output fields.
|
3163 | 9e5442ce | Michael Hanselmann |
|
3164 | 9e5442ce | Michael Hanselmann | """
|
3165 | 9e5442ce | Michael Hanselmann | self.op.name = getattr(self.op, "name", None) |
3166 | 9e5442ce | Michael Hanselmann | |
3167 | 9e5442ce | Michael Hanselmann | self.nodes = self.acquired_locks[locking.LEVEL_NODE] |
3168 | 9e5442ce | Michael Hanselmann | |
3169 | 9e5442ce | Michael Hanselmann | def Exec(self, feedback_fn): |
3170 | 9e5442ce | Michael Hanselmann | """Computes the list of nodes and their attributes.
|
3171 | 9e5442ce | Michael Hanselmann |
|
3172 | 9e5442ce | Michael Hanselmann | """
|
3173 | 9e5442ce | Michael Hanselmann | # Always get name to sort by
|
3174 | 9e5442ce | Michael Hanselmann | if constants.SF_NAME in self.op.output_fields: |
3175 | 9e5442ce | Michael Hanselmann | fields = self.op.output_fields[:]
|
3176 | 9e5442ce | Michael Hanselmann | else:
|
3177 | 9e5442ce | Michael Hanselmann | fields = [constants.SF_NAME] + self.op.output_fields
|
3178 | 9e5442ce | Michael Hanselmann | |
3179 | 620a85fd | Iustin Pop | # Never ask for node or type as it's only known to the LU
|
3180 | 620a85fd | Iustin Pop | for extra in [constants.SF_NODE, constants.SF_TYPE]: |
3181 | 620a85fd | Iustin Pop | while extra in fields: |
3182 | 620a85fd | Iustin Pop | fields.remove(extra) |
3183 | 9e5442ce | Michael Hanselmann | |
3184 | 9e5442ce | Michael Hanselmann | field_idx = dict([(name, idx) for (idx, name) in enumerate(fields)]) |
3185 | 9e5442ce | Michael Hanselmann | name_idx = field_idx[constants.SF_NAME] |
3186 | 9e5442ce | Michael Hanselmann | |
3187 | efb8da02 | Michael Hanselmann | st_args = _GetStorageTypeArgs(self.cfg, self.op.storage_type) |
3188 | 9e5442ce | Michael Hanselmann | data = self.rpc.call_storage_list(self.nodes, |
3189 | 9e5442ce | Michael Hanselmann | self.op.storage_type, st_args,
|
3190 | 9e5442ce | Michael Hanselmann | self.op.name, fields)
|
3191 | 9e5442ce | Michael Hanselmann | |
3192 | 9e5442ce | Michael Hanselmann | result = [] |
3193 | 9e5442ce | Michael Hanselmann | |
3194 | 9e5442ce | Michael Hanselmann | for node in utils.NiceSort(self.nodes): |
3195 | 9e5442ce | Michael Hanselmann | nresult = data[node] |
3196 | 9e5442ce | Michael Hanselmann | if nresult.offline:
|
3197 | 9e5442ce | Michael Hanselmann | continue
|
3198 | 9e5442ce | Michael Hanselmann | |
3199 | 9e5442ce | Michael Hanselmann | msg = nresult.fail_msg |
3200 | 9e5442ce | Michael Hanselmann | if msg:
|
3201 | 9e5442ce | Michael Hanselmann | self.LogWarning("Can't get storage data from node %s: %s", node, msg) |
3202 | 9e5442ce | Michael Hanselmann | continue
|
3203 | 9e5442ce | Michael Hanselmann | |
3204 | 9e5442ce | Michael Hanselmann | rows = dict([(row[name_idx], row) for row in nresult.payload]) |
3205 | 9e5442ce | Michael Hanselmann | |
3206 | 9e5442ce | Michael Hanselmann | for name in utils.NiceSort(rows.keys()): |
3207 | 9e5442ce | Michael Hanselmann | row = rows[name] |
3208 | 9e5442ce | Michael Hanselmann | |
3209 | 9e5442ce | Michael Hanselmann | out = [] |
3210 | 9e5442ce | Michael Hanselmann | |
3211 | 9e5442ce | Michael Hanselmann | for field in self.op.output_fields: |
3212 | 620a85fd | Iustin Pop | if field == constants.SF_NODE:
|
3213 | 9e5442ce | Michael Hanselmann | val = node |
3214 | 620a85fd | Iustin Pop | elif field == constants.SF_TYPE:
|
3215 | 620a85fd | Iustin Pop | val = self.op.storage_type
|
3216 | 9e5442ce | Michael Hanselmann | elif field in field_idx: |
3217 | 9e5442ce | Michael Hanselmann | val = row[field_idx[field]] |
3218 | 9e5442ce | Michael Hanselmann | else:
|
3219 | 9e5442ce | Michael Hanselmann | raise errors.ParameterError(field)
|
3220 | 9e5442ce | Michael Hanselmann | |
3221 | 9e5442ce | Michael Hanselmann | out.append(val) |
3222 | 9e5442ce | Michael Hanselmann | |
3223 | 9e5442ce | Michael Hanselmann | result.append(out) |
3224 | 9e5442ce | Michael Hanselmann | |
3225 | 9e5442ce | Michael Hanselmann | return result
|
3226 | 9e5442ce | Michael Hanselmann | |
3227 | 9e5442ce | Michael Hanselmann | |
3228 | efb8da02 | Michael Hanselmann | class LUModifyNodeStorage(NoHooksLU): |
3229 | efb8da02 | Michael Hanselmann | """Logical unit for modifying a storage volume on a node.
|
3230 | efb8da02 | Michael Hanselmann |
|
3231 | efb8da02 | Michael Hanselmann | """
|
3232 | efb8da02 | Michael Hanselmann | _OP_REQP = ["node_name", "storage_type", "name", "changes"] |
3233 | efb8da02 | Michael Hanselmann | REQ_BGL = False
|
3234 | efb8da02 | Michael Hanselmann | |
3235 | efb8da02 | Michael Hanselmann | def CheckArguments(self): |
3236 | cf26a87a | Iustin Pop | self.opnode_name = _ExpandNodeName(self.cfg, self.op.node_name) |
3237 | efb8da02 | Michael Hanselmann | |
3238 | 0e3baaf3 | Iustin Pop | _CheckStorageType(self.op.storage_type)
|
3239 | efb8da02 | Michael Hanselmann | |
3240 | efb8da02 | Michael Hanselmann | def ExpandNames(self): |
3241 | efb8da02 | Michael Hanselmann | self.needed_locks = {
|
3242 | efb8da02 | Michael Hanselmann | locking.LEVEL_NODE: self.op.node_name,
|
3243 | efb8da02 | Michael Hanselmann | } |
3244 | efb8da02 | Michael Hanselmann | |
3245 | efb8da02 | Michael Hanselmann | def CheckPrereq(self): |
3246 | efb8da02 | Michael Hanselmann | """Check prerequisites.
|
3247 | efb8da02 | Michael Hanselmann |
|
3248 | efb8da02 | Michael Hanselmann | """
|
3249 | efb8da02 | Michael Hanselmann | storage_type = self.op.storage_type
|
3250 | efb8da02 | Michael Hanselmann | |
3251 | efb8da02 | Michael Hanselmann | try:
|
3252 | efb8da02 | Michael Hanselmann | modifiable = constants.MODIFIABLE_STORAGE_FIELDS[storage_type] |
3253 | efb8da02 | Michael Hanselmann | except KeyError: |
3254 | efb8da02 | Michael Hanselmann | raise errors.OpPrereqError("Storage units of type '%s' can not be" |
3255 | 5c983ee5 | Iustin Pop | " modified" % storage_type,
|
3256 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3257 | efb8da02 | Michael Hanselmann | |
3258 | efb8da02 | Michael Hanselmann | diff = set(self.op.changes.keys()) - modifiable |
3259 | efb8da02 | Michael Hanselmann | if diff:
|
3260 | efb8da02 | Michael Hanselmann | raise errors.OpPrereqError("The following fields can not be modified for" |
3261 | efb8da02 | Michael Hanselmann | " storage units of type '%s': %r" %
|
3262 | 5c983ee5 | Iustin Pop | (storage_type, list(diff)),
|
3263 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3264 | efb8da02 | Michael Hanselmann | |
3265 | efb8da02 | Michael Hanselmann | def Exec(self, feedback_fn): |
3266 | efb8da02 | Michael Hanselmann | """Computes the list of nodes and their attributes.
|
3267 | efb8da02 | Michael Hanselmann |
|
3268 | efb8da02 | Michael Hanselmann | """
|
3269 | efb8da02 | Michael Hanselmann | st_args = _GetStorageTypeArgs(self.cfg, self.op.storage_type) |
3270 | efb8da02 | Michael Hanselmann | result = self.rpc.call_storage_modify(self.op.node_name, |
3271 | efb8da02 | Michael Hanselmann | self.op.storage_type, st_args,
|
3272 | efb8da02 | Michael Hanselmann | self.op.name, self.op.changes) |
3273 | efb8da02 | Michael Hanselmann | result.Raise("Failed to modify storage unit '%s' on %s" %
|
3274 | efb8da02 | Michael Hanselmann | (self.op.name, self.op.node_name)) |
3275 | efb8da02 | Michael Hanselmann | |
3276 | efb8da02 | Michael Hanselmann | |
3277 | a8083063 | Iustin Pop | class LUAddNode(LogicalUnit): |
3278 | a8083063 | Iustin Pop | """Logical unit for adding node to the cluster.
|
3279 | a8083063 | Iustin Pop |
|
3280 | a8083063 | Iustin Pop | """
|
3281 | a8083063 | Iustin Pop | HPATH = "node-add"
|
3282 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_NODE |
3283 | a8083063 | Iustin Pop | _OP_REQP = ["node_name"]
|
3284 | a8083063 | Iustin Pop | |
3285 | 44caf5a8 | Iustin Pop | def CheckArguments(self): |
3286 | 44caf5a8 | Iustin Pop | # validate/normalize the node name
|
3287 | 44caf5a8 | Iustin Pop | self.op.node_name = utils.HostInfo.NormalizeName(self.op.node_name) |
3288 | 44caf5a8 | Iustin Pop | |
3289 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
3290 | a8083063 | Iustin Pop | """Build hooks env.
|
3291 | a8083063 | Iustin Pop |
|
3292 | a8083063 | Iustin Pop | This will run on all nodes before, and on all nodes + the new node after.
|
3293 | a8083063 | Iustin Pop |
|
3294 | a8083063 | Iustin Pop | """
|
3295 | a8083063 | Iustin Pop | env = { |
3296 | 0e137c28 | Iustin Pop | "OP_TARGET": self.op.node_name, |
3297 | a8083063 | Iustin Pop | "NODE_NAME": self.op.node_name, |
3298 | a8083063 | Iustin Pop | "NODE_PIP": self.op.primary_ip, |
3299 | a8083063 | Iustin Pop | "NODE_SIP": self.op.secondary_ip, |
3300 | a8083063 | Iustin Pop | } |
3301 | a8083063 | Iustin Pop | nodes_0 = self.cfg.GetNodeList()
|
3302 | a8083063 | Iustin Pop | nodes_1 = nodes_0 + [self.op.node_name, ]
|
3303 | a8083063 | Iustin Pop | return env, nodes_0, nodes_1
|
3304 | a8083063 | Iustin Pop | |
3305 | a8083063 | Iustin Pop | def CheckPrereq(self): |
3306 | a8083063 | Iustin Pop | """Check prerequisites.
|
3307 | a8083063 | Iustin Pop |
|
3308 | a8083063 | Iustin Pop | This checks:
|
3309 | a8083063 | Iustin Pop | - the new node is not already in the config
|
3310 | a8083063 | Iustin Pop | - it is resolvable
|
3311 | a8083063 | Iustin Pop | - its parameters (single/dual homed) matches the cluster
|
3312 | a8083063 | Iustin Pop |
|
3313 | 5bbd3f7f | Michael Hanselmann | Any errors are signaled by raising errors.OpPrereqError.
|
3314 | a8083063 | Iustin Pop |
|
3315 | a8083063 | Iustin Pop | """
|
3316 | a8083063 | Iustin Pop | node_name = self.op.node_name
|
3317 | a8083063 | Iustin Pop | cfg = self.cfg
|
3318 | a8083063 | Iustin Pop | |
3319 | 104f4ca1 | Iustin Pop | dns_data = utils.GetHostInfo(node_name) |
3320 | a8083063 | Iustin Pop | |
3321 | bcf043c9 | Iustin Pop | node = dns_data.name |
3322 | bcf043c9 | Iustin Pop | primary_ip = self.op.primary_ip = dns_data.ip
|
3323 | a8083063 | Iustin Pop | secondary_ip = getattr(self.op, "secondary_ip", None) |
3324 | a8083063 | Iustin Pop | if secondary_ip is None: |
3325 | a8083063 | Iustin Pop | secondary_ip = primary_ip |
3326 | a8083063 | Iustin Pop | if not utils.IsValidIP(secondary_ip): |
3327 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid secondary IP given", |
3328 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3329 | a8083063 | Iustin Pop | self.op.secondary_ip = secondary_ip
|
3330 | e7c6e02b | Michael Hanselmann | |
3331 | a8083063 | Iustin Pop | node_list = cfg.GetNodeList() |
3332 | e7c6e02b | Michael Hanselmann | if not self.op.readd and node in node_list: |
3333 | e7c6e02b | Michael Hanselmann | raise errors.OpPrereqError("Node %s is already in the configuration" % |
3334 | 5c983ee5 | Iustin Pop | node, errors.ECODE_EXISTS) |
3335 | e7c6e02b | Michael Hanselmann | elif self.op.readd and node not in node_list: |
3336 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Node %s is not in the configuration" % node, |
3337 | 5c983ee5 | Iustin Pop | errors.ECODE_NOENT) |
3338 | a8083063 | Iustin Pop | |
3339 | 1513e2dd | Iustin Pop | self.changed_primary_ip = False |
3340 | 1513e2dd | Iustin Pop | |
3341 | a8083063 | Iustin Pop | for existing_node_name in node_list: |
3342 | a8083063 | Iustin Pop | existing_node = cfg.GetNodeInfo(existing_node_name) |
3343 | e7c6e02b | Michael Hanselmann | |
3344 | e7c6e02b | Michael Hanselmann | if self.op.readd and node == existing_node_name: |
3345 | 1513e2dd | Iustin Pop | if existing_node.secondary_ip != secondary_ip:
|
3346 | e7c6e02b | Michael Hanselmann | raise errors.OpPrereqError("Readded node doesn't have the same IP" |
3347 | 5c983ee5 | Iustin Pop | " address configuration as before",
|
3348 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3349 | 1513e2dd | Iustin Pop | if existing_node.primary_ip != primary_ip:
|
3350 | 1513e2dd | Iustin Pop | self.changed_primary_ip = True |
3351 | 1513e2dd | Iustin Pop | |
3352 | e7c6e02b | Michael Hanselmann | continue
|
3353 | e7c6e02b | Michael Hanselmann | |
3354 | a8083063 | Iustin Pop | if (existing_node.primary_ip == primary_ip or |
3355 | a8083063 | Iustin Pop | existing_node.secondary_ip == primary_ip or
|
3356 | a8083063 | Iustin Pop | existing_node.primary_ip == secondary_ip or
|
3357 | a8083063 | Iustin Pop | existing_node.secondary_ip == secondary_ip): |
3358 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("New node ip address(es) conflict with" |
3359 | 5c983ee5 | Iustin Pop | " existing node %s" % existing_node.name,
|
3360 | 5c983ee5 | Iustin Pop | errors.ECODE_NOTUNIQUE) |
3361 | a8083063 | Iustin Pop | |
3362 | a8083063 | Iustin Pop | # check that the type of the node (single versus dual homed) is the
|
3363 | a8083063 | Iustin Pop | # same as for the master
|
3364 | d6a02168 | Michael Hanselmann | myself = cfg.GetNodeInfo(self.cfg.GetMasterNode())
|
3365 | a8083063 | Iustin Pop | master_singlehomed = myself.secondary_ip == myself.primary_ip |
3366 | a8083063 | Iustin Pop | newbie_singlehomed = secondary_ip == primary_ip |
3367 | a8083063 | Iustin Pop | if master_singlehomed != newbie_singlehomed:
|
3368 | a8083063 | Iustin Pop | if master_singlehomed:
|
3369 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("The master has no private ip but the" |
3370 | 5c983ee5 | Iustin Pop | " new node has one",
|
3371 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3372 | a8083063 | Iustin Pop | else:
|
3373 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("The master has a private ip but the" |
3374 | 5c983ee5 | Iustin Pop | " new node doesn't have one",
|
3375 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3376 | a8083063 | Iustin Pop | |
3377 | 5bbd3f7f | Michael Hanselmann | # checks reachability
|
3378 | b15d625f | Iustin Pop | if not utils.TcpPing(primary_ip, constants.DEFAULT_NODED_PORT): |
3379 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Node not reachable by ping", |
3380 | 5c983ee5 | Iustin Pop | errors.ECODE_ENVIRON) |
3381 | a8083063 | Iustin Pop | |
3382 | a8083063 | Iustin Pop | if not newbie_singlehomed: |
3383 | a8083063 | Iustin Pop | # check reachability from my secondary ip to newbie's secondary ip
|
3384 | b15d625f | Iustin Pop | if not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT, |
3385 | b15d625f | Iustin Pop | source=myself.secondary_ip): |
3386 | f4bc1f2c | Michael Hanselmann | raise errors.OpPrereqError("Node secondary ip not reachable by TCP" |
3387 | 5c983ee5 | Iustin Pop | " based ping to noded port",
|
3388 | 5c983ee5 | Iustin Pop | errors.ECODE_ENVIRON) |
3389 | a8083063 | Iustin Pop | |
3390 | a8ae3eb5 | Iustin Pop | if self.op.readd: |
3391 | a8ae3eb5 | Iustin Pop | exceptions = [node] |
3392 | a8ae3eb5 | Iustin Pop | else:
|
3393 | a8ae3eb5 | Iustin Pop | exceptions = [] |
3394 | 6d7e1f20 | Guido Trotter | |
3395 | 6d7e1f20 | Guido Trotter | self.master_candidate = _DecideSelfPromotion(self, exceptions=exceptions) |
3396 | 0fff97e9 | Guido Trotter | |
3397 | a8ae3eb5 | Iustin Pop | if self.op.readd: |
3398 | a8ae3eb5 | Iustin Pop | self.new_node = self.cfg.GetNodeInfo(node) |
3399 | a8ae3eb5 | Iustin Pop | assert self.new_node is not None, "Can't retrieve locked node %s" % node |
3400 | a8ae3eb5 | Iustin Pop | else:
|
3401 | a8ae3eb5 | Iustin Pop | self.new_node = objects.Node(name=node,
|
3402 | a8ae3eb5 | Iustin Pop | primary_ip=primary_ip, |
3403 | a8ae3eb5 | Iustin Pop | secondary_ip=secondary_ip, |
3404 | a8ae3eb5 | Iustin Pop | master_candidate=self.master_candidate,
|
3405 | a8ae3eb5 | Iustin Pop | offline=False, drained=False) |
3406 | a8083063 | Iustin Pop | |
3407 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
3408 | a8083063 | Iustin Pop | """Adds the new node to the cluster.
|
3409 | a8083063 | Iustin Pop |
|
3410 | a8083063 | Iustin Pop | """
|
3411 | a8083063 | Iustin Pop | new_node = self.new_node
|
3412 | a8083063 | Iustin Pop | node = new_node.name |
3413 | a8083063 | Iustin Pop | |
3414 | a8ae3eb5 | Iustin Pop | # for re-adds, reset the offline/drained/master-candidate flags;
|
3415 | a8ae3eb5 | Iustin Pop | # we need to reset here, otherwise offline would prevent RPC calls
|
3416 | a8ae3eb5 | Iustin Pop | # later in the procedure; this also means that if the re-add
|
3417 | a8ae3eb5 | Iustin Pop | # fails, we are left with a non-offlined, broken node
|
3418 | a8ae3eb5 | Iustin Pop | if self.op.readd: |
3419 | 7260cfbe | Iustin Pop | new_node.drained = new_node.offline = False # pylint: disable-msg=W0201 |
3420 | a8ae3eb5 | Iustin Pop | self.LogInfo("Readding a node, the offline/drained flags were reset") |
3421 | a8ae3eb5 | Iustin Pop | # if we demote the node, we do cleanup later in the procedure
|
3422 | a8ae3eb5 | Iustin Pop | new_node.master_candidate = self.master_candidate
|
3423 | 1513e2dd | Iustin Pop | if self.changed_primary_ip: |
3424 | 1513e2dd | Iustin Pop | new_node.primary_ip = self.op.primary_ip
|
3425 | a8ae3eb5 | Iustin Pop | |
3426 | a8ae3eb5 | Iustin Pop | # notify the user about any possible mc promotion
|
3427 | a8ae3eb5 | Iustin Pop | if new_node.master_candidate:
|
3428 | a8ae3eb5 | Iustin Pop | self.LogInfo("Node will be a master candidate") |
3429 | a8ae3eb5 | Iustin Pop | |
3430 | a8083063 | Iustin Pop | # check connectivity
|
3431 | 72737a7f | Iustin Pop | result = self.rpc.call_version([node])[node]
|
3432 | 4c4e4e1e | Iustin Pop | result.Raise("Can't get version information from node %s" % node)
|
3433 | 90b54c26 | Iustin Pop | if constants.PROTOCOL_VERSION == result.payload:
|
3434 | 90b54c26 | Iustin Pop | logging.info("Communication to node %s fine, sw version %s match",
|
3435 | 90b54c26 | Iustin Pop | node, result.payload) |
3436 | a8083063 | Iustin Pop | else:
|
3437 | 90b54c26 | Iustin Pop | raise errors.OpExecError("Version mismatch master version %s," |
3438 | 90b54c26 | Iustin Pop | " node version %s" %
|
3439 | 90b54c26 | Iustin Pop | (constants.PROTOCOL_VERSION, result.payload)) |
3440 | a8083063 | Iustin Pop | |
3441 | a8083063 | Iustin Pop | # setup ssh on node
|
3442 | b989b9d9 | Ken Wehr | if self.cfg.GetClusterInfo().modify_ssh_setup: |
3443 | b989b9d9 | Ken Wehr | logging.info("Copy ssh key to node %s", node)
|
3444 | b989b9d9 | Ken Wehr | priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS) |
3445 | b989b9d9 | Ken Wehr | keyarray = [] |
3446 | b989b9d9 | Ken Wehr | keyfiles = [constants.SSH_HOST_DSA_PRIV, constants.SSH_HOST_DSA_PUB, |
3447 | b989b9d9 | Ken Wehr | constants.SSH_HOST_RSA_PRIV, constants.SSH_HOST_RSA_PUB, |
3448 | b989b9d9 | Ken Wehr | priv_key, pub_key] |
3449 | b989b9d9 | Ken Wehr | |
3450 | b989b9d9 | Ken Wehr | for i in keyfiles: |
3451 | b989b9d9 | Ken Wehr | keyarray.append(utils.ReadFile(i)) |
3452 | b989b9d9 | Ken Wehr | |
3453 | b989b9d9 | Ken Wehr | result = self.rpc.call_node_add(node, keyarray[0], keyarray[1], |
3454 | b989b9d9 | Ken Wehr | keyarray[2], keyarray[3], keyarray[4], |
3455 | b989b9d9 | Ken Wehr | keyarray[5])
|
3456 | b989b9d9 | Ken Wehr | result.Raise("Cannot transfer ssh keys to the new node")
|
3457 | a8083063 | Iustin Pop | |
3458 | a8083063 | Iustin Pop | # Add node to our /etc/hosts, and add key to known_hosts
|
3459 | b86a6bcd | Guido Trotter | if self.cfg.GetClusterInfo().modify_etc_hosts: |
3460 | b86a6bcd | Guido Trotter | utils.AddHostToEtcHosts(new_node.name) |
3461 | c8a0948f | Michael Hanselmann | |
3462 | a8083063 | Iustin Pop | if new_node.secondary_ip != new_node.primary_ip:
|
3463 | 781de953 | Iustin Pop | result = self.rpc.call_node_has_ip_address(new_node.name,
|
3464 | 781de953 | Iustin Pop | new_node.secondary_ip) |
3465 | 4c4e4e1e | Iustin Pop | result.Raise("Failure checking secondary ip on node %s" % new_node.name,
|
3466 | 045dd6d9 | Iustin Pop | prereq=True, ecode=errors.ECODE_ENVIRON)
|
3467 | c2fc8250 | Iustin Pop | if not result.payload: |
3468 | f4bc1f2c | Michael Hanselmann | raise errors.OpExecError("Node claims it doesn't have the secondary ip" |
3469 | f4bc1f2c | Michael Hanselmann | " you gave (%s). Please fix and re-run this"
|
3470 | f4bc1f2c | Michael Hanselmann | " command." % new_node.secondary_ip)
|
3471 | a8083063 | Iustin Pop | |
3472 | d6a02168 | Michael Hanselmann | node_verify_list = [self.cfg.GetMasterNode()]
|
3473 | 5c0527ed | Guido Trotter | node_verify_param = { |
3474 | f60759f7 | Iustin Pop | constants.NV_NODELIST: [node], |
3475 | 5c0527ed | Guido Trotter | # TODO: do a node-net-test as well?
|
3476 | 5c0527ed | Guido Trotter | } |
3477 | 5c0527ed | Guido Trotter | |
3478 | 72737a7f | Iustin Pop | result = self.rpc.call_node_verify(node_verify_list, node_verify_param,
|
3479 | 72737a7f | Iustin Pop | self.cfg.GetClusterName())
|
3480 | 5c0527ed | Guido Trotter | for verifier in node_verify_list: |
3481 | 4c4e4e1e | Iustin Pop | result[verifier].Raise("Cannot communicate with node %s" % verifier)
|
3482 | f60759f7 | Iustin Pop | nl_payload = result[verifier].payload[constants.NV_NODELIST] |
3483 | 6f68a739 | Iustin Pop | if nl_payload:
|
3484 | 6f68a739 | Iustin Pop | for failed in nl_payload: |
3485 | 31821208 | Iustin Pop | feedback_fn("ssh/hostname verification failed"
|
3486 | 31821208 | Iustin Pop | " (checking from %s): %s" %
|
3487 | 6f68a739 | Iustin Pop | (verifier, nl_payload[failed])) |
3488 | 5c0527ed | Guido Trotter | raise errors.OpExecError("ssh/hostname verification failed.") |
3489 | ff98055b | Iustin Pop | |
3490 | d8470559 | Michael Hanselmann | if self.op.readd: |
3491 | 28eddce5 | Guido Trotter | _RedistributeAncillaryFiles(self)
|
3492 | d8470559 | Michael Hanselmann | self.context.ReaddNode(new_node)
|
3493 | a8ae3eb5 | Iustin Pop | # make sure we redistribute the config
|
3494 | a4eae71f | Michael Hanselmann | self.cfg.Update(new_node, feedback_fn)
|
3495 | a8ae3eb5 | Iustin Pop | # and make sure the new node will not have old files around
|
3496 | a8ae3eb5 | Iustin Pop | if not new_node.master_candidate: |
3497 | a8ae3eb5 | Iustin Pop | result = self.rpc.call_node_demote_from_mc(new_node.name)
|
3498 | 3cebe102 | Michael Hanselmann | msg = result.fail_msg |
3499 | a8ae3eb5 | Iustin Pop | if msg:
|
3500 | a8ae3eb5 | Iustin Pop | self.LogWarning("Node failed to demote itself from master" |
3501 | a8ae3eb5 | Iustin Pop | " candidate status: %s" % msg)
|
3502 | d8470559 | Michael Hanselmann | else:
|
3503 | 035566e3 | Iustin Pop | _RedistributeAncillaryFiles(self, additional_nodes=[node])
|
3504 | 0debfb35 | Guido Trotter | self.context.AddNode(new_node, self.proc.GetECId()) |
3505 | a8083063 | Iustin Pop | |
3506 | a8083063 | Iustin Pop | |
3507 | b31c8676 | Iustin Pop | class LUSetNodeParams(LogicalUnit): |
3508 | b31c8676 | Iustin Pop | """Modifies the parameters of a node.
|
3509 | b31c8676 | Iustin Pop |
|
3510 | b31c8676 | Iustin Pop | """
|
3511 | b31c8676 | Iustin Pop | HPATH = "node-modify"
|
3512 | b31c8676 | Iustin Pop | HTYPE = constants.HTYPE_NODE |
3513 | b31c8676 | Iustin Pop | _OP_REQP = ["node_name"]
|
3514 | b31c8676 | Iustin Pop | REQ_BGL = False
|
3515 | b31c8676 | Iustin Pop | |
3516 | b31c8676 | Iustin Pop | def CheckArguments(self): |
3517 | cf26a87a | Iustin Pop | self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name) |
3518 | 3a5ba66a | Iustin Pop | _CheckBooleanOpField(self.op, 'master_candidate') |
3519 | 3a5ba66a | Iustin Pop | _CheckBooleanOpField(self.op, 'offline') |
3520 | c9d443ea | Iustin Pop | _CheckBooleanOpField(self.op, 'drained') |
3521 | 601908d0 | Iustin Pop | _CheckBooleanOpField(self.op, 'auto_promote') |
3522 | c9d443ea | Iustin Pop | all_mods = [self.op.offline, self.op.master_candidate, self.op.drained] |
3523 | c9d443ea | Iustin Pop | if all_mods.count(None) == 3: |
3524 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Please pass at least one modification", |
3525 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3526 | c9d443ea | Iustin Pop | if all_mods.count(True) > 1: |
3527 | c9d443ea | Iustin Pop | raise errors.OpPrereqError("Can't set the node into more than one" |
3528 | 5c983ee5 | Iustin Pop | " state at the same time",
|
3529 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3530 | b31c8676 | Iustin Pop | |
3531 | 601908d0 | Iustin Pop | # Boolean value that tells us whether we're offlining or draining the node
|
3532 | 601908d0 | Iustin Pop | self.offline_or_drain = (self.op.offline == True or |
3533 | 601908d0 | Iustin Pop | self.op.drained == True) |
3534 | 601908d0 | Iustin Pop | self.deoffline_or_drain = (self.op.offline == False or |
3535 | 601908d0 | Iustin Pop | self.op.drained == False) |
3536 | 601908d0 | Iustin Pop | self.might_demote = (self.op.master_candidate == False or |
3537 | 601908d0 | Iustin Pop | self.offline_or_drain)
|
3538 | 601908d0 | Iustin Pop | |
3539 | 601908d0 | Iustin Pop | self.lock_all = self.op.auto_promote and self.might_demote |
3540 | 601908d0 | Iustin Pop | |
3541 | 601908d0 | Iustin Pop | |
3542 | b31c8676 | Iustin Pop | def ExpandNames(self): |
3543 | 601908d0 | Iustin Pop | if self.lock_all: |
3544 | 601908d0 | Iustin Pop | self.needed_locks = {locking.LEVEL_NODE: locking.ALL_SET}
|
3545 | 601908d0 | Iustin Pop | else:
|
3546 | 601908d0 | Iustin Pop | self.needed_locks = {locking.LEVEL_NODE: self.op.node_name} |
3547 | b31c8676 | Iustin Pop | |
3548 | b31c8676 | Iustin Pop | def BuildHooksEnv(self): |
3549 | b31c8676 | Iustin Pop | """Build hooks env.
|
3550 | b31c8676 | Iustin Pop |
|
3551 | b31c8676 | Iustin Pop | This runs on the master node.
|
3552 | b31c8676 | Iustin Pop |
|
3553 | b31c8676 | Iustin Pop | """
|
3554 | b31c8676 | Iustin Pop | env = { |
3555 | b31c8676 | Iustin Pop | "OP_TARGET": self.op.node_name, |
3556 | b31c8676 | Iustin Pop | "MASTER_CANDIDATE": str(self.op.master_candidate), |
3557 | 3a5ba66a | Iustin Pop | "OFFLINE": str(self.op.offline), |
3558 | c9d443ea | Iustin Pop | "DRAINED": str(self.op.drained), |
3559 | b31c8676 | Iustin Pop | } |
3560 | b31c8676 | Iustin Pop | nl = [self.cfg.GetMasterNode(),
|
3561 | b31c8676 | Iustin Pop | self.op.node_name]
|
3562 | b31c8676 | Iustin Pop | return env, nl, nl
|
3563 | b31c8676 | Iustin Pop | |
3564 | b31c8676 | Iustin Pop | def CheckPrereq(self): |
3565 | b31c8676 | Iustin Pop | """Check prerequisites.
|
3566 | b31c8676 | Iustin Pop |
|
3567 | b31c8676 | Iustin Pop | This only checks the instance list against the existing names.
|
3568 | b31c8676 | Iustin Pop |
|
3569 | b31c8676 | Iustin Pop | """
|
3570 | 3a5ba66a | Iustin Pop | node = self.node = self.cfg.GetNodeInfo(self.op.node_name) |
3571 | b31c8676 | Iustin Pop | |
3572 | 97c61d46 | Iustin Pop | if (self.op.master_candidate is not None or |
3573 | 97c61d46 | Iustin Pop | self.op.drained is not None or |
3574 | 97c61d46 | Iustin Pop | self.op.offline is not None): |
3575 | 97c61d46 | Iustin Pop | # we can't change the master's node flags
|
3576 | 97c61d46 | Iustin Pop | if self.op.node_name == self.cfg.GetMasterNode(): |
3577 | 97c61d46 | Iustin Pop | raise errors.OpPrereqError("The master role can be changed" |
3578 | 5c983ee5 | Iustin Pop | " only via masterfailover",
|
3579 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3580 | 97c61d46 | Iustin Pop | |
3581 | 601908d0 | Iustin Pop | |
3582 | 601908d0 | Iustin Pop | if node.master_candidate and self.might_demote and not self.lock_all: |
3583 | 601908d0 | Iustin Pop | assert not self.op.auto_promote, "auto-promote set but lock_all not" |
3584 | 601908d0 | Iustin Pop | # check if after removing the current node, we're missing master
|
3585 | 601908d0 | Iustin Pop | # candidates
|
3586 | 601908d0 | Iustin Pop | (mc_remaining, mc_should, _) = \ |
3587 | 601908d0 | Iustin Pop | self.cfg.GetMasterCandidateStats(exceptions=[node.name])
|
3588 | 8fe9239e | Iustin Pop | if mc_remaining < mc_should:
|
3589 | 601908d0 | Iustin Pop | raise errors.OpPrereqError("Not enough master candidates, please" |
3590 | 601908d0 | Iustin Pop | " pass auto_promote to allow promotion",
|
3591 | 601908d0 | Iustin Pop | errors.ECODE_INVAL) |
3592 | 3e83dd48 | Iustin Pop | |
3593 | c9d443ea | Iustin Pop | if (self.op.master_candidate == True and |
3594 | c9d443ea | Iustin Pop | ((node.offline and not self.op.offline == False) or |
3595 | c9d443ea | Iustin Pop | (node.drained and not self.op.drained == False))): |
3596 | c9d443ea | Iustin Pop | raise errors.OpPrereqError("Node '%s' is offline or drained, can't set" |
3597 | 5c983ee5 | Iustin Pop | " to master_candidate" % node.name,
|
3598 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3599 | 3a5ba66a | Iustin Pop | |
3600 | 3d9eb52b | Guido Trotter | # If we're being deofflined/drained, we'll MC ourself if needed
|
3601 | 601908d0 | Iustin Pop | if (self.deoffline_or_drain and not self.offline_or_drain and not |
3602 | cea0534a | Guido Trotter | self.op.master_candidate == True and not node.master_candidate): |
3603 | 3d9eb52b | Guido Trotter | self.op.master_candidate = _DecideSelfPromotion(self) |
3604 | 3d9eb52b | Guido Trotter | if self.op.master_candidate: |
3605 | 3d9eb52b | Guido Trotter | self.LogInfo("Autopromoting node to master candidate") |
3606 | 3d9eb52b | Guido Trotter | |
3607 | b31c8676 | Iustin Pop | return
|
3608 | b31c8676 | Iustin Pop | |
3609 | b31c8676 | Iustin Pop | def Exec(self, feedback_fn): |
3610 | b31c8676 | Iustin Pop | """Modifies a node.
|
3611 | b31c8676 | Iustin Pop |
|
3612 | b31c8676 | Iustin Pop | """
|
3613 | 3a5ba66a | Iustin Pop | node = self.node
|
3614 | b31c8676 | Iustin Pop | |
3615 | b31c8676 | Iustin Pop | result = [] |
3616 | c9d443ea | Iustin Pop | changed_mc = False
|
3617 | b31c8676 | Iustin Pop | |
3618 | 3a5ba66a | Iustin Pop | if self.op.offline is not None: |
3619 | 3a5ba66a | Iustin Pop | node.offline = self.op.offline
|
3620 | 3a5ba66a | Iustin Pop | result.append(("offline", str(self.op.offline))) |
3621 | c9d443ea | Iustin Pop | if self.op.offline == True: |
3622 | c9d443ea | Iustin Pop | if node.master_candidate:
|
3623 | c9d443ea | Iustin Pop | node.master_candidate = False
|
3624 | c9d443ea | Iustin Pop | changed_mc = True
|
3625 | c9d443ea | Iustin Pop | result.append(("master_candidate", "auto-demotion due to offline")) |
3626 | c9d443ea | Iustin Pop | if node.drained:
|
3627 | c9d443ea | Iustin Pop | node.drained = False
|
3628 | c9d443ea | Iustin Pop | result.append(("drained", "clear drained status due to offline")) |
3629 | 3a5ba66a | Iustin Pop | |
3630 | b31c8676 | Iustin Pop | if self.op.master_candidate is not None: |
3631 | b31c8676 | Iustin Pop | node.master_candidate = self.op.master_candidate
|
3632 | c9d443ea | Iustin Pop | changed_mc = True
|
3633 | b31c8676 | Iustin Pop | result.append(("master_candidate", str(self.op.master_candidate))) |
3634 | 56aa9fd5 | Iustin Pop | if self.op.master_candidate == False: |
3635 | 56aa9fd5 | Iustin Pop | rrc = self.rpc.call_node_demote_from_mc(node.name)
|
3636 | 4c4e4e1e | Iustin Pop | msg = rrc.fail_msg |
3637 | 0959c824 | Iustin Pop | if msg:
|
3638 | 0959c824 | Iustin Pop | self.LogWarning("Node failed to demote itself: %s" % msg) |
3639 | b31c8676 | Iustin Pop | |
3640 | c9d443ea | Iustin Pop | if self.op.drained is not None: |
3641 | c9d443ea | Iustin Pop | node.drained = self.op.drained
|
3642 | 82e12743 | Iustin Pop | result.append(("drained", str(self.op.drained))) |
3643 | c9d443ea | Iustin Pop | if self.op.drained == True: |
3644 | c9d443ea | Iustin Pop | if node.master_candidate:
|
3645 | c9d443ea | Iustin Pop | node.master_candidate = False
|
3646 | c9d443ea | Iustin Pop | changed_mc = True
|
3647 | c9d443ea | Iustin Pop | result.append(("master_candidate", "auto-demotion due to drain")) |
3648 | dec0d9da | Iustin Pop | rrc = self.rpc.call_node_demote_from_mc(node.name)
|
3649 | 3cebe102 | Michael Hanselmann | msg = rrc.fail_msg |
3650 | dec0d9da | Iustin Pop | if msg:
|
3651 | dec0d9da | Iustin Pop | self.LogWarning("Node failed to demote itself: %s" % msg) |
3652 | c9d443ea | Iustin Pop | if node.offline:
|
3653 | c9d443ea | Iustin Pop | node.offline = False
|
3654 | c9d443ea | Iustin Pop | result.append(("offline", "clear offline status due to drain")) |
3655 | c9d443ea | Iustin Pop | |
3656 | 601908d0 | Iustin Pop | # we locked all nodes, we adjust the CP before updating this node
|
3657 | 601908d0 | Iustin Pop | if self.lock_all: |
3658 | 601908d0 | Iustin Pop | _AdjustCandidatePool(self, [node.name])
|
3659 | 601908d0 | Iustin Pop | |
3660 | b31c8676 | Iustin Pop | # this will trigger configuration file update, if needed
|
3661 | a4eae71f | Michael Hanselmann | self.cfg.Update(node, feedback_fn)
|
3662 | 601908d0 | Iustin Pop | |
3663 | b31c8676 | Iustin Pop | # this will trigger job queue propagation or cleanup
|
3664 | c9d443ea | Iustin Pop | if changed_mc:
|
3665 | 3a26773f | Iustin Pop | self.context.ReaddNode(node)
|
3666 | b31c8676 | Iustin Pop | |
3667 | b31c8676 | Iustin Pop | return result
|
3668 | b31c8676 | Iustin Pop | |
3669 | b31c8676 | Iustin Pop | |
3670 | f5118ade | Iustin Pop | class LUPowercycleNode(NoHooksLU): |
3671 | f5118ade | Iustin Pop | """Powercycles a node.
|
3672 | f5118ade | Iustin Pop |
|
3673 | f5118ade | Iustin Pop | """
|
3674 | f5118ade | Iustin Pop | _OP_REQP = ["node_name", "force"] |
3675 | f5118ade | Iustin Pop | REQ_BGL = False
|
3676 | f5118ade | Iustin Pop | |
3677 | f5118ade | Iustin Pop | def CheckArguments(self): |
3678 | cf26a87a | Iustin Pop | self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name) |
3679 | cf26a87a | Iustin Pop | if self.op.node_name == self.cfg.GetMasterNode() and not self.op.force: |
3680 | f5118ade | Iustin Pop | raise errors.OpPrereqError("The node is the master and the force" |
3681 | 5c983ee5 | Iustin Pop | " parameter was not set",
|
3682 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
3683 | f5118ade | Iustin Pop | |
3684 | f5118ade | Iustin Pop | def ExpandNames(self): |
3685 | f5118ade | Iustin Pop | """Locking for PowercycleNode.
|
3686 | f5118ade | Iustin Pop |
|
3687 | efb8da02 | Michael Hanselmann | This is a last-resort option and shouldn't block on other
|
3688 | f5118ade | Iustin Pop | jobs. Therefore, we grab no locks.
|
3689 | f5118ade | Iustin Pop |
|
3690 | f5118ade | Iustin Pop | """
|
3691 | f5118ade | Iustin Pop | self.needed_locks = {}
|
3692 | f5118ade | Iustin Pop | |
3693 | f5118ade | Iustin Pop | def CheckPrereq(self): |
3694 | f5118ade | Iustin Pop | """Check prerequisites.
|
3695 | f5118ade | Iustin Pop |
|
3696 | f5118ade | Iustin Pop | This LU has no prereqs.
|
3697 | f5118ade | Iustin Pop |
|
3698 | f5118ade | Iustin Pop | """
|
3699 | f5118ade | Iustin Pop | pass
|
3700 | f5118ade | Iustin Pop | |
3701 | f5118ade | Iustin Pop | def Exec(self, feedback_fn): |
3702 | f5118ade | Iustin Pop | """Reboots a node.
|
3703 | f5118ade | Iustin Pop |
|
3704 | f5118ade | Iustin Pop | """
|
3705 | f5118ade | Iustin Pop | result = self.rpc.call_node_powercycle(self.op.node_name, |
3706 | f5118ade | Iustin Pop | self.cfg.GetHypervisorType())
|
3707 | 4c4e4e1e | Iustin Pop | result.Raise("Failed to schedule the reboot")
|
3708 | f5118ade | Iustin Pop | return result.payload
|
3709 | f5118ade | Iustin Pop | |
3710 | f5118ade | Iustin Pop | |
3711 | a8083063 | Iustin Pop | class LUQueryClusterInfo(NoHooksLU): |
3712 | a8083063 | Iustin Pop | """Query cluster configuration.
|
3713 | a8083063 | Iustin Pop |
|
3714 | a8083063 | Iustin Pop | """
|
3715 | a8083063 | Iustin Pop | _OP_REQP = [] |
3716 | 642339cf | Guido Trotter | REQ_BGL = False
|
3717 | 642339cf | Guido Trotter | |
3718 | 642339cf | Guido Trotter | def ExpandNames(self): |
3719 | 642339cf | Guido Trotter | self.needed_locks = {}
|
3720 | a8083063 | Iustin Pop | |
3721 | a8083063 | Iustin Pop | def CheckPrereq(self): |
3722 | a8083063 | Iustin Pop | """No prerequsites needed for this LU.
|
3723 | a8083063 | Iustin Pop |
|
3724 | a8083063 | Iustin Pop | """
|
3725 | a8083063 | Iustin Pop | pass
|
3726 | a8083063 | Iustin Pop | |
3727 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
3728 | a8083063 | Iustin Pop | """Return cluster config.
|
3729 | a8083063 | Iustin Pop |
|
3730 | a8083063 | Iustin Pop | """
|
3731 | 469f88e1 | Iustin Pop | cluster = self.cfg.GetClusterInfo()
|
3732 | 17463d22 | René Nussbaumer | os_hvp = {} |
3733 | 17463d22 | René Nussbaumer | |
3734 | 17463d22 | René Nussbaumer | # Filter just for enabled hypervisors
|
3735 | 17463d22 | René Nussbaumer | for os_name, hv_dict in cluster.os_hvp.items(): |
3736 | 17463d22 | René Nussbaumer | os_hvp[os_name] = {} |
3737 | 17463d22 | René Nussbaumer | for hv_name, hv_params in hv_dict.items(): |
3738 | 17463d22 | René Nussbaumer | if hv_name in cluster.enabled_hypervisors: |
3739 | 17463d22 | René Nussbaumer | os_hvp[os_name][hv_name] = hv_params |
3740 | 17463d22 | René Nussbaumer | |
3741 | a8083063 | Iustin Pop | result = { |
3742 | a8083063 | Iustin Pop | "software_version": constants.RELEASE_VERSION,
|
3743 | a8083063 | Iustin Pop | "protocol_version": constants.PROTOCOL_VERSION,
|
3744 | a8083063 | Iustin Pop | "config_version": constants.CONFIG_VERSION,
|
3745 | d1a7d66f | Guido Trotter | "os_api_version": max(constants.OS_API_VERSIONS), |
3746 | a8083063 | Iustin Pop | "export_version": constants.EXPORT_VERSION,
|
3747 | a8083063 | Iustin Pop | "architecture": (platform.architecture()[0], platform.machine()), |
3748 | 469f88e1 | Iustin Pop | "name": cluster.cluster_name,
|
3749 | 469f88e1 | Iustin Pop | "master": cluster.master_node,
|
3750 | 066f465d | Guido Trotter | "default_hypervisor": cluster.enabled_hypervisors[0], |
3751 | 469f88e1 | Iustin Pop | "enabled_hypervisors": cluster.enabled_hypervisors,
|
3752 | b8810fec | Michael Hanselmann | "hvparams": dict([(hypervisor_name, cluster.hvparams[hypervisor_name]) |
3753 | 7c4d6c7b | Michael Hanselmann | for hypervisor_name in cluster.enabled_hypervisors]), |
3754 | 17463d22 | René Nussbaumer | "os_hvp": os_hvp,
|
3755 | 469f88e1 | Iustin Pop | "beparams": cluster.beparams,
|
3756 | 1094acda | Guido Trotter | "nicparams": cluster.nicparams,
|
3757 | 4b7735f9 | Iustin Pop | "candidate_pool_size": cluster.candidate_pool_size,
|
3758 | 7a56b411 | Guido Trotter | "master_netdev": cluster.master_netdev,
|
3759 | 7a56b411 | Guido Trotter | "volume_group_name": cluster.volume_group_name,
|
3760 | 7a56b411 | Guido Trotter | "file_storage_dir": cluster.file_storage_dir,
|
3761 | 3953242f | Iustin Pop | "maintain_node_health": cluster.maintain_node_health,
|
3762 | 90f72445 | Iustin Pop | "ctime": cluster.ctime,
|
3763 | 90f72445 | Iustin Pop | "mtime": cluster.mtime,
|
3764 | 259578eb | Iustin Pop | "uuid": cluster.uuid,
|
3765 | c118d1f4 | Michael Hanselmann | "tags": list(cluster.GetTags()), |
3766 | 1338f2b4 | Balazs Lecz | "uid_pool": cluster.uid_pool,
|
3767 | a8083063 | Iustin Pop | } |
3768 | a8083063 | Iustin Pop | |
3769 | a8083063 | Iustin Pop | return result
|
3770 | a8083063 | Iustin Pop | |
3771 | a8083063 | Iustin Pop | |
3772 | ae5849b5 | Michael Hanselmann | class LUQueryConfigValues(NoHooksLU): |
3773 | ae5849b5 | Michael Hanselmann | """Return configuration values.
|
3774 | a8083063 | Iustin Pop |
|
3775 | a8083063 | Iustin Pop | """
|
3776 | a8083063 | Iustin Pop | _OP_REQP = [] |
3777 | 642339cf | Guido Trotter | REQ_BGL = False
|
3778 | a2d2e1a7 | Iustin Pop | _FIELDS_DYNAMIC = utils.FieldSet() |
3779 | 05e50653 | Michael Hanselmann | _FIELDS_STATIC = utils.FieldSet("cluster_name", "master_node", "drain_flag", |
3780 | 05e50653 | Michael Hanselmann | "watcher_pause")
|
3781 | 642339cf | Guido Trotter | |
3782 | 642339cf | Guido Trotter | def ExpandNames(self): |
3783 | 642339cf | Guido Trotter | self.needed_locks = {}
|
3784 | a8083063 | Iustin Pop | |
3785 | 31bf511f | Iustin Pop | _CheckOutputFields(static=self._FIELDS_STATIC,
|
3786 | 31bf511f | Iustin Pop | dynamic=self._FIELDS_DYNAMIC,
|
3787 | ae5849b5 | Michael Hanselmann | selected=self.op.output_fields)
|
3788 | ae5849b5 | Michael Hanselmann | |
3789 | a8083063 | Iustin Pop | def CheckPrereq(self): |
3790 | a8083063 | Iustin Pop | """No prerequisites.
|
3791 | a8083063 | Iustin Pop |
|
3792 | a8083063 | Iustin Pop | """
|
3793 | a8083063 | Iustin Pop | pass
|
3794 | a8083063 | Iustin Pop | |
3795 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
3796 | a8083063 | Iustin Pop | """Dump a representation of the cluster config to the standard output.
|
3797 | a8083063 | Iustin Pop |
|
3798 | a8083063 | Iustin Pop | """
|
3799 | ae5849b5 | Michael Hanselmann | values = [] |
3800 | ae5849b5 | Michael Hanselmann | for field in self.op.output_fields: |
3801 | ae5849b5 | Michael Hanselmann | if field == "cluster_name": |
3802 | 3ccafd0e | Iustin Pop | entry = self.cfg.GetClusterName()
|
3803 | ae5849b5 | Michael Hanselmann | elif field == "master_node": |
3804 | 3ccafd0e | Iustin Pop | entry = self.cfg.GetMasterNode()
|
3805 | 3ccafd0e | Iustin Pop | elif field == "drain_flag": |
3806 | 3ccafd0e | Iustin Pop | entry = os.path.exists(constants.JOB_QUEUE_DRAIN_FILE) |
3807 | 05e50653 | Michael Hanselmann | elif field == "watcher_pause": |
3808 | cac599f1 | Michael Hanselmann | entry = utils.ReadWatcherPauseFile(constants.WATCHER_PAUSEFILE) |
3809 | ae5849b5 | Michael Hanselmann | else:
|
3810 | ae5849b5 | Michael Hanselmann | raise errors.ParameterError(field)
|
3811 | 3ccafd0e | Iustin Pop | values.append(entry) |
3812 | ae5849b5 | Michael Hanselmann | return values
|
3813 | a8083063 | Iustin Pop | |
3814 | a8083063 | Iustin Pop | |
3815 | a8083063 | Iustin Pop | class LUActivateInstanceDisks(NoHooksLU): |
3816 | a8083063 | Iustin Pop | """Bring up an instance's disks.
|
3817 | a8083063 | Iustin Pop |
|
3818 | a8083063 | Iustin Pop | """
|
3819 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name"]
|
3820 | f22a8ba3 | Guido Trotter | REQ_BGL = False
|
3821 | f22a8ba3 | Guido Trotter | |
3822 | f22a8ba3 | Guido Trotter | def ExpandNames(self): |
3823 | f22a8ba3 | Guido Trotter | self._ExpandAndLockInstance()
|
3824 | f22a8ba3 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
3825 | f22a8ba3 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
3826 | f22a8ba3 | Guido Trotter | |
3827 | f22a8ba3 | Guido Trotter | def DeclareLocks(self, level): |
3828 | f22a8ba3 | Guido Trotter | if level == locking.LEVEL_NODE:
|
3829 | f22a8ba3 | Guido Trotter | self._LockInstancesNodes()
|
3830 | a8083063 | Iustin Pop | |
3831 | a8083063 | Iustin Pop | def CheckPrereq(self): |
3832 | a8083063 | Iustin Pop | """Check prerequisites.
|
3833 | a8083063 | Iustin Pop |
|
3834 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
3835 | a8083063 | Iustin Pop |
|
3836 | a8083063 | Iustin Pop | """
|
3837 | f22a8ba3 | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
3838 | f22a8ba3 | Guido Trotter | assert self.instance is not None, \ |
3839 | f22a8ba3 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
3840 | 43017d26 | Iustin Pop | _CheckNodeOnline(self, self.instance.primary_node) |
3841 | b4ec07f8 | Iustin Pop | if not hasattr(self.op, "ignore_size"): |
3842 | b4ec07f8 | Iustin Pop | self.op.ignore_size = False |
3843 | a8083063 | Iustin Pop | |
3844 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
3845 | a8083063 | Iustin Pop | """Activate the disks.
|
3846 | a8083063 | Iustin Pop |
|
3847 | a8083063 | Iustin Pop | """
|
3848 | b4ec07f8 | Iustin Pop | disks_ok, disks_info = \ |
3849 | b4ec07f8 | Iustin Pop | _AssembleInstanceDisks(self, self.instance, |
3850 | b4ec07f8 | Iustin Pop | ignore_size=self.op.ignore_size)
|
3851 | a8083063 | Iustin Pop | if not disks_ok: |
3852 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Cannot activate block devices") |
3853 | a8083063 | Iustin Pop | |
3854 | a8083063 | Iustin Pop | return disks_info
|
3855 | a8083063 | Iustin Pop | |
3856 | a8083063 | Iustin Pop | |
3857 | e3443b36 | Iustin Pop | def _AssembleInstanceDisks(lu, instance, ignore_secondaries=False, |
3858 | e3443b36 | Iustin Pop | ignore_size=False):
|
3859 | a8083063 | Iustin Pop | """Prepare the block devices for an instance.
|
3860 | a8083063 | Iustin Pop |
|
3861 | a8083063 | Iustin Pop | This sets up the block devices on all nodes.
|
3862 | a8083063 | Iustin Pop |
|
3863 | e4376078 | Iustin Pop | @type lu: L{LogicalUnit}
|
3864 | e4376078 | Iustin Pop | @param lu: the logical unit on whose behalf we execute
|
3865 | e4376078 | Iustin Pop | @type instance: L{objects.Instance}
|
3866 | e4376078 | Iustin Pop | @param instance: the instance for whose disks we assemble
|
3867 | e4376078 | Iustin Pop | @type ignore_secondaries: boolean
|
3868 | e4376078 | Iustin Pop | @param ignore_secondaries: if true, errors on secondary nodes
|
3869 | e4376078 | Iustin Pop | won't result in an error return from the function
|
3870 | e3443b36 | Iustin Pop | @type ignore_size: boolean
|
3871 | e3443b36 | Iustin Pop | @param ignore_size: if true, the current known size of the disk
|
3872 | e3443b36 | Iustin Pop | will not be used during the disk activation, useful for cases
|
3873 | e3443b36 | Iustin Pop | when the size is wrong
|
3874 | e4376078 | Iustin Pop | @return: False if the operation failed, otherwise a list of
|
3875 | e4376078 | Iustin Pop | (host, instance_visible_name, node_visible_name)
|
3876 | e4376078 | Iustin Pop | with the mapping from node devices to instance devices
|
3877 | a8083063 | Iustin Pop |
|
3878 | a8083063 | Iustin Pop | """
|
3879 | a8083063 | Iustin Pop | device_info = [] |
3880 | a8083063 | Iustin Pop | disks_ok = True
|
3881 | fdbd668d | Iustin Pop | iname = instance.name |
3882 | fdbd668d | Iustin Pop | # With the two passes mechanism we try to reduce the window of
|
3883 | fdbd668d | Iustin Pop | # opportunity for the race condition of switching DRBD to primary
|
3884 | fdbd668d | Iustin Pop | # before handshaking occured, but we do not eliminate it
|
3885 | fdbd668d | Iustin Pop | |
3886 | fdbd668d | Iustin Pop | # The proper fix would be to wait (with some limits) until the
|
3887 | fdbd668d | Iustin Pop | # connection has been made and drbd transitions from WFConnection
|
3888 | fdbd668d | Iustin Pop | # into any other network-connected state (Connected, SyncTarget,
|
3889 | fdbd668d | Iustin Pop | # SyncSource, etc.)
|
3890 | fdbd668d | Iustin Pop | |
3891 | fdbd668d | Iustin Pop | # 1st pass, assemble on all nodes in secondary mode
|
3892 | a8083063 | Iustin Pop | for inst_disk in instance.disks: |
3893 | a8083063 | Iustin Pop | for node, node_disk in inst_disk.ComputeNodeTree(instance.primary_node): |
3894 | e3443b36 | Iustin Pop | if ignore_size:
|
3895 | e3443b36 | Iustin Pop | node_disk = node_disk.Copy() |
3896 | e3443b36 | Iustin Pop | node_disk.UnsetSize() |
3897 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(node_disk, node) |
3898 | 72737a7f | Iustin Pop | result = lu.rpc.call_blockdev_assemble(node, node_disk, iname, False)
|
3899 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
3900 | 53c14ef1 | Iustin Pop | if msg:
|
3901 | 86d9d3bb | Iustin Pop | lu.proc.LogWarning("Could not prepare block device %s on node %s"
|
3902 | 53c14ef1 | Iustin Pop | " (is_primary=False, pass=1): %s",
|
3903 | 53c14ef1 | Iustin Pop | inst_disk.iv_name, node, msg) |
3904 | fdbd668d | Iustin Pop | if not ignore_secondaries: |
3905 | a8083063 | Iustin Pop | disks_ok = False
|
3906 | fdbd668d | Iustin Pop | |
3907 | fdbd668d | Iustin Pop | # FIXME: race condition on drbd migration to primary
|
3908 | fdbd668d | Iustin Pop | |
3909 | fdbd668d | Iustin Pop | # 2nd pass, do only the primary node
|
3910 | fdbd668d | Iustin Pop | for inst_disk in instance.disks: |
3911 | d52ea991 | Michael Hanselmann | dev_path = None
|
3912 | d52ea991 | Michael Hanselmann | |
3913 | fdbd668d | Iustin Pop | for node, node_disk in inst_disk.ComputeNodeTree(instance.primary_node): |
3914 | fdbd668d | Iustin Pop | if node != instance.primary_node:
|
3915 | fdbd668d | Iustin Pop | continue
|
3916 | e3443b36 | Iustin Pop | if ignore_size:
|
3917 | e3443b36 | Iustin Pop | node_disk = node_disk.Copy() |
3918 | e3443b36 | Iustin Pop | node_disk.UnsetSize() |
3919 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(node_disk, node) |
3920 | 72737a7f | Iustin Pop | result = lu.rpc.call_blockdev_assemble(node, node_disk, iname, True)
|
3921 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
3922 | 53c14ef1 | Iustin Pop | if msg:
|
3923 | 86d9d3bb | Iustin Pop | lu.proc.LogWarning("Could not prepare block device %s on node %s"
|
3924 | 53c14ef1 | Iustin Pop | " (is_primary=True, pass=2): %s",
|
3925 | 53c14ef1 | Iustin Pop | inst_disk.iv_name, node, msg) |
3926 | fdbd668d | Iustin Pop | disks_ok = False
|
3927 | d52ea991 | Michael Hanselmann | else:
|
3928 | d52ea991 | Michael Hanselmann | dev_path = result.payload |
3929 | d52ea991 | Michael Hanselmann | |
3930 | d52ea991 | Michael Hanselmann | device_info.append((instance.primary_node, inst_disk.iv_name, dev_path)) |
3931 | a8083063 | Iustin Pop | |
3932 | b352ab5b | Iustin Pop | # leave the disks configured for the primary node
|
3933 | b352ab5b | Iustin Pop | # this is a workaround that would be fixed better by
|
3934 | b352ab5b | Iustin Pop | # improving the logical/physical id handling
|
3935 | b352ab5b | Iustin Pop | for disk in instance.disks: |
3936 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(disk, instance.primary_node) |
3937 | b352ab5b | Iustin Pop | |
3938 | a8083063 | Iustin Pop | return disks_ok, device_info
|
3939 | a8083063 | Iustin Pop | |
3940 | a8083063 | Iustin Pop | |
3941 | b9bddb6b | Iustin Pop | def _StartInstanceDisks(lu, instance, force): |
3942 | 3ecf6786 | Iustin Pop | """Start the disks of an instance.
|
3943 | 3ecf6786 | Iustin Pop |
|
3944 | 3ecf6786 | Iustin Pop | """
|
3945 | 7c4d6c7b | Michael Hanselmann | disks_ok, _ = _AssembleInstanceDisks(lu, instance, |
3946 | fe7b0351 | Michael Hanselmann | ignore_secondaries=force) |
3947 | fe7b0351 | Michael Hanselmann | if not disks_ok: |
3948 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(lu, instance) |
3949 | fe7b0351 | Michael Hanselmann | if force is not None and not force: |
3950 | 86d9d3bb | Iustin Pop | lu.proc.LogWarning("", hint="If the message above refers to a" |
3951 | 86d9d3bb | Iustin Pop | " secondary node,"
|
3952 | 86d9d3bb | Iustin Pop | " you can retry the operation using '--force'.")
|
3953 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Disk consistency error") |
3954 | fe7b0351 | Michael Hanselmann | |
3955 | fe7b0351 | Michael Hanselmann | |
3956 | a8083063 | Iustin Pop | class LUDeactivateInstanceDisks(NoHooksLU): |
3957 | a8083063 | Iustin Pop | """Shutdown an instance's disks.
|
3958 | a8083063 | Iustin Pop |
|
3959 | a8083063 | Iustin Pop | """
|
3960 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name"]
|
3961 | f22a8ba3 | Guido Trotter | REQ_BGL = False
|
3962 | f22a8ba3 | Guido Trotter | |
3963 | f22a8ba3 | Guido Trotter | def ExpandNames(self): |
3964 | f22a8ba3 | Guido Trotter | self._ExpandAndLockInstance()
|
3965 | f22a8ba3 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
3966 | f22a8ba3 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
3967 | f22a8ba3 | Guido Trotter | |
3968 | f22a8ba3 | Guido Trotter | def DeclareLocks(self, level): |
3969 | f22a8ba3 | Guido Trotter | if level == locking.LEVEL_NODE:
|
3970 | f22a8ba3 | Guido Trotter | self._LockInstancesNodes()
|
3971 | a8083063 | Iustin Pop | |
3972 | a8083063 | Iustin Pop | def CheckPrereq(self): |
3973 | a8083063 | Iustin Pop | """Check prerequisites.
|
3974 | a8083063 | Iustin Pop |
|
3975 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
3976 | a8083063 | Iustin Pop |
|
3977 | a8083063 | Iustin Pop | """
|
3978 | f22a8ba3 | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
3979 | f22a8ba3 | Guido Trotter | assert self.instance is not None, \ |
3980 | f22a8ba3 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
3981 | a8083063 | Iustin Pop | |
3982 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
3983 | a8083063 | Iustin Pop | """Deactivate the disks
|
3984 | a8083063 | Iustin Pop |
|
3985 | a8083063 | Iustin Pop | """
|
3986 | a8083063 | Iustin Pop | instance = self.instance
|
3987 | b9bddb6b | Iustin Pop | _SafeShutdownInstanceDisks(self, instance)
|
3988 | a8083063 | Iustin Pop | |
3989 | a8083063 | Iustin Pop | |
3990 | b9bddb6b | Iustin Pop | def _SafeShutdownInstanceDisks(lu, instance): |
3991 | 155d6c75 | Guido Trotter | """Shutdown block devices of an instance.
|
3992 | 155d6c75 | Guido Trotter |
|
3993 | 155d6c75 | Guido Trotter | This function checks if an instance is running, before calling
|
3994 | 155d6c75 | Guido Trotter | _ShutdownInstanceDisks.
|
3995 | 155d6c75 | Guido Trotter |
|
3996 | 155d6c75 | Guido Trotter | """
|
3997 | 31624382 | Iustin Pop | _CheckInstanceDown(lu, instance, "cannot shutdown disks")
|
3998 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(lu, instance) |
3999 | a8083063 | Iustin Pop | |
4000 | a8083063 | Iustin Pop | |
4001 | b9bddb6b | Iustin Pop | def _ShutdownInstanceDisks(lu, instance, ignore_primary=False): |
4002 | a8083063 | Iustin Pop | """Shutdown block devices of an instance.
|
4003 | a8083063 | Iustin Pop |
|
4004 | a8083063 | Iustin Pop | This does the shutdown on all nodes of the instance.
|
4005 | a8083063 | Iustin Pop |
|
4006 | a8083063 | Iustin Pop | If the ignore_primary is false, errors on the primary node are
|
4007 | a8083063 | Iustin Pop | ignored.
|
4008 | a8083063 | Iustin Pop |
|
4009 | a8083063 | Iustin Pop | """
|
4010 | cacfd1fd | Iustin Pop | all_result = True
|
4011 | a8083063 | Iustin Pop | for disk in instance.disks: |
4012 | a8083063 | Iustin Pop | for node, top_disk in disk.ComputeNodeTree(instance.primary_node): |
4013 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(top_disk, node) |
4014 | 781de953 | Iustin Pop | result = lu.rpc.call_blockdev_shutdown(node, top_disk) |
4015 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
4016 | cacfd1fd | Iustin Pop | if msg:
|
4017 | cacfd1fd | Iustin Pop | lu.LogWarning("Could not shutdown block device %s on node %s: %s",
|
4018 | cacfd1fd | Iustin Pop | disk.iv_name, node, msg) |
4019 | a8083063 | Iustin Pop | if not ignore_primary or node != instance.primary_node: |
4020 | cacfd1fd | Iustin Pop | all_result = False
|
4021 | cacfd1fd | Iustin Pop | return all_result
|
4022 | a8083063 | Iustin Pop | |
4023 | a8083063 | Iustin Pop | |
4024 | 9ca87a96 | Iustin Pop | def _CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name): |
4025 | d4f16fd9 | Iustin Pop | """Checks if a node has enough free memory.
|
4026 | d4f16fd9 | Iustin Pop |
|
4027 | d4f16fd9 | Iustin Pop | This function check if a given node has the needed amount of free
|
4028 | d4f16fd9 | Iustin Pop | memory. In case the node has less memory or we cannot get the
|
4029 | d4f16fd9 | Iustin Pop | information from the node, this function raise an OpPrereqError
|
4030 | d4f16fd9 | Iustin Pop | exception.
|
4031 | d4f16fd9 | Iustin Pop |
|
4032 | b9bddb6b | Iustin Pop | @type lu: C{LogicalUnit}
|
4033 | b9bddb6b | Iustin Pop | @param lu: a logical unit from which we get configuration data
|
4034 | e69d05fd | Iustin Pop | @type node: C{str}
|
4035 | e69d05fd | Iustin Pop | @param node: the node to check
|
4036 | e69d05fd | Iustin Pop | @type reason: C{str}
|
4037 | e69d05fd | Iustin Pop | @param reason: string to use in the error message
|
4038 | e69d05fd | Iustin Pop | @type requested: C{int}
|
4039 | e69d05fd | Iustin Pop | @param requested: the amount of memory in MiB to check for
|
4040 | 9ca87a96 | Iustin Pop | @type hypervisor_name: C{str}
|
4041 | 9ca87a96 | Iustin Pop | @param hypervisor_name: the hypervisor to ask for memory stats
|
4042 | e69d05fd | Iustin Pop | @raise errors.OpPrereqError: if the node doesn't have enough memory, or
|
4043 | e69d05fd | Iustin Pop | we cannot check the node
|
4044 | d4f16fd9 | Iustin Pop |
|
4045 | d4f16fd9 | Iustin Pop | """
|
4046 | 9ca87a96 | Iustin Pop | nodeinfo = lu.rpc.call_node_info([node], lu.cfg.GetVGName(), hypervisor_name) |
4047 | 045dd6d9 | Iustin Pop | nodeinfo[node].Raise("Can't get data from node %s" % node,
|
4048 | 045dd6d9 | Iustin Pop | prereq=True, ecode=errors.ECODE_ENVIRON)
|
4049 | 070e998b | Iustin Pop | free_mem = nodeinfo[node].payload.get('memory_free', None) |
4050 | d4f16fd9 | Iustin Pop | if not isinstance(free_mem, int): |
4051 | d4f16fd9 | Iustin Pop | raise errors.OpPrereqError("Can't compute free memory on node %s, result" |
4052 | 5c983ee5 | Iustin Pop | " was '%s'" % (node, free_mem),
|
4053 | 5c983ee5 | Iustin Pop | errors.ECODE_ENVIRON) |
4054 | d4f16fd9 | Iustin Pop | if requested > free_mem:
|
4055 | d4f16fd9 | Iustin Pop | raise errors.OpPrereqError("Not enough memory on node %s for %s:" |
4056 | 070e998b | Iustin Pop | " needed %s MiB, available %s MiB" %
|
4057 | 5c983ee5 | Iustin Pop | (node, reason, requested, free_mem), |
4058 | 5c983ee5 | Iustin Pop | errors.ECODE_NORES) |
4059 | d4f16fd9 | Iustin Pop | |
4060 | d4f16fd9 | Iustin Pop | |
4061 | 701384a9 | Iustin Pop | def _CheckNodesFreeDisk(lu, nodenames, requested): |
4062 | 701384a9 | Iustin Pop | """Checks if nodes have enough free disk space in the default VG.
|
4063 | 701384a9 | Iustin Pop |
|
4064 | 701384a9 | Iustin Pop | This function check if all given nodes have the needed amount of
|
4065 | 701384a9 | Iustin Pop | free disk. In case any node has less disk or we cannot get the
|
4066 | 701384a9 | Iustin Pop | information from the node, this function raise an OpPrereqError
|
4067 | 701384a9 | Iustin Pop | exception.
|
4068 | 701384a9 | Iustin Pop |
|
4069 | 701384a9 | Iustin Pop | @type lu: C{LogicalUnit}
|
4070 | 701384a9 | Iustin Pop | @param lu: a logical unit from which we get configuration data
|
4071 | 701384a9 | Iustin Pop | @type nodenames: C{list}
|
4072 | 3a488770 | Iustin Pop | @param nodenames: the list of node names to check
|
4073 | 701384a9 | Iustin Pop | @type requested: C{int}
|
4074 | 701384a9 | Iustin Pop | @param requested: the amount of disk in MiB to check for
|
4075 | 701384a9 | Iustin Pop | @raise errors.OpPrereqError: if the node doesn't have enough disk, or
|
4076 | 701384a9 | Iustin Pop | we cannot check the node
|
4077 | 701384a9 | Iustin Pop |
|
4078 | 701384a9 | Iustin Pop | """
|
4079 | 701384a9 | Iustin Pop | nodeinfo = lu.rpc.call_node_info(nodenames, lu.cfg.GetVGName(), |
4080 | 701384a9 | Iustin Pop | lu.cfg.GetHypervisorType()) |
4081 | 701384a9 | Iustin Pop | for node in nodenames: |
4082 | 701384a9 | Iustin Pop | info = nodeinfo[node] |
4083 | 701384a9 | Iustin Pop | info.Raise("Cannot get current information from node %s" % node,
|
4084 | 701384a9 | Iustin Pop | prereq=True, ecode=errors.ECODE_ENVIRON)
|
4085 | 701384a9 | Iustin Pop | vg_free = info.payload.get("vg_free", None) |
4086 | 701384a9 | Iustin Pop | if not isinstance(vg_free, int): |
4087 | 701384a9 | Iustin Pop | raise errors.OpPrereqError("Can't compute free disk space on node %s," |
4088 | 701384a9 | Iustin Pop | " result was '%s'" % (node, vg_free),
|
4089 | 701384a9 | Iustin Pop | errors.ECODE_ENVIRON) |
4090 | 701384a9 | Iustin Pop | if requested > vg_free:
|
4091 | 701384a9 | Iustin Pop | raise errors.OpPrereqError("Not enough disk space on target node %s:" |
4092 | 701384a9 | Iustin Pop | " required %d MiB, available %d MiB" %
|
4093 | 701384a9 | Iustin Pop | (node, requested, vg_free), |
4094 | 701384a9 | Iustin Pop | errors.ECODE_NORES) |
4095 | 701384a9 | Iustin Pop | |
4096 | 701384a9 | Iustin Pop | |
4097 | a8083063 | Iustin Pop | class LUStartupInstance(LogicalUnit): |
4098 | a8083063 | Iustin Pop | """Starts an instance.
|
4099 | a8083063 | Iustin Pop |
|
4100 | a8083063 | Iustin Pop | """
|
4101 | a8083063 | Iustin Pop | HPATH = "instance-start"
|
4102 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
4103 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name", "force"] |
4104 | e873317a | Guido Trotter | REQ_BGL = False
|
4105 | e873317a | Guido Trotter | |
4106 | e873317a | Guido Trotter | def ExpandNames(self): |
4107 | e873317a | Guido Trotter | self._ExpandAndLockInstance()
|
4108 | a8083063 | Iustin Pop | |
4109 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
4110 | a8083063 | Iustin Pop | """Build hooks env.
|
4111 | a8083063 | Iustin Pop |
|
4112 | a8083063 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
4113 | a8083063 | Iustin Pop |
|
4114 | a8083063 | Iustin Pop | """
|
4115 | a8083063 | Iustin Pop | env = { |
4116 | a8083063 | Iustin Pop | "FORCE": self.op.force, |
4117 | a8083063 | Iustin Pop | } |
4118 | 338e51e8 | Iustin Pop | env.update(_BuildInstanceHookEnvByObject(self, self.instance)) |
4119 | 6b12959c | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
4120 | a8083063 | Iustin Pop | return env, nl, nl
|
4121 | a8083063 | Iustin Pop | |
4122 | a8083063 | Iustin Pop | def CheckPrereq(self): |
4123 | a8083063 | Iustin Pop | """Check prerequisites.
|
4124 | a8083063 | Iustin Pop |
|
4125 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
4126 | a8083063 | Iustin Pop |
|
4127 | a8083063 | Iustin Pop | """
|
4128 | e873317a | Guido Trotter | self.instance = instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4129 | e873317a | Guido Trotter | assert self.instance is not None, \ |
4130 | e873317a | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
4131 | a8083063 | Iustin Pop | |
4132 | d04aaa2f | Iustin Pop | # extra beparams
|
4133 | d04aaa2f | Iustin Pop | self.beparams = getattr(self.op, "beparams", {}) |
4134 | d04aaa2f | Iustin Pop | if self.beparams: |
4135 | d04aaa2f | Iustin Pop | if not isinstance(self.beparams, dict): |
4136 | d04aaa2f | Iustin Pop | raise errors.OpPrereqError("Invalid beparams passed: %s, expected" |
4137 | 5c983ee5 | Iustin Pop | " dict" % (type(self.beparams), ), |
4138 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
4139 | d04aaa2f | Iustin Pop | # fill the beparams dict
|
4140 | d04aaa2f | Iustin Pop | utils.ForceDictType(self.beparams, constants.BES_PARAMETER_TYPES)
|
4141 | d04aaa2f | Iustin Pop | self.op.beparams = self.beparams |
4142 | d04aaa2f | Iustin Pop | |
4143 | d04aaa2f | Iustin Pop | # extra hvparams
|
4144 | d04aaa2f | Iustin Pop | self.hvparams = getattr(self.op, "hvparams", {}) |
4145 | d04aaa2f | Iustin Pop | if self.hvparams: |
4146 | d04aaa2f | Iustin Pop | if not isinstance(self.hvparams, dict): |
4147 | d04aaa2f | Iustin Pop | raise errors.OpPrereqError("Invalid hvparams passed: %s, expected" |
4148 | 5c983ee5 | Iustin Pop | " dict" % (type(self.hvparams), ), |
4149 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
4150 | d04aaa2f | Iustin Pop | |
4151 | d04aaa2f | Iustin Pop | # check hypervisor parameter syntax (locally)
|
4152 | d04aaa2f | Iustin Pop | cluster = self.cfg.GetClusterInfo()
|
4153 | d04aaa2f | Iustin Pop | utils.ForceDictType(self.hvparams, constants.HVS_PARAMETER_TYPES)
|
4154 | abe609b2 | Guido Trotter | filled_hvp = objects.FillDict(cluster.hvparams[instance.hypervisor], |
4155 | d04aaa2f | Iustin Pop | instance.hvparams) |
4156 | d04aaa2f | Iustin Pop | filled_hvp.update(self.hvparams)
|
4157 | d04aaa2f | Iustin Pop | hv_type = hypervisor.GetHypervisor(instance.hypervisor) |
4158 | d04aaa2f | Iustin Pop | hv_type.CheckParameterSyntax(filled_hvp) |
4159 | d04aaa2f | Iustin Pop | _CheckHVParams(self, instance.all_nodes, instance.hypervisor, filled_hvp)
|
4160 | d04aaa2f | Iustin Pop | self.op.hvparams = self.hvparams |
4161 | d04aaa2f | Iustin Pop | |
4162 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, instance.primary_node)
|
4163 | 7527a8a4 | Iustin Pop | |
4164 | 338e51e8 | Iustin Pop | bep = self.cfg.GetClusterInfo().FillBE(instance)
|
4165 | 5bbd3f7f | Michael Hanselmann | # check bridges existence
|
4166 | b9bddb6b | Iustin Pop | _CheckInstanceBridgesExist(self, instance)
|
4167 | a8083063 | Iustin Pop | |
4168 | f1926756 | Guido Trotter | remote_info = self.rpc.call_instance_info(instance.primary_node,
|
4169 | f1926756 | Guido Trotter | instance.name, |
4170 | f1926756 | Guido Trotter | instance.hypervisor) |
4171 | 4c4e4e1e | Iustin Pop | remote_info.Raise("Error checking node %s" % instance.primary_node,
|
4172 | 045dd6d9 | Iustin Pop | prereq=True, ecode=errors.ECODE_ENVIRON)
|
4173 | 7ad1af4a | Iustin Pop | if not remote_info.payload: # not running already |
4174 | f1926756 | Guido Trotter | _CheckNodeFreeMemory(self, instance.primary_node,
|
4175 | f1926756 | Guido Trotter | "starting instance %s" % instance.name,
|
4176 | f1926756 | Guido Trotter | bep[constants.BE_MEMORY], instance.hypervisor) |
4177 | d4f16fd9 | Iustin Pop | |
4178 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
4179 | a8083063 | Iustin Pop | """Start the instance.
|
4180 | a8083063 | Iustin Pop |
|
4181 | a8083063 | Iustin Pop | """
|
4182 | a8083063 | Iustin Pop | instance = self.instance
|
4183 | a8083063 | Iustin Pop | force = self.op.force
|
4184 | a8083063 | Iustin Pop | |
4185 | fe482621 | Iustin Pop | self.cfg.MarkInstanceUp(instance.name)
|
4186 | fe482621 | Iustin Pop | |
4187 | a8083063 | Iustin Pop | node_current = instance.primary_node |
4188 | a8083063 | Iustin Pop | |
4189 | b9bddb6b | Iustin Pop | _StartInstanceDisks(self, instance, force)
|
4190 | a8083063 | Iustin Pop | |
4191 | d04aaa2f | Iustin Pop | result = self.rpc.call_instance_start(node_current, instance,
|
4192 | d04aaa2f | Iustin Pop | self.hvparams, self.beparams) |
4193 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
4194 | dd279568 | Iustin Pop | if msg:
|
4195 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
4196 | dd279568 | Iustin Pop | raise errors.OpExecError("Could not start instance: %s" % msg) |
4197 | a8083063 | Iustin Pop | |
4198 | a8083063 | Iustin Pop | |
4199 | bf6929a2 | Alexander Schreiber | class LURebootInstance(LogicalUnit): |
4200 | bf6929a2 | Alexander Schreiber | """Reboot an instance.
|
4201 | bf6929a2 | Alexander Schreiber |
|
4202 | bf6929a2 | Alexander Schreiber | """
|
4203 | bf6929a2 | Alexander Schreiber | HPATH = "instance-reboot"
|
4204 | bf6929a2 | Alexander Schreiber | HTYPE = constants.HTYPE_INSTANCE |
4205 | bf6929a2 | Alexander Schreiber | _OP_REQP = ["instance_name", "ignore_secondaries", "reboot_type"] |
4206 | e873317a | Guido Trotter | REQ_BGL = False
|
4207 | e873317a | Guido Trotter | |
4208 | 17c3f802 | Guido Trotter | def CheckArguments(self): |
4209 | 17c3f802 | Guido Trotter | """Check the arguments.
|
4210 | 17c3f802 | Guido Trotter |
|
4211 | 17c3f802 | Guido Trotter | """
|
4212 | 17c3f802 | Guido Trotter | self.shutdown_timeout = getattr(self.op, "shutdown_timeout", |
4213 | 17c3f802 | Guido Trotter | constants.DEFAULT_SHUTDOWN_TIMEOUT) |
4214 | 17c3f802 | Guido Trotter | |
4215 | e873317a | Guido Trotter | def ExpandNames(self): |
4216 | 0fcc5db3 | Guido Trotter | if self.op.reboot_type not in [constants.INSTANCE_REBOOT_SOFT, |
4217 | 0fcc5db3 | Guido Trotter | constants.INSTANCE_REBOOT_HARD, |
4218 | 0fcc5db3 | Guido Trotter | constants.INSTANCE_REBOOT_FULL]: |
4219 | 0fcc5db3 | Guido Trotter | raise errors.ParameterError("reboot type not in [%s, %s, %s]" % |
4220 | 0fcc5db3 | Guido Trotter | (constants.INSTANCE_REBOOT_SOFT, |
4221 | 0fcc5db3 | Guido Trotter | constants.INSTANCE_REBOOT_HARD, |
4222 | 0fcc5db3 | Guido Trotter | constants.INSTANCE_REBOOT_FULL)) |
4223 | e873317a | Guido Trotter | self._ExpandAndLockInstance()
|
4224 | bf6929a2 | Alexander Schreiber | |
4225 | bf6929a2 | Alexander Schreiber | def BuildHooksEnv(self): |
4226 | bf6929a2 | Alexander Schreiber | """Build hooks env.
|
4227 | bf6929a2 | Alexander Schreiber |
|
4228 | bf6929a2 | Alexander Schreiber | This runs on master, primary and secondary nodes of the instance.
|
4229 | bf6929a2 | Alexander Schreiber |
|
4230 | bf6929a2 | Alexander Schreiber | """
|
4231 | bf6929a2 | Alexander Schreiber | env = { |
4232 | bf6929a2 | Alexander Schreiber | "IGNORE_SECONDARIES": self.op.ignore_secondaries, |
4233 | 2c2690c9 | Iustin Pop | "REBOOT_TYPE": self.op.reboot_type, |
4234 | 17c3f802 | Guido Trotter | "SHUTDOWN_TIMEOUT": self.shutdown_timeout, |
4235 | bf6929a2 | Alexander Schreiber | } |
4236 | 338e51e8 | Iustin Pop | env.update(_BuildInstanceHookEnvByObject(self, self.instance)) |
4237 | 6b12959c | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
4238 | bf6929a2 | Alexander Schreiber | return env, nl, nl
|
4239 | bf6929a2 | Alexander Schreiber | |
4240 | bf6929a2 | Alexander Schreiber | def CheckPrereq(self): |
4241 | bf6929a2 | Alexander Schreiber | """Check prerequisites.
|
4242 | bf6929a2 | Alexander Schreiber |
|
4243 | bf6929a2 | Alexander Schreiber | This checks that the instance is in the cluster.
|
4244 | bf6929a2 | Alexander Schreiber |
|
4245 | bf6929a2 | Alexander Schreiber | """
|
4246 | e873317a | Guido Trotter | self.instance = instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4247 | e873317a | Guido Trotter | assert self.instance is not None, \ |
4248 | e873317a | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
4249 | bf6929a2 | Alexander Schreiber | |
4250 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, instance.primary_node)
|
4251 | 7527a8a4 | Iustin Pop | |
4252 | 5bbd3f7f | Michael Hanselmann | # check bridges existence
|
4253 | b9bddb6b | Iustin Pop | _CheckInstanceBridgesExist(self, instance)
|
4254 | bf6929a2 | Alexander Schreiber | |
4255 | bf6929a2 | Alexander Schreiber | def Exec(self, feedback_fn): |
4256 | bf6929a2 | Alexander Schreiber | """Reboot the instance.
|
4257 | bf6929a2 | Alexander Schreiber |
|
4258 | bf6929a2 | Alexander Schreiber | """
|
4259 | bf6929a2 | Alexander Schreiber | instance = self.instance
|
4260 | bf6929a2 | Alexander Schreiber | ignore_secondaries = self.op.ignore_secondaries
|
4261 | bf6929a2 | Alexander Schreiber | reboot_type = self.op.reboot_type
|
4262 | bf6929a2 | Alexander Schreiber | |
4263 | bf6929a2 | Alexander Schreiber | node_current = instance.primary_node |
4264 | bf6929a2 | Alexander Schreiber | |
4265 | bf6929a2 | Alexander Schreiber | if reboot_type in [constants.INSTANCE_REBOOT_SOFT, |
4266 | bf6929a2 | Alexander Schreiber | constants.INSTANCE_REBOOT_HARD]: |
4267 | ae48ac32 | Iustin Pop | for disk in instance.disks: |
4268 | ae48ac32 | Iustin Pop | self.cfg.SetDiskID(disk, node_current)
|
4269 | 781de953 | Iustin Pop | result = self.rpc.call_instance_reboot(node_current, instance,
|
4270 | 17c3f802 | Guido Trotter | reboot_type, |
4271 | 17c3f802 | Guido Trotter | self.shutdown_timeout)
|
4272 | 4c4e4e1e | Iustin Pop | result.Raise("Could not reboot instance")
|
4273 | bf6929a2 | Alexander Schreiber | else:
|
4274 | 17c3f802 | Guido Trotter | result = self.rpc.call_instance_shutdown(node_current, instance,
|
4275 | 17c3f802 | Guido Trotter | self.shutdown_timeout)
|
4276 | 4c4e4e1e | Iustin Pop | result.Raise("Could not shutdown instance for full reboot")
|
4277 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
4278 | b9bddb6b | Iustin Pop | _StartInstanceDisks(self, instance, ignore_secondaries)
|
4279 | 0eca8e0c | Iustin Pop | result = self.rpc.call_instance_start(node_current, instance, None, None) |
4280 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
4281 | dd279568 | Iustin Pop | if msg:
|
4282 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
4283 | dd279568 | Iustin Pop | raise errors.OpExecError("Could not start instance for" |
4284 | dd279568 | Iustin Pop | " full reboot: %s" % msg)
|
4285 | bf6929a2 | Alexander Schreiber | |
4286 | bf6929a2 | Alexander Schreiber | self.cfg.MarkInstanceUp(instance.name)
|
4287 | bf6929a2 | Alexander Schreiber | |
4288 | bf6929a2 | Alexander Schreiber | |
4289 | a8083063 | Iustin Pop | class LUShutdownInstance(LogicalUnit): |
4290 | a8083063 | Iustin Pop | """Shutdown an instance.
|
4291 | a8083063 | Iustin Pop |
|
4292 | a8083063 | Iustin Pop | """
|
4293 | a8083063 | Iustin Pop | HPATH = "instance-stop"
|
4294 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
4295 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name"]
|
4296 | e873317a | Guido Trotter | REQ_BGL = False
|
4297 | e873317a | Guido Trotter | |
4298 | 6263189c | Guido Trotter | def CheckArguments(self): |
4299 | 6263189c | Guido Trotter | """Check the arguments.
|
4300 | 6263189c | Guido Trotter |
|
4301 | 6263189c | Guido Trotter | """
|
4302 | 6263189c | Guido Trotter | self.timeout = getattr(self.op, "timeout", |
4303 | 6263189c | Guido Trotter | constants.DEFAULT_SHUTDOWN_TIMEOUT) |
4304 | 6263189c | Guido Trotter | |
4305 | e873317a | Guido Trotter | def ExpandNames(self): |
4306 | e873317a | Guido Trotter | self._ExpandAndLockInstance()
|
4307 | a8083063 | Iustin Pop | |
4308 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
4309 | a8083063 | Iustin Pop | """Build hooks env.
|
4310 | a8083063 | Iustin Pop |
|
4311 | a8083063 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
4312 | a8083063 | Iustin Pop |
|
4313 | a8083063 | Iustin Pop | """
|
4314 | 338e51e8 | Iustin Pop | env = _BuildInstanceHookEnvByObject(self, self.instance) |
4315 | 6263189c | Guido Trotter | env["TIMEOUT"] = self.timeout |
4316 | 6b12959c | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
4317 | a8083063 | Iustin Pop | return env, nl, nl
|
4318 | a8083063 | Iustin Pop | |
4319 | a8083063 | Iustin Pop | def CheckPrereq(self): |
4320 | a8083063 | Iustin Pop | """Check prerequisites.
|
4321 | a8083063 | Iustin Pop |
|
4322 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
4323 | a8083063 | Iustin Pop |
|
4324 | a8083063 | Iustin Pop | """
|
4325 | e873317a | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4326 | e873317a | Guido Trotter | assert self.instance is not None, \ |
4327 | e873317a | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
4328 | 43017d26 | Iustin Pop | _CheckNodeOnline(self, self.instance.primary_node) |
4329 | a8083063 | Iustin Pop | |
4330 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
4331 | a8083063 | Iustin Pop | """Shutdown the instance.
|
4332 | a8083063 | Iustin Pop |
|
4333 | a8083063 | Iustin Pop | """
|
4334 | a8083063 | Iustin Pop | instance = self.instance
|
4335 | a8083063 | Iustin Pop | node_current = instance.primary_node |
4336 | 6263189c | Guido Trotter | timeout = self.timeout
|
4337 | fe482621 | Iustin Pop | self.cfg.MarkInstanceDown(instance.name)
|
4338 | 6263189c | Guido Trotter | result = self.rpc.call_instance_shutdown(node_current, instance, timeout)
|
4339 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
4340 | 1fae010f | Iustin Pop | if msg:
|
4341 | 1fae010f | Iustin Pop | self.proc.LogWarning("Could not shutdown instance: %s" % msg) |
4342 | a8083063 | Iustin Pop | |
4343 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
4344 | a8083063 | Iustin Pop | |
4345 | a8083063 | Iustin Pop | |
4346 | fe7b0351 | Michael Hanselmann | class LUReinstallInstance(LogicalUnit): |
4347 | fe7b0351 | Michael Hanselmann | """Reinstall an instance.
|
4348 | fe7b0351 | Michael Hanselmann |
|
4349 | fe7b0351 | Michael Hanselmann | """
|
4350 | fe7b0351 | Michael Hanselmann | HPATH = "instance-reinstall"
|
4351 | fe7b0351 | Michael Hanselmann | HTYPE = constants.HTYPE_INSTANCE |
4352 | fe7b0351 | Michael Hanselmann | _OP_REQP = ["instance_name"]
|
4353 | 4e0b4d2d | Guido Trotter | REQ_BGL = False
|
4354 | 4e0b4d2d | Guido Trotter | |
4355 | 4e0b4d2d | Guido Trotter | def ExpandNames(self): |
4356 | 4e0b4d2d | Guido Trotter | self._ExpandAndLockInstance()
|
4357 | fe7b0351 | Michael Hanselmann | |
4358 | fe7b0351 | Michael Hanselmann | def BuildHooksEnv(self): |
4359 | fe7b0351 | Michael Hanselmann | """Build hooks env.
|
4360 | fe7b0351 | Michael Hanselmann |
|
4361 | fe7b0351 | Michael Hanselmann | This runs on master, primary and secondary nodes of the instance.
|
4362 | fe7b0351 | Michael Hanselmann |
|
4363 | fe7b0351 | Michael Hanselmann | """
|
4364 | 338e51e8 | Iustin Pop | env = _BuildInstanceHookEnvByObject(self, self.instance) |
4365 | 6b12959c | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
4366 | fe7b0351 | Michael Hanselmann | return env, nl, nl
|
4367 | fe7b0351 | Michael Hanselmann | |
4368 | fe7b0351 | Michael Hanselmann | def CheckPrereq(self): |
4369 | fe7b0351 | Michael Hanselmann | """Check prerequisites.
|
4370 | fe7b0351 | Michael Hanselmann |
|
4371 | fe7b0351 | Michael Hanselmann | This checks that the instance is in the cluster and is not running.
|
4372 | fe7b0351 | Michael Hanselmann |
|
4373 | fe7b0351 | Michael Hanselmann | """
|
4374 | 4e0b4d2d | Guido Trotter | instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4375 | 4e0b4d2d | Guido Trotter | assert instance is not None, \ |
4376 | 4e0b4d2d | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
4377 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, instance.primary_node)
|
4378 | 4e0b4d2d | Guido Trotter | |
4379 | fe7b0351 | Michael Hanselmann | if instance.disk_template == constants.DT_DISKLESS:
|
4380 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Instance '%s' has no disks" % |
4381 | 5c983ee5 | Iustin Pop | self.op.instance_name,
|
4382 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
4383 | 31624382 | Iustin Pop | _CheckInstanceDown(self, instance, "cannot reinstall") |
4384 | d0834de3 | Michael Hanselmann | |
4385 | d0834de3 | Michael Hanselmann | self.op.os_type = getattr(self.op, "os_type", None) |
4386 | f2c05717 | Guido Trotter | self.op.force_variant = getattr(self.op, "force_variant", False) |
4387 | d0834de3 | Michael Hanselmann | if self.op.os_type is not None: |
4388 | d0834de3 | Michael Hanselmann | # OS verification
|
4389 | cf26a87a | Iustin Pop | pnode = _ExpandNodeName(self.cfg, instance.primary_node)
|
4390 | 231cd901 | Iustin Pop | _CheckNodeHasOS(self, pnode, self.op.os_type, self.op.force_variant) |
4391 | d0834de3 | Michael Hanselmann | |
4392 | fe7b0351 | Michael Hanselmann | self.instance = instance
|
4393 | fe7b0351 | Michael Hanselmann | |
4394 | fe7b0351 | Michael Hanselmann | def Exec(self, feedback_fn): |
4395 | fe7b0351 | Michael Hanselmann | """Reinstall the instance.
|
4396 | fe7b0351 | Michael Hanselmann |
|
4397 | fe7b0351 | Michael Hanselmann | """
|
4398 | fe7b0351 | Michael Hanselmann | inst = self.instance
|
4399 | fe7b0351 | Michael Hanselmann | |
4400 | d0834de3 | Michael Hanselmann | if self.op.os_type is not None: |
4401 | d0834de3 | Michael Hanselmann | feedback_fn("Changing OS to '%s'..." % self.op.os_type) |
4402 | d0834de3 | Michael Hanselmann | inst.os = self.op.os_type
|
4403 | a4eae71f | Michael Hanselmann | self.cfg.Update(inst, feedback_fn)
|
4404 | d0834de3 | Michael Hanselmann | |
4405 | b9bddb6b | Iustin Pop | _StartInstanceDisks(self, inst, None) |
4406 | fe7b0351 | Michael Hanselmann | try:
|
4407 | fe7b0351 | Michael Hanselmann | feedback_fn("Running the instance OS create scripts...")
|
4408 | 4a0e011f | Iustin Pop | # FIXME: pass debug option from opcode to backend
|
4409 | dd713605 | Iustin Pop | result = self.rpc.call_instance_os_add(inst.primary_node, inst, True, |
4410 | dd713605 | Iustin Pop | self.op.debug_level)
|
4411 | 4c4e4e1e | Iustin Pop | result.Raise("Could not install OS for instance %s on node %s" %
|
4412 | 4c4e4e1e | Iustin Pop | (inst.name, inst.primary_node)) |
4413 | fe7b0351 | Michael Hanselmann | finally:
|
4414 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, inst)
|
4415 | fe7b0351 | Michael Hanselmann | |
4416 | fe7b0351 | Michael Hanselmann | |
4417 | bd315bfa | Iustin Pop | class LURecreateInstanceDisks(LogicalUnit): |
4418 | bd315bfa | Iustin Pop | """Recreate an instance's missing disks.
|
4419 | bd315bfa | Iustin Pop |
|
4420 | bd315bfa | Iustin Pop | """
|
4421 | bd315bfa | Iustin Pop | HPATH = "instance-recreate-disks"
|
4422 | bd315bfa | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
4423 | bd315bfa | Iustin Pop | _OP_REQP = ["instance_name", "disks"] |
4424 | bd315bfa | Iustin Pop | REQ_BGL = False
|
4425 | bd315bfa | Iustin Pop | |
4426 | bd315bfa | Iustin Pop | def CheckArguments(self): |
4427 | bd315bfa | Iustin Pop | """Check the arguments.
|
4428 | bd315bfa | Iustin Pop |
|
4429 | bd315bfa | Iustin Pop | """
|
4430 | bd315bfa | Iustin Pop | if not isinstance(self.op.disks, list): |
4431 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid disks parameter", errors.ECODE_INVAL) |
4432 | bd315bfa | Iustin Pop | for item in self.op.disks: |
4433 | bd315bfa | Iustin Pop | if (not isinstance(item, int) or |
4434 | bd315bfa | Iustin Pop | item < 0):
|
4435 | bd315bfa | Iustin Pop | raise errors.OpPrereqError("Invalid disk specification '%s'" % |
4436 | 5c983ee5 | Iustin Pop | str(item), errors.ECODE_INVAL)
|
4437 | bd315bfa | Iustin Pop | |
4438 | bd315bfa | Iustin Pop | def ExpandNames(self): |
4439 | bd315bfa | Iustin Pop | self._ExpandAndLockInstance()
|
4440 | bd315bfa | Iustin Pop | |
4441 | bd315bfa | Iustin Pop | def BuildHooksEnv(self): |
4442 | bd315bfa | Iustin Pop | """Build hooks env.
|
4443 | bd315bfa | Iustin Pop |
|
4444 | bd315bfa | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
4445 | bd315bfa | Iustin Pop |
|
4446 | bd315bfa | Iustin Pop | """
|
4447 | bd315bfa | Iustin Pop | env = _BuildInstanceHookEnvByObject(self, self.instance) |
4448 | bd315bfa | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
4449 | bd315bfa | Iustin Pop | return env, nl, nl
|
4450 | bd315bfa | Iustin Pop | |
4451 | bd315bfa | Iustin Pop | def CheckPrereq(self): |
4452 | bd315bfa | Iustin Pop | """Check prerequisites.
|
4453 | bd315bfa | Iustin Pop |
|
4454 | bd315bfa | Iustin Pop | This checks that the instance is in the cluster and is not running.
|
4455 | bd315bfa | Iustin Pop |
|
4456 | bd315bfa | Iustin Pop | """
|
4457 | bd315bfa | Iustin Pop | instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4458 | bd315bfa | Iustin Pop | assert instance is not None, \ |
4459 | bd315bfa | Iustin Pop | "Cannot retrieve locked instance %s" % self.op.instance_name |
4460 | bd315bfa | Iustin Pop | _CheckNodeOnline(self, instance.primary_node)
|
4461 | bd315bfa | Iustin Pop | |
4462 | bd315bfa | Iustin Pop | if instance.disk_template == constants.DT_DISKLESS:
|
4463 | bd315bfa | Iustin Pop | raise errors.OpPrereqError("Instance '%s' has no disks" % |
4464 | 5c983ee5 | Iustin Pop | self.op.instance_name, errors.ECODE_INVAL)
|
4465 | 31624382 | Iustin Pop | _CheckInstanceDown(self, instance, "cannot recreate disks") |
4466 | bd315bfa | Iustin Pop | |
4467 | bd315bfa | Iustin Pop | if not self.op.disks: |
4468 | bd315bfa | Iustin Pop | self.op.disks = range(len(instance.disks)) |
4469 | bd315bfa | Iustin Pop | else:
|
4470 | bd315bfa | Iustin Pop | for idx in self.op.disks: |
4471 | bd315bfa | Iustin Pop | if idx >= len(instance.disks): |
4472 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid disk index passed '%s'" % idx, |
4473 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
4474 | bd315bfa | Iustin Pop | |
4475 | bd315bfa | Iustin Pop | self.instance = instance
|
4476 | bd315bfa | Iustin Pop | |
4477 | bd315bfa | Iustin Pop | def Exec(self, feedback_fn): |
4478 | bd315bfa | Iustin Pop | """Recreate the disks.
|
4479 | bd315bfa | Iustin Pop |
|
4480 | bd315bfa | Iustin Pop | """
|
4481 | bd315bfa | Iustin Pop | to_skip = [] |
4482 | 1122eb25 | Iustin Pop | for idx, _ in enumerate(self.instance.disks): |
4483 | bd315bfa | Iustin Pop | if idx not in self.op.disks: # disk idx has not been passed in |
4484 | bd315bfa | Iustin Pop | to_skip.append(idx) |
4485 | bd315bfa | Iustin Pop | continue
|
4486 | bd315bfa | Iustin Pop | |
4487 | bd315bfa | Iustin Pop | _CreateDisks(self, self.instance, to_skip=to_skip) |
4488 | bd315bfa | Iustin Pop | |
4489 | bd315bfa | Iustin Pop | |
4490 | decd5f45 | Iustin Pop | class LURenameInstance(LogicalUnit): |
4491 | decd5f45 | Iustin Pop | """Rename an instance.
|
4492 | decd5f45 | Iustin Pop |
|
4493 | decd5f45 | Iustin Pop | """
|
4494 | decd5f45 | Iustin Pop | HPATH = "instance-rename"
|
4495 | decd5f45 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
4496 | decd5f45 | Iustin Pop | _OP_REQP = ["instance_name", "new_name"] |
4497 | decd5f45 | Iustin Pop | |
4498 | decd5f45 | Iustin Pop | def BuildHooksEnv(self): |
4499 | decd5f45 | Iustin Pop | """Build hooks env.
|
4500 | decd5f45 | Iustin Pop |
|
4501 | decd5f45 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
4502 | decd5f45 | Iustin Pop |
|
4503 | decd5f45 | Iustin Pop | """
|
4504 | 338e51e8 | Iustin Pop | env = _BuildInstanceHookEnvByObject(self, self.instance) |
4505 | decd5f45 | Iustin Pop | env["INSTANCE_NEW_NAME"] = self.op.new_name |
4506 | 6b12959c | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
4507 | decd5f45 | Iustin Pop | return env, nl, nl
|
4508 | decd5f45 | Iustin Pop | |
4509 | decd5f45 | Iustin Pop | def CheckPrereq(self): |
4510 | decd5f45 | Iustin Pop | """Check prerequisites.
|
4511 | decd5f45 | Iustin Pop |
|
4512 | decd5f45 | Iustin Pop | This checks that the instance is in the cluster and is not running.
|
4513 | decd5f45 | Iustin Pop |
|
4514 | decd5f45 | Iustin Pop | """
|
4515 | cf26a87a | Iustin Pop | self.op.instance_name = _ExpandInstanceName(self.cfg, |
4516 | cf26a87a | Iustin Pop | self.op.instance_name)
|
4517 | cf26a87a | Iustin Pop | instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4518 | cf26a87a | Iustin Pop | assert instance is not None |
4519 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, instance.primary_node)
|
4520 | 31624382 | Iustin Pop | _CheckInstanceDown(self, instance, "cannot rename") |
4521 | decd5f45 | Iustin Pop | self.instance = instance
|
4522 | decd5f45 | Iustin Pop | |
4523 | decd5f45 | Iustin Pop | # new name verification
|
4524 | 104f4ca1 | Iustin Pop | name_info = utils.GetHostInfo(self.op.new_name)
|
4525 | decd5f45 | Iustin Pop | |
4526 | 89e1fc26 | Iustin Pop | self.op.new_name = new_name = name_info.name
|
4527 | 7bde3275 | Guido Trotter | instance_list = self.cfg.GetInstanceList()
|
4528 | 7bde3275 | Guido Trotter | if new_name in instance_list: |
4529 | 7bde3275 | Guido Trotter | raise errors.OpPrereqError("Instance '%s' is already in the cluster" % |
4530 | 5c983ee5 | Iustin Pop | new_name, errors.ECODE_EXISTS) |
4531 | 7bde3275 | Guido Trotter | |
4532 | decd5f45 | Iustin Pop | if not getattr(self.op, "ignore_ip", False): |
4533 | 937f983d | Guido Trotter | if utils.TcpPing(name_info.ip, constants.DEFAULT_NODED_PORT):
|
4534 | decd5f45 | Iustin Pop | raise errors.OpPrereqError("IP %s of instance %s already in use" % |
4535 | 5c983ee5 | Iustin Pop | (name_info.ip, new_name), |
4536 | 5c983ee5 | Iustin Pop | errors.ECODE_NOTUNIQUE) |
4537 | decd5f45 | Iustin Pop | |
4538 | decd5f45 | Iustin Pop | |
4539 | decd5f45 | Iustin Pop | def Exec(self, feedback_fn): |
4540 | decd5f45 | Iustin Pop | """Reinstall the instance.
|
4541 | decd5f45 | Iustin Pop |
|
4542 | decd5f45 | Iustin Pop | """
|
4543 | decd5f45 | Iustin Pop | inst = self.instance
|
4544 | decd5f45 | Iustin Pop | old_name = inst.name |
4545 | decd5f45 | Iustin Pop | |
4546 | b23c4333 | Manuel Franceschini | if inst.disk_template == constants.DT_FILE:
|
4547 | b23c4333 | Manuel Franceschini | old_file_storage_dir = os.path.dirname(inst.disks[0].logical_id[1]) |
4548 | b23c4333 | Manuel Franceschini | |
4549 | decd5f45 | Iustin Pop | self.cfg.RenameInstance(inst.name, self.op.new_name) |
4550 | 74b5913f | Guido Trotter | # Change the instance lock. This is definitely safe while we hold the BGL
|
4551 | cb4e8387 | Iustin Pop | self.context.glm.remove(locking.LEVEL_INSTANCE, old_name)
|
4552 | 74b5913f | Guido Trotter | self.context.glm.add(locking.LEVEL_INSTANCE, self.op.new_name) |
4553 | decd5f45 | Iustin Pop | |
4554 | decd5f45 | Iustin Pop | # re-read the instance from the configuration after rename
|
4555 | decd5f45 | Iustin Pop | inst = self.cfg.GetInstanceInfo(self.op.new_name) |
4556 | decd5f45 | Iustin Pop | |
4557 | b23c4333 | Manuel Franceschini | if inst.disk_template == constants.DT_FILE:
|
4558 | b23c4333 | Manuel Franceschini | new_file_storage_dir = os.path.dirname(inst.disks[0].logical_id[1]) |
4559 | 72737a7f | Iustin Pop | result = self.rpc.call_file_storage_dir_rename(inst.primary_node,
|
4560 | 72737a7f | Iustin Pop | old_file_storage_dir, |
4561 | 72737a7f | Iustin Pop | new_file_storage_dir) |
4562 | 4c4e4e1e | Iustin Pop | result.Raise("Could not rename on node %s directory '%s' to '%s'"
|
4563 | 4c4e4e1e | Iustin Pop | " (but the instance has been renamed in Ganeti)" %
|
4564 | 4c4e4e1e | Iustin Pop | (inst.primary_node, old_file_storage_dir, |
4565 | 4c4e4e1e | Iustin Pop | new_file_storage_dir)) |
4566 | b23c4333 | Manuel Franceschini | |
4567 | b9bddb6b | Iustin Pop | _StartInstanceDisks(self, inst, None) |
4568 | decd5f45 | Iustin Pop | try:
|
4569 | 781de953 | Iustin Pop | result = self.rpc.call_instance_run_rename(inst.primary_node, inst,
|
4570 | dd713605 | Iustin Pop | old_name, self.op.debug_level)
|
4571 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
4572 | 96841384 | Iustin Pop | if msg:
|
4573 | 6291574d | Alexander Schreiber | msg = ("Could not run OS rename script for instance %s on node %s"
|
4574 | 96841384 | Iustin Pop | " (but the instance has been renamed in Ganeti): %s" %
|
4575 | 96841384 | Iustin Pop | (inst.name, inst.primary_node, msg)) |
4576 | 86d9d3bb | Iustin Pop | self.proc.LogWarning(msg)
|
4577 | decd5f45 | Iustin Pop | finally:
|
4578 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, inst)
|
4579 | decd5f45 | Iustin Pop | |
4580 | decd5f45 | Iustin Pop | |
4581 | a8083063 | Iustin Pop | class LURemoveInstance(LogicalUnit): |
4582 | a8083063 | Iustin Pop | """Remove an instance.
|
4583 | a8083063 | Iustin Pop |
|
4584 | a8083063 | Iustin Pop | """
|
4585 | a8083063 | Iustin Pop | HPATH = "instance-remove"
|
4586 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
4587 | 5c54b832 | Iustin Pop | _OP_REQP = ["instance_name", "ignore_failures"] |
4588 | cf472233 | Guido Trotter | REQ_BGL = False
|
4589 | cf472233 | Guido Trotter | |
4590 | 17c3f802 | Guido Trotter | def CheckArguments(self): |
4591 | 17c3f802 | Guido Trotter | """Check the arguments.
|
4592 | 17c3f802 | Guido Trotter |
|
4593 | 17c3f802 | Guido Trotter | """
|
4594 | 17c3f802 | Guido Trotter | self.shutdown_timeout = getattr(self.op, "shutdown_timeout", |
4595 | 17c3f802 | Guido Trotter | constants.DEFAULT_SHUTDOWN_TIMEOUT) |
4596 | 17c3f802 | Guido Trotter | |
4597 | cf472233 | Guido Trotter | def ExpandNames(self): |
4598 | cf472233 | Guido Trotter | self._ExpandAndLockInstance()
|
4599 | cf472233 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
4600 | cf472233 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
4601 | cf472233 | Guido Trotter | |
4602 | cf472233 | Guido Trotter | def DeclareLocks(self, level): |
4603 | cf472233 | Guido Trotter | if level == locking.LEVEL_NODE:
|
4604 | cf472233 | Guido Trotter | self._LockInstancesNodes()
|
4605 | a8083063 | Iustin Pop | |
4606 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
4607 | a8083063 | Iustin Pop | """Build hooks env.
|
4608 | a8083063 | Iustin Pop |
|
4609 | a8083063 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
4610 | a8083063 | Iustin Pop |
|
4611 | a8083063 | Iustin Pop | """
|
4612 | 338e51e8 | Iustin Pop | env = _BuildInstanceHookEnvByObject(self, self.instance) |
4613 | 17c3f802 | Guido Trotter | env["SHUTDOWN_TIMEOUT"] = self.shutdown_timeout |
4614 | d6a02168 | Michael Hanselmann | nl = [self.cfg.GetMasterNode()]
|
4615 | abd8e836 | Iustin Pop | nl_post = list(self.instance.all_nodes) + nl |
4616 | abd8e836 | Iustin Pop | return env, nl, nl_post
|
4617 | a8083063 | Iustin Pop | |
4618 | a8083063 | Iustin Pop | def CheckPrereq(self): |
4619 | a8083063 | Iustin Pop | """Check prerequisites.
|
4620 | a8083063 | Iustin Pop |
|
4621 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
4622 | a8083063 | Iustin Pop |
|
4623 | a8083063 | Iustin Pop | """
|
4624 | cf472233 | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4625 | cf472233 | Guido Trotter | assert self.instance is not None, \ |
4626 | cf472233 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
4627 | a8083063 | Iustin Pop | |
4628 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
4629 | a8083063 | Iustin Pop | """Remove the instance.
|
4630 | a8083063 | Iustin Pop |
|
4631 | a8083063 | Iustin Pop | """
|
4632 | a8083063 | Iustin Pop | instance = self.instance
|
4633 | 9a4f63d1 | Iustin Pop | logging.info("Shutting down instance %s on node %s",
|
4634 | 9a4f63d1 | Iustin Pop | instance.name, instance.primary_node) |
4635 | a8083063 | Iustin Pop | |
4636 | 17c3f802 | Guido Trotter | result = self.rpc.call_instance_shutdown(instance.primary_node, instance,
|
4637 | 17c3f802 | Guido Trotter | self.shutdown_timeout)
|
4638 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
4639 | 1fae010f | Iustin Pop | if msg:
|
4640 | 1d67656e | Iustin Pop | if self.op.ignore_failures: |
4641 | 1fae010f | Iustin Pop | feedback_fn("Warning: can't shutdown instance: %s" % msg)
|
4642 | 1d67656e | Iustin Pop | else:
|
4643 | 1fae010f | Iustin Pop | raise errors.OpExecError("Could not shutdown instance %s on" |
4644 | 1fae010f | Iustin Pop | " node %s: %s" %
|
4645 | 1fae010f | Iustin Pop | (instance.name, instance.primary_node, msg)) |
4646 | a8083063 | Iustin Pop | |
4647 | 9a4f63d1 | Iustin Pop | logging.info("Removing block devices for instance %s", instance.name)
|
4648 | a8083063 | Iustin Pop | |
4649 | b9bddb6b | Iustin Pop | if not _RemoveDisks(self, instance): |
4650 | 1d67656e | Iustin Pop | if self.op.ignore_failures: |
4651 | 1d67656e | Iustin Pop | feedback_fn("Warning: can't remove instance's disks")
|
4652 | 1d67656e | Iustin Pop | else:
|
4653 | 1d67656e | Iustin Pop | raise errors.OpExecError("Can't remove instance's disks") |
4654 | a8083063 | Iustin Pop | |
4655 | 9a4f63d1 | Iustin Pop | logging.info("Removing instance %s out of cluster config", instance.name)
|
4656 | a8083063 | Iustin Pop | |
4657 | a8083063 | Iustin Pop | self.cfg.RemoveInstance(instance.name)
|
4658 | cf472233 | Guido Trotter | self.remove_locks[locking.LEVEL_INSTANCE] = instance.name
|
4659 | a8083063 | Iustin Pop | |
4660 | a8083063 | Iustin Pop | |
4661 | a8083063 | Iustin Pop | class LUQueryInstances(NoHooksLU): |
4662 | a8083063 | Iustin Pop | """Logical unit for querying instances.
|
4663 | a8083063 | Iustin Pop |
|
4664 | a8083063 | Iustin Pop | """
|
4665 | 7260cfbe | Iustin Pop | # pylint: disable-msg=W0142
|
4666 | ec79568d | Iustin Pop | _OP_REQP = ["output_fields", "names", "use_locking"] |
4667 | 7eb9d8f7 | Guido Trotter | REQ_BGL = False
|
4668 | 19bed813 | Iustin Pop | _SIMPLE_FIELDS = ["name", "os", "network_port", "hypervisor", |
4669 | 19bed813 | Iustin Pop | "serial_no", "ctime", "mtime", "uuid"] |
4670 | a2d2e1a7 | Iustin Pop | _FIELDS_STATIC = utils.FieldSet(*["name", "os", "pnode", "snodes", |
4671 | 5b460366 | Iustin Pop | "admin_state",
|
4672 | a2d2e1a7 | Iustin Pop | "disk_template", "ip", "mac", "bridge", |
4673 | 638c6349 | Guido Trotter | "nic_mode", "nic_link", |
4674 | a2d2e1a7 | Iustin Pop | "sda_size", "sdb_size", "vcpus", "tags", |
4675 | a2d2e1a7 | Iustin Pop | "network_port", "beparams", |
4676 | 8aec325c | Iustin Pop | r"(disk)\.(size)/([0-9]+)",
|
4677 | 8aec325c | Iustin Pop | r"(disk)\.(sizes)", "disk_usage", |
4678 | 638c6349 | Guido Trotter | r"(nic)\.(mac|ip|mode|link)/([0-9]+)",
|
4679 | 638c6349 | Guido Trotter | r"(nic)\.(bridge)/([0-9]+)",
|
4680 | 638c6349 | Guido Trotter | r"(nic)\.(macs|ips|modes|links|bridges)",
|
4681 | 8aec325c | Iustin Pop | r"(disk|nic)\.(count)",
|
4682 | 19bed813 | Iustin Pop | "hvparams",
|
4683 | 19bed813 | Iustin Pop | ] + _SIMPLE_FIELDS + |
4684 | a2d2e1a7 | Iustin Pop | ["hv/%s" % name
|
4685 | 7736a5f2 | Iustin Pop | for name in constants.HVS_PARAMETERS |
4686 | 7736a5f2 | Iustin Pop | if name not in constants.HVC_GLOBALS] + |
4687 | a2d2e1a7 | Iustin Pop | ["be/%s" % name
|
4688 | a2d2e1a7 | Iustin Pop | for name in constants.BES_PARAMETERS]) |
4689 | a2d2e1a7 | Iustin Pop | _FIELDS_DYNAMIC = utils.FieldSet("oper_state", "oper_ram", "status") |
4690 | 31bf511f | Iustin Pop | |
4691 | a8083063 | Iustin Pop | |
4692 | 7eb9d8f7 | Guido Trotter | def ExpandNames(self): |
4693 | 31bf511f | Iustin Pop | _CheckOutputFields(static=self._FIELDS_STATIC,
|
4694 | 31bf511f | Iustin Pop | dynamic=self._FIELDS_DYNAMIC,
|
4695 | dcb93971 | Michael Hanselmann | selected=self.op.output_fields)
|
4696 | a8083063 | Iustin Pop | |
4697 | 7eb9d8f7 | Guido Trotter | self.needed_locks = {}
|
4698 | 7eb9d8f7 | Guido Trotter | self.share_locks[locking.LEVEL_INSTANCE] = 1 |
4699 | 7eb9d8f7 | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
4700 | 7eb9d8f7 | Guido Trotter | |
4701 | 57a2fb91 | Iustin Pop | if self.op.names: |
4702 | 57a2fb91 | Iustin Pop | self.wanted = _GetWantedInstances(self, self.op.names) |
4703 | 7eb9d8f7 | Guido Trotter | else:
|
4704 | 57a2fb91 | Iustin Pop | self.wanted = locking.ALL_SET
|
4705 | 7eb9d8f7 | Guido Trotter | |
4706 | ec79568d | Iustin Pop | self.do_node_query = self._FIELDS_STATIC.NonMatching(self.op.output_fields) |
4707 | ec79568d | Iustin Pop | self.do_locking = self.do_node_query and self.op.use_locking |
4708 | 57a2fb91 | Iustin Pop | if self.do_locking: |
4709 | 57a2fb91 | Iustin Pop | self.needed_locks[locking.LEVEL_INSTANCE] = self.wanted |
4710 | 57a2fb91 | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = []
|
4711 | 57a2fb91 | Iustin Pop | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
4712 | 7eb9d8f7 | Guido Trotter | |
4713 | 7eb9d8f7 | Guido Trotter | def DeclareLocks(self, level): |
4714 | 57a2fb91 | Iustin Pop | if level == locking.LEVEL_NODE and self.do_locking: |
4715 | 7eb9d8f7 | Guido Trotter | self._LockInstancesNodes()
|
4716 | 7eb9d8f7 | Guido Trotter | |
4717 | 7eb9d8f7 | Guido Trotter | def CheckPrereq(self): |
4718 | 7eb9d8f7 | Guido Trotter | """Check prerequisites.
|
4719 | 7eb9d8f7 | Guido Trotter |
|
4720 | 7eb9d8f7 | Guido Trotter | """
|
4721 | 57a2fb91 | Iustin Pop | pass
|
4722 | 069dcc86 | Iustin Pop | |
4723 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
4724 | a8083063 | Iustin Pop | """Computes the list of nodes and their attributes.
|
4725 | a8083063 | Iustin Pop |
|
4726 | a8083063 | Iustin Pop | """
|
4727 | 7260cfbe | Iustin Pop | # pylint: disable-msg=R0912
|
4728 | 7260cfbe | Iustin Pop | # way too many branches here
|
4729 | 57a2fb91 | Iustin Pop | all_info = self.cfg.GetAllInstancesInfo()
|
4730 | a7f5dc98 | Iustin Pop | if self.wanted == locking.ALL_SET: |
4731 | a7f5dc98 | Iustin Pop | # caller didn't specify instance names, so ordering is not important
|
4732 | a7f5dc98 | Iustin Pop | if self.do_locking: |
4733 | a7f5dc98 | Iustin Pop | instance_names = self.acquired_locks[locking.LEVEL_INSTANCE]
|
4734 | a7f5dc98 | Iustin Pop | else:
|
4735 | a7f5dc98 | Iustin Pop | instance_names = all_info.keys() |
4736 | a7f5dc98 | Iustin Pop | instance_names = utils.NiceSort(instance_names) |
4737 | 57a2fb91 | Iustin Pop | else:
|
4738 | a7f5dc98 | Iustin Pop | # caller did specify names, so we must keep the ordering
|
4739 | a7f5dc98 | Iustin Pop | if self.do_locking: |
4740 | a7f5dc98 | Iustin Pop | tgt_set = self.acquired_locks[locking.LEVEL_INSTANCE]
|
4741 | a7f5dc98 | Iustin Pop | else:
|
4742 | a7f5dc98 | Iustin Pop | tgt_set = all_info.keys() |
4743 | a7f5dc98 | Iustin Pop | missing = set(self.wanted).difference(tgt_set) |
4744 | a7f5dc98 | Iustin Pop | if missing:
|
4745 | a7f5dc98 | Iustin Pop | raise errors.OpExecError("Some instances were removed before" |
4746 | a7f5dc98 | Iustin Pop | " retrieving their data: %s" % missing)
|
4747 | a7f5dc98 | Iustin Pop | instance_names = self.wanted
|
4748 | c1f1cbb2 | Iustin Pop | |
4749 | 57a2fb91 | Iustin Pop | instance_list = [all_info[iname] for iname in instance_names] |
4750 | a8083063 | Iustin Pop | |
4751 | a8083063 | Iustin Pop | # begin data gathering
|
4752 | a8083063 | Iustin Pop | |
4753 | a8083063 | Iustin Pop | nodes = frozenset([inst.primary_node for inst in instance_list]) |
4754 | e69d05fd | Iustin Pop | hv_list = list(set([inst.hypervisor for inst in instance_list])) |
4755 | a8083063 | Iustin Pop | |
4756 | a8083063 | Iustin Pop | bad_nodes = [] |
4757 | cbfc4681 | Iustin Pop | off_nodes = [] |
4758 | ec79568d | Iustin Pop | if self.do_node_query: |
4759 | a8083063 | Iustin Pop | live_data = {} |
4760 | 72737a7f | Iustin Pop | node_data = self.rpc.call_all_instances_info(nodes, hv_list)
|
4761 | a8083063 | Iustin Pop | for name in nodes: |
4762 | a8083063 | Iustin Pop | result = node_data[name] |
4763 | cbfc4681 | Iustin Pop | if result.offline:
|
4764 | cbfc4681 | Iustin Pop | # offline nodes will be in both lists
|
4765 | cbfc4681 | Iustin Pop | off_nodes.append(name) |
4766 | 3cebe102 | Michael Hanselmann | if result.fail_msg:
|
4767 | a8083063 | Iustin Pop | bad_nodes.append(name) |
4768 | 781de953 | Iustin Pop | else:
|
4769 | 2fa74ef4 | Iustin Pop | if result.payload:
|
4770 | 2fa74ef4 | Iustin Pop | live_data.update(result.payload) |
4771 | 2fa74ef4 | Iustin Pop | # else no instance is alive
|
4772 | a8083063 | Iustin Pop | else:
|
4773 | a8083063 | Iustin Pop | live_data = dict([(name, {}) for name in instance_names]) |
4774 | a8083063 | Iustin Pop | |
4775 | a8083063 | Iustin Pop | # end data gathering
|
4776 | a8083063 | Iustin Pop | |
4777 | 5018a335 | Iustin Pop | HVPREFIX = "hv/"
|
4778 | 338e51e8 | Iustin Pop | BEPREFIX = "be/"
|
4779 | a8083063 | Iustin Pop | output = [] |
4780 | 638c6349 | Guido Trotter | cluster = self.cfg.GetClusterInfo()
|
4781 | a8083063 | Iustin Pop | for instance in instance_list: |
4782 | a8083063 | Iustin Pop | iout = [] |
4783 | 7736a5f2 | Iustin Pop | i_hv = cluster.FillHV(instance, skip_globals=True)
|
4784 | 638c6349 | Guido Trotter | i_be = cluster.FillBE(instance) |
4785 | 638c6349 | Guido Trotter | i_nicp = [objects.FillDict(cluster.nicparams[constants.PP_DEFAULT], |
4786 | 638c6349 | Guido Trotter | nic.nicparams) for nic in instance.nics] |
4787 | a8083063 | Iustin Pop | for field in self.op.output_fields: |
4788 | 71c1af58 | Iustin Pop | st_match = self._FIELDS_STATIC.Matches(field)
|
4789 | 19bed813 | Iustin Pop | if field in self._SIMPLE_FIELDS: |
4790 | 19bed813 | Iustin Pop | val = getattr(instance, field)
|
4791 | a8083063 | Iustin Pop | elif field == "pnode": |
4792 | a8083063 | Iustin Pop | val = instance.primary_node |
4793 | a8083063 | Iustin Pop | elif field == "snodes": |
4794 | 8a23d2d3 | Iustin Pop | val = list(instance.secondary_nodes)
|
4795 | a8083063 | Iustin Pop | elif field == "admin_state": |
4796 | 0d68c45d | Iustin Pop | val = instance.admin_up |
4797 | a8083063 | Iustin Pop | elif field == "oper_state": |
4798 | a8083063 | Iustin Pop | if instance.primary_node in bad_nodes: |
4799 | 8a23d2d3 | Iustin Pop | val = None
|
4800 | a8083063 | Iustin Pop | else:
|
4801 | 8a23d2d3 | Iustin Pop | val = bool(live_data.get(instance.name))
|
4802 | d8052456 | Iustin Pop | elif field == "status": |
4803 | cbfc4681 | Iustin Pop | if instance.primary_node in off_nodes: |
4804 | cbfc4681 | Iustin Pop | val = "ERROR_nodeoffline"
|
4805 | cbfc4681 | Iustin Pop | elif instance.primary_node in bad_nodes: |
4806 | d8052456 | Iustin Pop | val = "ERROR_nodedown"
|
4807 | d8052456 | Iustin Pop | else:
|
4808 | d8052456 | Iustin Pop | running = bool(live_data.get(instance.name))
|
4809 | d8052456 | Iustin Pop | if running:
|
4810 | 0d68c45d | Iustin Pop | if instance.admin_up:
|
4811 | d8052456 | Iustin Pop | val = "running"
|
4812 | d8052456 | Iustin Pop | else:
|
4813 | d8052456 | Iustin Pop | val = "ERROR_up"
|
4814 | d8052456 | Iustin Pop | else:
|
4815 | 0d68c45d | Iustin Pop | if instance.admin_up:
|
4816 | d8052456 | Iustin Pop | val = "ERROR_down"
|
4817 | d8052456 | Iustin Pop | else:
|
4818 | d8052456 | Iustin Pop | val = "ADMIN_down"
|
4819 | a8083063 | Iustin Pop | elif field == "oper_ram": |
4820 | a8083063 | Iustin Pop | if instance.primary_node in bad_nodes: |
4821 | 8a23d2d3 | Iustin Pop | val = None
|
4822 | a8083063 | Iustin Pop | elif instance.name in live_data: |
4823 | a8083063 | Iustin Pop | val = live_data[instance.name].get("memory", "?") |
4824 | a8083063 | Iustin Pop | else:
|
4825 | a8083063 | Iustin Pop | val = "-"
|
4826 | c1ce76bb | Iustin Pop | elif field == "vcpus": |
4827 | c1ce76bb | Iustin Pop | val = i_be[constants.BE_VCPUS] |
4828 | a8083063 | Iustin Pop | elif field == "disk_template": |
4829 | a8083063 | Iustin Pop | val = instance.disk_template |
4830 | a8083063 | Iustin Pop | elif field == "ip": |
4831 | 39a02558 | Guido Trotter | if instance.nics:
|
4832 | 39a02558 | Guido Trotter | val = instance.nics[0].ip
|
4833 | 39a02558 | Guido Trotter | else:
|
4834 | 39a02558 | Guido Trotter | val = None
|
4835 | 638c6349 | Guido Trotter | elif field == "nic_mode": |
4836 | 638c6349 | Guido Trotter | if instance.nics:
|
4837 | 638c6349 | Guido Trotter | val = i_nicp[0][constants.NIC_MODE]
|
4838 | 638c6349 | Guido Trotter | else:
|
4839 | 638c6349 | Guido Trotter | val = None
|
4840 | 638c6349 | Guido Trotter | elif field == "nic_link": |
4841 | 39a02558 | Guido Trotter | if instance.nics:
|
4842 | 638c6349 | Guido Trotter | val = i_nicp[0][constants.NIC_LINK]
|
4843 | 638c6349 | Guido Trotter | else:
|
4844 | 638c6349 | Guido Trotter | val = None
|
4845 | 638c6349 | Guido Trotter | elif field == "bridge": |
4846 | 638c6349 | Guido Trotter | if (instance.nics and |
4847 | 638c6349 | Guido Trotter | i_nicp[0][constants.NIC_MODE] == constants.NIC_MODE_BRIDGED):
|
4848 | 638c6349 | Guido Trotter | val = i_nicp[0][constants.NIC_LINK]
|
4849 | 39a02558 | Guido Trotter | else:
|
4850 | 39a02558 | Guido Trotter | val = None
|
4851 | a8083063 | Iustin Pop | elif field == "mac": |
4852 | 39a02558 | Guido Trotter | if instance.nics:
|
4853 | 39a02558 | Guido Trotter | val = instance.nics[0].mac
|
4854 | 39a02558 | Guido Trotter | else:
|
4855 | 39a02558 | Guido Trotter | val = None
|
4856 | 644eeef9 | Iustin Pop | elif field == "sda_size" or field == "sdb_size": |
4857 | ad24e046 | Iustin Pop | idx = ord(field[2]) - ord('a') |
4858 | ad24e046 | Iustin Pop | try:
|
4859 | ad24e046 | Iustin Pop | val = instance.FindDisk(idx).size |
4860 | ad24e046 | Iustin Pop | except errors.OpPrereqError:
|
4861 | 8a23d2d3 | Iustin Pop | val = None
|
4862 | 024e157f | Iustin Pop | elif field == "disk_usage": # total disk usage per node |
4863 | 024e157f | Iustin Pop | disk_sizes = [{'size': disk.size} for disk in instance.disks] |
4864 | 024e157f | Iustin Pop | val = _ComputeDiskSize(instance.disk_template, disk_sizes) |
4865 | 130a6a6f | Iustin Pop | elif field == "tags": |
4866 | 130a6a6f | Iustin Pop | val = list(instance.GetTags())
|
4867 | 338e51e8 | Iustin Pop | elif field == "hvparams": |
4868 | 338e51e8 | Iustin Pop | val = i_hv |
4869 | 5018a335 | Iustin Pop | elif (field.startswith(HVPREFIX) and |
4870 | 7736a5f2 | Iustin Pop | field[len(HVPREFIX):] in constants.HVS_PARAMETERS and |
4871 | 7736a5f2 | Iustin Pop | field[len(HVPREFIX):] not in constants.HVC_GLOBALS): |
4872 | 5018a335 | Iustin Pop | val = i_hv.get(field[len(HVPREFIX):], None) |
4873 | 338e51e8 | Iustin Pop | elif field == "beparams": |
4874 | 338e51e8 | Iustin Pop | val = i_be |
4875 | 338e51e8 | Iustin Pop | elif (field.startswith(BEPREFIX) and |
4876 | 338e51e8 | Iustin Pop | field[len(BEPREFIX):] in constants.BES_PARAMETERS): |
4877 | 338e51e8 | Iustin Pop | val = i_be.get(field[len(BEPREFIX):], None) |
4878 | 71c1af58 | Iustin Pop | elif st_match and st_match.groups(): |
4879 | 71c1af58 | Iustin Pop | # matches a variable list
|
4880 | 71c1af58 | Iustin Pop | st_groups = st_match.groups() |
4881 | 71c1af58 | Iustin Pop | if st_groups and st_groups[0] == "disk": |
4882 | 71c1af58 | Iustin Pop | if st_groups[1] == "count": |
4883 | 71c1af58 | Iustin Pop | val = len(instance.disks)
|
4884 | 41a776da | Iustin Pop | elif st_groups[1] == "sizes": |
4885 | 41a776da | Iustin Pop | val = [disk.size for disk in instance.disks] |
4886 | 71c1af58 | Iustin Pop | elif st_groups[1] == "size": |
4887 | 3e0cea06 | Iustin Pop | try:
|
4888 | 3e0cea06 | Iustin Pop | val = instance.FindDisk(st_groups[2]).size
|
4889 | 3e0cea06 | Iustin Pop | except errors.OpPrereqError:
|
4890 | 71c1af58 | Iustin Pop | val = None
|
4891 | 71c1af58 | Iustin Pop | else:
|
4892 | 71c1af58 | Iustin Pop | assert False, "Unhandled disk parameter" |
4893 | 71c1af58 | Iustin Pop | elif st_groups[0] == "nic": |
4894 | 71c1af58 | Iustin Pop | if st_groups[1] == "count": |
4895 | 71c1af58 | Iustin Pop | val = len(instance.nics)
|
4896 | 41a776da | Iustin Pop | elif st_groups[1] == "macs": |
4897 | 41a776da | Iustin Pop | val = [nic.mac for nic in instance.nics] |
4898 | 41a776da | Iustin Pop | elif st_groups[1] == "ips": |
4899 | 41a776da | Iustin Pop | val = [nic.ip for nic in instance.nics] |
4900 | 638c6349 | Guido Trotter | elif st_groups[1] == "modes": |
4901 | 638c6349 | Guido Trotter | val = [nicp[constants.NIC_MODE] for nicp in i_nicp] |
4902 | 638c6349 | Guido Trotter | elif st_groups[1] == "links": |
4903 | 638c6349 | Guido Trotter | val = [nicp[constants.NIC_LINK] for nicp in i_nicp] |
4904 | 41a776da | Iustin Pop | elif st_groups[1] == "bridges": |
4905 | 638c6349 | Guido Trotter | val = [] |
4906 | 638c6349 | Guido Trotter | for nicp in i_nicp: |
4907 | 638c6349 | Guido Trotter | if nicp[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
|
4908 | 638c6349 | Guido Trotter | val.append(nicp[constants.NIC_LINK]) |
4909 | 638c6349 | Guido Trotter | else:
|
4910 | 638c6349 | Guido Trotter | val.append(None)
|
4911 | 71c1af58 | Iustin Pop | else:
|
4912 | 71c1af58 | Iustin Pop | # index-based item
|
4913 | 71c1af58 | Iustin Pop | nic_idx = int(st_groups[2]) |
4914 | 71c1af58 | Iustin Pop | if nic_idx >= len(instance.nics): |
4915 | 71c1af58 | Iustin Pop | val = None
|
4916 | 71c1af58 | Iustin Pop | else:
|
4917 | 71c1af58 | Iustin Pop | if st_groups[1] == "mac": |
4918 | 71c1af58 | Iustin Pop | val = instance.nics[nic_idx].mac |
4919 | 71c1af58 | Iustin Pop | elif st_groups[1] == "ip": |
4920 | 71c1af58 | Iustin Pop | val = instance.nics[nic_idx].ip |
4921 | 638c6349 | Guido Trotter | elif st_groups[1] == "mode": |
4922 | 638c6349 | Guido Trotter | val = i_nicp[nic_idx][constants.NIC_MODE] |
4923 | 638c6349 | Guido Trotter | elif st_groups[1] == "link": |
4924 | 638c6349 | Guido Trotter | val = i_nicp[nic_idx][constants.NIC_LINK] |
4925 | 71c1af58 | Iustin Pop | elif st_groups[1] == "bridge": |
4926 | 638c6349 | Guido Trotter | nic_mode = i_nicp[nic_idx][constants.NIC_MODE] |
4927 | 638c6349 | Guido Trotter | if nic_mode == constants.NIC_MODE_BRIDGED:
|
4928 | 638c6349 | Guido Trotter | val = i_nicp[nic_idx][constants.NIC_LINK] |
4929 | 638c6349 | Guido Trotter | else:
|
4930 | 638c6349 | Guido Trotter | val = None
|
4931 | 71c1af58 | Iustin Pop | else:
|
4932 | 71c1af58 | Iustin Pop | assert False, "Unhandled NIC parameter" |
4933 | 71c1af58 | Iustin Pop | else:
|
4934 | c1ce76bb | Iustin Pop | assert False, ("Declared but unhandled variable parameter '%s'" % |
4935 | c1ce76bb | Iustin Pop | field) |
4936 | a8083063 | Iustin Pop | else:
|
4937 | c1ce76bb | Iustin Pop | assert False, "Declared but unhandled parameter '%s'" % field |
4938 | a8083063 | Iustin Pop | iout.append(val) |
4939 | a8083063 | Iustin Pop | output.append(iout) |
4940 | a8083063 | Iustin Pop | |
4941 | a8083063 | Iustin Pop | return output
|
4942 | a8083063 | Iustin Pop | |
4943 | a8083063 | Iustin Pop | |
4944 | a8083063 | Iustin Pop | class LUFailoverInstance(LogicalUnit): |
4945 | a8083063 | Iustin Pop | """Failover an instance.
|
4946 | a8083063 | Iustin Pop |
|
4947 | a8083063 | Iustin Pop | """
|
4948 | a8083063 | Iustin Pop | HPATH = "instance-failover"
|
4949 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
4950 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name", "ignore_consistency"] |
4951 | c9e5c064 | Guido Trotter | REQ_BGL = False
|
4952 | c9e5c064 | Guido Trotter | |
4953 | 17c3f802 | Guido Trotter | def CheckArguments(self): |
4954 | 17c3f802 | Guido Trotter | """Check the arguments.
|
4955 | 17c3f802 | Guido Trotter |
|
4956 | 17c3f802 | Guido Trotter | """
|
4957 | 17c3f802 | Guido Trotter | self.shutdown_timeout = getattr(self.op, "shutdown_timeout", |
4958 | 17c3f802 | Guido Trotter | constants.DEFAULT_SHUTDOWN_TIMEOUT) |
4959 | 17c3f802 | Guido Trotter | |
4960 | c9e5c064 | Guido Trotter | def ExpandNames(self): |
4961 | c9e5c064 | Guido Trotter | self._ExpandAndLockInstance()
|
4962 | c9e5c064 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
4963 | f6d9a522 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
4964 | c9e5c064 | Guido Trotter | |
4965 | c9e5c064 | Guido Trotter | def DeclareLocks(self, level): |
4966 | c9e5c064 | Guido Trotter | if level == locking.LEVEL_NODE:
|
4967 | c9e5c064 | Guido Trotter | self._LockInstancesNodes()
|
4968 | a8083063 | Iustin Pop | |
4969 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
4970 | a8083063 | Iustin Pop | """Build hooks env.
|
4971 | a8083063 | Iustin Pop |
|
4972 | a8083063 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
4973 | a8083063 | Iustin Pop |
|
4974 | a8083063 | Iustin Pop | """
|
4975 | 08eec276 | Iustin Pop | instance = self.instance
|
4976 | 08eec276 | Iustin Pop | source_node = instance.primary_node |
4977 | 08eec276 | Iustin Pop | target_node = instance.secondary_nodes[0]
|
4978 | a8083063 | Iustin Pop | env = { |
4979 | a8083063 | Iustin Pop | "IGNORE_CONSISTENCY": self.op.ignore_consistency, |
4980 | 17c3f802 | Guido Trotter | "SHUTDOWN_TIMEOUT": self.shutdown_timeout, |
4981 | 08eec276 | Iustin Pop | "OLD_PRIMARY": source_node,
|
4982 | 08eec276 | Iustin Pop | "OLD_SECONDARY": target_node,
|
4983 | 08eec276 | Iustin Pop | "NEW_PRIMARY": target_node,
|
4984 | 08eec276 | Iustin Pop | "NEW_SECONDARY": source_node,
|
4985 | a8083063 | Iustin Pop | } |
4986 | 08eec276 | Iustin Pop | env.update(_BuildInstanceHookEnvByObject(self, instance))
|
4987 | 08eec276 | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(instance.secondary_nodes) |
4988 | abd8e836 | Iustin Pop | nl_post = list(nl)
|
4989 | abd8e836 | Iustin Pop | nl_post.append(source_node) |
4990 | abd8e836 | Iustin Pop | return env, nl, nl_post
|
4991 | a8083063 | Iustin Pop | |
4992 | a8083063 | Iustin Pop | def CheckPrereq(self): |
4993 | a8083063 | Iustin Pop | """Check prerequisites.
|
4994 | a8083063 | Iustin Pop |
|
4995 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
4996 | a8083063 | Iustin Pop |
|
4997 | a8083063 | Iustin Pop | """
|
4998 | c9e5c064 | Guido Trotter | self.instance = instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
4999 | c9e5c064 | Guido Trotter | assert self.instance is not None, \ |
5000 | c9e5c064 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
5001 | a8083063 | Iustin Pop | |
5002 | 338e51e8 | Iustin Pop | bep = self.cfg.GetClusterInfo().FillBE(instance)
|
5003 | a1f445d3 | Iustin Pop | if instance.disk_template not in constants.DTS_NET_MIRROR: |
5004 | 2a710df1 | Michael Hanselmann | raise errors.OpPrereqError("Instance's disk layout is not" |
5005 | 5c983ee5 | Iustin Pop | " network mirrored, cannot failover.",
|
5006 | 5c983ee5 | Iustin Pop | errors.ECODE_STATE) |
5007 | 2a710df1 | Michael Hanselmann | |
5008 | 2a710df1 | Michael Hanselmann | secondary_nodes = instance.secondary_nodes |
5009 | 2a710df1 | Michael Hanselmann | if not secondary_nodes: |
5010 | 2a710df1 | Michael Hanselmann | raise errors.ProgrammerError("no secondary node but using " |
5011 | abdf0113 | Iustin Pop | "a mirrored disk template")
|
5012 | 2a710df1 | Michael Hanselmann | |
5013 | 2a710df1 | Michael Hanselmann | target_node = secondary_nodes[0]
|
5014 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, target_node)
|
5015 | 733a2b6a | Iustin Pop | _CheckNodeNotDrained(self, target_node)
|
5016 | d27776f0 | Iustin Pop | if instance.admin_up:
|
5017 | d27776f0 | Iustin Pop | # check memory requirements on the secondary node
|
5018 | d27776f0 | Iustin Pop | _CheckNodeFreeMemory(self, target_node, "failing over instance %s" % |
5019 | d27776f0 | Iustin Pop | instance.name, bep[constants.BE_MEMORY], |
5020 | d27776f0 | Iustin Pop | instance.hypervisor) |
5021 | d27776f0 | Iustin Pop | else:
|
5022 | d27776f0 | Iustin Pop | self.LogInfo("Not checking memory on the secondary node as" |
5023 | d27776f0 | Iustin Pop | " instance will not be started")
|
5024 | 3a7c308e | Guido Trotter | |
5025 | a8083063 | Iustin Pop | # check bridge existance
|
5026 | b165e77e | Guido Trotter | _CheckInstanceBridgesExist(self, instance, node=target_node)
|
5027 | a8083063 | Iustin Pop | |
5028 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
5029 | a8083063 | Iustin Pop | """Failover an instance.
|
5030 | a8083063 | Iustin Pop |
|
5031 | a8083063 | Iustin Pop | The failover is done by shutting it down on its present node and
|
5032 | a8083063 | Iustin Pop | starting it on the secondary.
|
5033 | a8083063 | Iustin Pop |
|
5034 | a8083063 | Iustin Pop | """
|
5035 | a8083063 | Iustin Pop | instance = self.instance
|
5036 | a8083063 | Iustin Pop | |
5037 | a8083063 | Iustin Pop | source_node = instance.primary_node |
5038 | a8083063 | Iustin Pop | target_node = instance.secondary_nodes[0]
|
5039 | a8083063 | Iustin Pop | |
5040 | 1df79ce6 | Michael Hanselmann | if instance.admin_up:
|
5041 | 1df79ce6 | Michael Hanselmann | feedback_fn("* checking disk consistency between source and target")
|
5042 | 1df79ce6 | Michael Hanselmann | for dev in instance.disks: |
5043 | 1df79ce6 | Michael Hanselmann | # for drbd, these are drbd over lvm
|
5044 | 1df79ce6 | Michael Hanselmann | if not _CheckDiskConsistency(self, dev, target_node, False): |
5045 | 1df79ce6 | Michael Hanselmann | if not self.op.ignore_consistency: |
5046 | 1df79ce6 | Michael Hanselmann | raise errors.OpExecError("Disk %s is degraded on target node," |
5047 | 1df79ce6 | Michael Hanselmann | " aborting failover." % dev.iv_name)
|
5048 | 1df79ce6 | Michael Hanselmann | else:
|
5049 | 1df79ce6 | Michael Hanselmann | feedback_fn("* not checking disk consistency as instance is not running")
|
5050 | a8083063 | Iustin Pop | |
5051 | a8083063 | Iustin Pop | feedback_fn("* shutting down instance on source node")
|
5052 | 9a4f63d1 | Iustin Pop | logging.info("Shutting down instance %s on node %s",
|
5053 | 9a4f63d1 | Iustin Pop | instance.name, source_node) |
5054 | a8083063 | Iustin Pop | |
5055 | 17c3f802 | Guido Trotter | result = self.rpc.call_instance_shutdown(source_node, instance,
|
5056 | 17c3f802 | Guido Trotter | self.shutdown_timeout)
|
5057 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
5058 | 1fae010f | Iustin Pop | if msg:
|
5059 | 24a40d57 | Iustin Pop | if self.op.ignore_consistency: |
5060 | 86d9d3bb | Iustin Pop | self.proc.LogWarning("Could not shutdown instance %s on node %s." |
5061 | 1fae010f | Iustin Pop | " Proceeding anyway. Please make sure node"
|
5062 | 1fae010f | Iustin Pop | " %s is down. Error details: %s",
|
5063 | 1fae010f | Iustin Pop | instance.name, source_node, source_node, msg) |
5064 | 24a40d57 | Iustin Pop | else:
|
5065 | 1fae010f | Iustin Pop | raise errors.OpExecError("Could not shutdown instance %s on" |
5066 | 1fae010f | Iustin Pop | " node %s: %s" %
|
5067 | 1fae010f | Iustin Pop | (instance.name, source_node, msg)) |
5068 | a8083063 | Iustin Pop | |
5069 | a8083063 | Iustin Pop | feedback_fn("* deactivating the instance's disks on source node")
|
5070 | b9bddb6b | Iustin Pop | if not _ShutdownInstanceDisks(self, instance, ignore_primary=True): |
5071 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Can't shut down the instance's disks.") |
5072 | a8083063 | Iustin Pop | |
5073 | a8083063 | Iustin Pop | instance.primary_node = target_node |
5074 | a8083063 | Iustin Pop | # distribute new instance config to the other nodes
|
5075 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, feedback_fn)
|
5076 | a8083063 | Iustin Pop | |
5077 | 12a0cfbe | Guido Trotter | # Only start the instance if it's marked as up
|
5078 | 0d68c45d | Iustin Pop | if instance.admin_up:
|
5079 | 12a0cfbe | Guido Trotter | feedback_fn("* activating the instance's disks on target node")
|
5080 | 9a4f63d1 | Iustin Pop | logging.info("Starting instance %s on node %s",
|
5081 | 9a4f63d1 | Iustin Pop | instance.name, target_node) |
5082 | 12a0cfbe | Guido Trotter | |
5083 | 7c4d6c7b | Michael Hanselmann | disks_ok, _ = _AssembleInstanceDisks(self, instance,
|
5084 | 12a0cfbe | Guido Trotter | ignore_secondaries=True)
|
5085 | 12a0cfbe | Guido Trotter | if not disks_ok: |
5086 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
5087 | 12a0cfbe | Guido Trotter | raise errors.OpExecError("Can't activate the instance's disks") |
5088 | a8083063 | Iustin Pop | |
5089 | 12a0cfbe | Guido Trotter | feedback_fn("* starting the instance on the target node")
|
5090 | 0eca8e0c | Iustin Pop | result = self.rpc.call_instance_start(target_node, instance, None, None) |
5091 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
5092 | dd279568 | Iustin Pop | if msg:
|
5093 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
5094 | dd279568 | Iustin Pop | raise errors.OpExecError("Could not start instance %s on node %s: %s" % |
5095 | dd279568 | Iustin Pop | (instance.name, target_node, msg)) |
5096 | a8083063 | Iustin Pop | |
5097 | a8083063 | Iustin Pop | |
5098 | 53c776b5 | Iustin Pop | class LUMigrateInstance(LogicalUnit): |
5099 | 53c776b5 | Iustin Pop | """Migrate an instance.
|
5100 | 53c776b5 | Iustin Pop |
|
5101 | 53c776b5 | Iustin Pop | This is migration without shutting down, compared to the failover,
|
5102 | 53c776b5 | Iustin Pop | which is done with shutdown.
|
5103 | 53c776b5 | Iustin Pop |
|
5104 | 53c776b5 | Iustin Pop | """
|
5105 | 53c776b5 | Iustin Pop | HPATH = "instance-migrate"
|
5106 | 53c776b5 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
5107 | 53c776b5 | Iustin Pop | _OP_REQP = ["instance_name", "live", "cleanup"] |
5108 | 53c776b5 | Iustin Pop | |
5109 | 53c776b5 | Iustin Pop | REQ_BGL = False
|
5110 | 53c776b5 | Iustin Pop | |
5111 | 53c776b5 | Iustin Pop | def ExpandNames(self): |
5112 | 53c776b5 | Iustin Pop | self._ExpandAndLockInstance()
|
5113 | 3e06e001 | Michael Hanselmann | |
5114 | 53c776b5 | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = []
|
5115 | 53c776b5 | Iustin Pop | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
5116 | 53c776b5 | Iustin Pop | |
5117 | 3e06e001 | Michael Hanselmann | self._migrater = TLMigrateInstance(self, self.op.instance_name, |
5118 | 3e06e001 | Michael Hanselmann | self.op.live, self.op.cleanup) |
5119 | 3a012b41 | Michael Hanselmann | self.tasklets = [self._migrater] |
5120 | 3e06e001 | Michael Hanselmann | |
5121 | 53c776b5 | Iustin Pop | def DeclareLocks(self, level): |
5122 | 53c776b5 | Iustin Pop | if level == locking.LEVEL_NODE:
|
5123 | 53c776b5 | Iustin Pop | self._LockInstancesNodes()
|
5124 | 53c776b5 | Iustin Pop | |
5125 | 53c776b5 | Iustin Pop | def BuildHooksEnv(self): |
5126 | 53c776b5 | Iustin Pop | """Build hooks env.
|
5127 | 53c776b5 | Iustin Pop |
|
5128 | 53c776b5 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
5129 | 53c776b5 | Iustin Pop |
|
5130 | 53c776b5 | Iustin Pop | """
|
5131 | 3e06e001 | Michael Hanselmann | instance = self._migrater.instance
|
5132 | 08eec276 | Iustin Pop | source_node = instance.primary_node |
5133 | 08eec276 | Iustin Pop | target_node = instance.secondary_nodes[0]
|
5134 | 3e06e001 | Michael Hanselmann | env = _BuildInstanceHookEnvByObject(self, instance)
|
5135 | 2c2690c9 | Iustin Pop | env["MIGRATE_LIVE"] = self.op.live |
5136 | 2c2690c9 | Iustin Pop | env["MIGRATE_CLEANUP"] = self.op.cleanup |
5137 | 08eec276 | Iustin Pop | env.update({ |
5138 | 08eec276 | Iustin Pop | "OLD_PRIMARY": source_node,
|
5139 | 08eec276 | Iustin Pop | "OLD_SECONDARY": target_node,
|
5140 | 08eec276 | Iustin Pop | "NEW_PRIMARY": target_node,
|
5141 | 08eec276 | Iustin Pop | "NEW_SECONDARY": source_node,
|
5142 | 08eec276 | Iustin Pop | }) |
5143 | 3e06e001 | Michael Hanselmann | nl = [self.cfg.GetMasterNode()] + list(instance.secondary_nodes) |
5144 | abd8e836 | Iustin Pop | nl_post = list(nl)
|
5145 | abd8e836 | Iustin Pop | nl_post.append(source_node) |
5146 | abd8e836 | Iustin Pop | return env, nl, nl_post
|
5147 | 53c776b5 | Iustin Pop | |
5148 | 3e06e001 | Michael Hanselmann | |
5149 | 313bcead | Iustin Pop | class LUMoveInstance(LogicalUnit): |
5150 | 313bcead | Iustin Pop | """Move an instance by data-copying.
|
5151 | 313bcead | Iustin Pop |
|
5152 | 313bcead | Iustin Pop | """
|
5153 | 313bcead | Iustin Pop | HPATH = "instance-move"
|
5154 | 313bcead | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
5155 | 313bcead | Iustin Pop | _OP_REQP = ["instance_name", "target_node"] |
5156 | 313bcead | Iustin Pop | REQ_BGL = False
|
5157 | 313bcead | Iustin Pop | |
5158 | 17c3f802 | Guido Trotter | def CheckArguments(self): |
5159 | 17c3f802 | Guido Trotter | """Check the arguments.
|
5160 | 17c3f802 | Guido Trotter |
|
5161 | 17c3f802 | Guido Trotter | """
|
5162 | 17c3f802 | Guido Trotter | self.shutdown_timeout = getattr(self.op, "shutdown_timeout", |
5163 | 17c3f802 | Guido Trotter | constants.DEFAULT_SHUTDOWN_TIMEOUT) |
5164 | 17c3f802 | Guido Trotter | |
5165 | 313bcead | Iustin Pop | def ExpandNames(self): |
5166 | 313bcead | Iustin Pop | self._ExpandAndLockInstance()
|
5167 | cf26a87a | Iustin Pop | target_node = _ExpandNodeName(self.cfg, self.op.target_node) |
5168 | 313bcead | Iustin Pop | self.op.target_node = target_node
|
5169 | 313bcead | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = [target_node]
|
5170 | 313bcead | Iustin Pop | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_APPEND
|
5171 | 313bcead | Iustin Pop | |
5172 | 313bcead | Iustin Pop | def DeclareLocks(self, level): |
5173 | 313bcead | Iustin Pop | if level == locking.LEVEL_NODE:
|
5174 | 313bcead | Iustin Pop | self._LockInstancesNodes(primary_only=True) |
5175 | 313bcead | Iustin Pop | |
5176 | 313bcead | Iustin Pop | def BuildHooksEnv(self): |
5177 | 313bcead | Iustin Pop | """Build hooks env.
|
5178 | 313bcead | Iustin Pop |
|
5179 | 313bcead | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
5180 | 313bcead | Iustin Pop |
|
5181 | 313bcead | Iustin Pop | """
|
5182 | 313bcead | Iustin Pop | env = { |
5183 | 313bcead | Iustin Pop | "TARGET_NODE": self.op.target_node, |
5184 | 17c3f802 | Guido Trotter | "SHUTDOWN_TIMEOUT": self.shutdown_timeout, |
5185 | 313bcead | Iustin Pop | } |
5186 | 313bcead | Iustin Pop | env.update(_BuildInstanceHookEnvByObject(self, self.instance)) |
5187 | 313bcead | Iustin Pop | nl = [self.cfg.GetMasterNode()] + [self.instance.primary_node, |
5188 | 313bcead | Iustin Pop | self.op.target_node]
|
5189 | 313bcead | Iustin Pop | return env, nl, nl
|
5190 | 313bcead | Iustin Pop | |
5191 | 313bcead | Iustin Pop | def CheckPrereq(self): |
5192 | 313bcead | Iustin Pop | """Check prerequisites.
|
5193 | 313bcead | Iustin Pop |
|
5194 | 313bcead | Iustin Pop | This checks that the instance is in the cluster.
|
5195 | 313bcead | Iustin Pop |
|
5196 | 313bcead | Iustin Pop | """
|
5197 | 313bcead | Iustin Pop | self.instance = instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
5198 | 313bcead | Iustin Pop | assert self.instance is not None, \ |
5199 | 313bcead | Iustin Pop | "Cannot retrieve locked instance %s" % self.op.instance_name |
5200 | 313bcead | Iustin Pop | |
5201 | 313bcead | Iustin Pop | node = self.cfg.GetNodeInfo(self.op.target_node) |
5202 | 313bcead | Iustin Pop | assert node is not None, \ |
5203 | 313bcead | Iustin Pop | "Cannot retrieve locked node %s" % self.op.target_node |
5204 | 313bcead | Iustin Pop | |
5205 | 313bcead | Iustin Pop | self.target_node = target_node = node.name
|
5206 | 313bcead | Iustin Pop | |
5207 | 313bcead | Iustin Pop | if target_node == instance.primary_node:
|
5208 | 313bcead | Iustin Pop | raise errors.OpPrereqError("Instance %s is already on the node %s" % |
5209 | 5c983ee5 | Iustin Pop | (instance.name, target_node), |
5210 | 5c983ee5 | Iustin Pop | errors.ECODE_STATE) |
5211 | 313bcead | Iustin Pop | |
5212 | 313bcead | Iustin Pop | bep = self.cfg.GetClusterInfo().FillBE(instance)
|
5213 | 313bcead | Iustin Pop | |
5214 | 313bcead | Iustin Pop | for idx, dsk in enumerate(instance.disks): |
5215 | 313bcead | Iustin Pop | if dsk.dev_type not in (constants.LD_LV, constants.LD_FILE): |
5216 | 313bcead | Iustin Pop | raise errors.OpPrereqError("Instance disk %d has a complex layout," |
5217 | d1b83918 | Iustin Pop | " cannot copy" % idx, errors.ECODE_STATE)
|
5218 | 313bcead | Iustin Pop | |
5219 | 313bcead | Iustin Pop | _CheckNodeOnline(self, target_node)
|
5220 | 313bcead | Iustin Pop | _CheckNodeNotDrained(self, target_node)
|
5221 | 313bcead | Iustin Pop | |
5222 | 313bcead | Iustin Pop | if instance.admin_up:
|
5223 | 313bcead | Iustin Pop | # check memory requirements on the secondary node
|
5224 | 313bcead | Iustin Pop | _CheckNodeFreeMemory(self, target_node, "failing over instance %s" % |
5225 | 313bcead | Iustin Pop | instance.name, bep[constants.BE_MEMORY], |
5226 | 313bcead | Iustin Pop | instance.hypervisor) |
5227 | 313bcead | Iustin Pop | else:
|
5228 | 313bcead | Iustin Pop | self.LogInfo("Not checking memory on the secondary node as" |
5229 | 313bcead | Iustin Pop | " instance will not be started")
|
5230 | 313bcead | Iustin Pop | |
5231 | 313bcead | Iustin Pop | # check bridge existance
|
5232 | 313bcead | Iustin Pop | _CheckInstanceBridgesExist(self, instance, node=target_node)
|
5233 | 313bcead | Iustin Pop | |
5234 | 313bcead | Iustin Pop | def Exec(self, feedback_fn): |
5235 | 313bcead | Iustin Pop | """Move an instance.
|
5236 | 313bcead | Iustin Pop |
|
5237 | 313bcead | Iustin Pop | The move is done by shutting it down on its present node, copying
|
5238 | 313bcead | Iustin Pop | the data over (slow) and starting it on the new node.
|
5239 | 313bcead | Iustin Pop |
|
5240 | 313bcead | Iustin Pop | """
|
5241 | 313bcead | Iustin Pop | instance = self.instance
|
5242 | 313bcead | Iustin Pop | |
5243 | 313bcead | Iustin Pop | source_node = instance.primary_node |
5244 | 313bcead | Iustin Pop | target_node = self.target_node
|
5245 | 313bcead | Iustin Pop | |
5246 | 313bcead | Iustin Pop | self.LogInfo("Shutting down instance %s on source node %s", |
5247 | 313bcead | Iustin Pop | instance.name, source_node) |
5248 | 313bcead | Iustin Pop | |
5249 | 17c3f802 | Guido Trotter | result = self.rpc.call_instance_shutdown(source_node, instance,
|
5250 | 17c3f802 | Guido Trotter | self.shutdown_timeout)
|
5251 | 313bcead | Iustin Pop | msg = result.fail_msg |
5252 | 313bcead | Iustin Pop | if msg:
|
5253 | 313bcead | Iustin Pop | if self.op.ignore_consistency: |
5254 | 313bcead | Iustin Pop | self.proc.LogWarning("Could not shutdown instance %s on node %s." |
5255 | 313bcead | Iustin Pop | " Proceeding anyway. Please make sure node"
|
5256 | 313bcead | Iustin Pop | " %s is down. Error details: %s",
|
5257 | 313bcead | Iustin Pop | instance.name, source_node, source_node, msg) |
5258 | 313bcead | Iustin Pop | else:
|
5259 | 313bcead | Iustin Pop | raise errors.OpExecError("Could not shutdown instance %s on" |
5260 | 313bcead | Iustin Pop | " node %s: %s" %
|
5261 | 313bcead | Iustin Pop | (instance.name, source_node, msg)) |
5262 | 313bcead | Iustin Pop | |
5263 | 313bcead | Iustin Pop | # create the target disks
|
5264 | 313bcead | Iustin Pop | try:
|
5265 | 313bcead | Iustin Pop | _CreateDisks(self, instance, target_node=target_node)
|
5266 | 313bcead | Iustin Pop | except errors.OpExecError:
|
5267 | 313bcead | Iustin Pop | self.LogWarning("Device creation failed, reverting...") |
5268 | 313bcead | Iustin Pop | try:
|
5269 | 313bcead | Iustin Pop | _RemoveDisks(self, instance, target_node=target_node)
|
5270 | 313bcead | Iustin Pop | finally:
|
5271 | 313bcead | Iustin Pop | self.cfg.ReleaseDRBDMinors(instance.name)
|
5272 | 313bcead | Iustin Pop | raise
|
5273 | 313bcead | Iustin Pop | |
5274 | 313bcead | Iustin Pop | cluster_name = self.cfg.GetClusterInfo().cluster_name
|
5275 | 313bcead | Iustin Pop | |
5276 | 313bcead | Iustin Pop | errs = [] |
5277 | 313bcead | Iustin Pop | # activate, get path, copy the data over
|
5278 | 313bcead | Iustin Pop | for idx, disk in enumerate(instance.disks): |
5279 | 313bcead | Iustin Pop | self.LogInfo("Copying data for disk %d", idx) |
5280 | 313bcead | Iustin Pop | result = self.rpc.call_blockdev_assemble(target_node, disk,
|
5281 | 313bcead | Iustin Pop | instance.name, True)
|
5282 | 313bcead | Iustin Pop | if result.fail_msg:
|
5283 | 313bcead | Iustin Pop | self.LogWarning("Can't assemble newly created disk %d: %s", |
5284 | 313bcead | Iustin Pop | idx, result.fail_msg) |
5285 | 313bcead | Iustin Pop | errs.append(result.fail_msg) |
5286 | 313bcead | Iustin Pop | break
|
5287 | 313bcead | Iustin Pop | dev_path = result.payload |
5288 | 313bcead | Iustin Pop | result = self.rpc.call_blockdev_export(source_node, disk,
|
5289 | 313bcead | Iustin Pop | target_node, dev_path, |
5290 | 313bcead | Iustin Pop | cluster_name) |
5291 | 313bcead | Iustin Pop | if result.fail_msg:
|
5292 | 313bcead | Iustin Pop | self.LogWarning("Can't copy data over for disk %d: %s", |
5293 | 313bcead | Iustin Pop | idx, result.fail_msg) |
5294 | 313bcead | Iustin Pop | errs.append(result.fail_msg) |
5295 | 313bcead | Iustin Pop | break
|
5296 | 313bcead | Iustin Pop | |
5297 | 313bcead | Iustin Pop | if errs:
|
5298 | 313bcead | Iustin Pop | self.LogWarning("Some disks failed to copy, aborting") |
5299 | 313bcead | Iustin Pop | try:
|
5300 | 313bcead | Iustin Pop | _RemoveDisks(self, instance, target_node=target_node)
|
5301 | 313bcead | Iustin Pop | finally:
|
5302 | 313bcead | Iustin Pop | self.cfg.ReleaseDRBDMinors(instance.name)
|
5303 | 313bcead | Iustin Pop | raise errors.OpExecError("Errors during disk copy: %s" % |
5304 | 313bcead | Iustin Pop | (",".join(errs),))
|
5305 | 313bcead | Iustin Pop | |
5306 | 313bcead | Iustin Pop | instance.primary_node = target_node |
5307 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, feedback_fn)
|
5308 | 313bcead | Iustin Pop | |
5309 | 313bcead | Iustin Pop | self.LogInfo("Removing the disks on the original node") |
5310 | 313bcead | Iustin Pop | _RemoveDisks(self, instance, target_node=source_node)
|
5311 | 313bcead | Iustin Pop | |
5312 | 313bcead | Iustin Pop | # Only start the instance if it's marked as up
|
5313 | 313bcead | Iustin Pop | if instance.admin_up:
|
5314 | 313bcead | Iustin Pop | self.LogInfo("Starting instance %s on node %s", |
5315 | 313bcead | Iustin Pop | instance.name, target_node) |
5316 | 313bcead | Iustin Pop | |
5317 | 313bcead | Iustin Pop | disks_ok, _ = _AssembleInstanceDisks(self, instance,
|
5318 | 313bcead | Iustin Pop | ignore_secondaries=True)
|
5319 | 313bcead | Iustin Pop | if not disks_ok: |
5320 | 313bcead | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
5321 | 313bcead | Iustin Pop | raise errors.OpExecError("Can't activate the instance's disks") |
5322 | 313bcead | Iustin Pop | |
5323 | 313bcead | Iustin Pop | result = self.rpc.call_instance_start(target_node, instance, None, None) |
5324 | 313bcead | Iustin Pop | msg = result.fail_msg |
5325 | 313bcead | Iustin Pop | if msg:
|
5326 | 313bcead | Iustin Pop | _ShutdownInstanceDisks(self, instance)
|
5327 | 313bcead | Iustin Pop | raise errors.OpExecError("Could not start instance %s on node %s: %s" % |
5328 | 313bcead | Iustin Pop | (instance.name, target_node, msg)) |
5329 | 313bcead | Iustin Pop | |
5330 | 313bcead | Iustin Pop | |
5331 | 80cb875c | Michael Hanselmann | class LUMigrateNode(LogicalUnit): |
5332 | 80cb875c | Michael Hanselmann | """Migrate all instances from a node.
|
5333 | 80cb875c | Michael Hanselmann |
|
5334 | 80cb875c | Michael Hanselmann | """
|
5335 | 80cb875c | Michael Hanselmann | HPATH = "node-migrate"
|
5336 | 80cb875c | Michael Hanselmann | HTYPE = constants.HTYPE_NODE |
5337 | 80cb875c | Michael Hanselmann | _OP_REQP = ["node_name", "live"] |
5338 | 80cb875c | Michael Hanselmann | REQ_BGL = False
|
5339 | 80cb875c | Michael Hanselmann | |
5340 | 80cb875c | Michael Hanselmann | def ExpandNames(self): |
5341 | cf26a87a | Iustin Pop | self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name) |
5342 | 80cb875c | Michael Hanselmann | |
5343 | 80cb875c | Michael Hanselmann | self.needed_locks = {
|
5344 | 80cb875c | Michael Hanselmann | locking.LEVEL_NODE: [self.op.node_name],
|
5345 | 80cb875c | Michael Hanselmann | } |
5346 | 80cb875c | Michael Hanselmann | |
5347 | 80cb875c | Michael Hanselmann | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_APPEND
|
5348 | 80cb875c | Michael Hanselmann | |
5349 | 80cb875c | Michael Hanselmann | # Create tasklets for migrating instances for all instances on this node
|
5350 | 80cb875c | Michael Hanselmann | names = [] |
5351 | 80cb875c | Michael Hanselmann | tasklets = [] |
5352 | 80cb875c | Michael Hanselmann | |
5353 | 80cb875c | Michael Hanselmann | for inst in _GetNodePrimaryInstances(self.cfg, self.op.node_name): |
5354 | 80cb875c | Michael Hanselmann | logging.debug("Migrating instance %s", inst.name)
|
5355 | 80cb875c | Michael Hanselmann | names.append(inst.name) |
5356 | 80cb875c | Michael Hanselmann | |
5357 | 80cb875c | Michael Hanselmann | tasklets.append(TLMigrateInstance(self, inst.name, self.op.live, False)) |
5358 | 80cb875c | Michael Hanselmann | |
5359 | 80cb875c | Michael Hanselmann | self.tasklets = tasklets
|
5360 | 80cb875c | Michael Hanselmann | |
5361 | 80cb875c | Michael Hanselmann | # Declare instance locks
|
5362 | 80cb875c | Michael Hanselmann | self.needed_locks[locking.LEVEL_INSTANCE] = names
|
5363 | 80cb875c | Michael Hanselmann | |
5364 | 80cb875c | Michael Hanselmann | def DeclareLocks(self, level): |
5365 | 80cb875c | Michael Hanselmann | if level == locking.LEVEL_NODE:
|
5366 | 80cb875c | Michael Hanselmann | self._LockInstancesNodes()
|
5367 | 80cb875c | Michael Hanselmann | |
5368 | 80cb875c | Michael Hanselmann | def BuildHooksEnv(self): |
5369 | 80cb875c | Michael Hanselmann | """Build hooks env.
|
5370 | 80cb875c | Michael Hanselmann |
|
5371 | 80cb875c | Michael Hanselmann | This runs on the master, the primary and all the secondaries.
|
5372 | 80cb875c | Michael Hanselmann |
|
5373 | 80cb875c | Michael Hanselmann | """
|
5374 | 80cb875c | Michael Hanselmann | env = { |
5375 | 80cb875c | Michael Hanselmann | "NODE_NAME": self.op.node_name, |
5376 | 80cb875c | Michael Hanselmann | } |
5377 | 80cb875c | Michael Hanselmann | |
5378 | 80cb875c | Michael Hanselmann | nl = [self.cfg.GetMasterNode()]
|
5379 | 80cb875c | Michael Hanselmann | |
5380 | 80cb875c | Michael Hanselmann | return (env, nl, nl)
|
5381 | 80cb875c | Michael Hanselmann | |
5382 | 80cb875c | Michael Hanselmann | |
5383 | 3e06e001 | Michael Hanselmann | class TLMigrateInstance(Tasklet): |
5384 | 3e06e001 | Michael Hanselmann | def __init__(self, lu, instance_name, live, cleanup): |
5385 | 3e06e001 | Michael Hanselmann | """Initializes this class.
|
5386 | 3e06e001 | Michael Hanselmann |
|
5387 | 3e06e001 | Michael Hanselmann | """
|
5388 | 464243a7 | Michael Hanselmann | Tasklet.__init__(self, lu)
|
5389 | 464243a7 | Michael Hanselmann | |
5390 | 3e06e001 | Michael Hanselmann | # Parameters
|
5391 | 3e06e001 | Michael Hanselmann | self.instance_name = instance_name
|
5392 | 3e06e001 | Michael Hanselmann | self.live = live
|
5393 | 3e06e001 | Michael Hanselmann | self.cleanup = cleanup
|
5394 | 3e06e001 | Michael Hanselmann | |
5395 | 53c776b5 | Iustin Pop | def CheckPrereq(self): |
5396 | 53c776b5 | Iustin Pop | """Check prerequisites.
|
5397 | 53c776b5 | Iustin Pop |
|
5398 | 53c776b5 | Iustin Pop | This checks that the instance is in the cluster.
|
5399 | 53c776b5 | Iustin Pop |
|
5400 | 53c776b5 | Iustin Pop | """
|
5401 | cf26a87a | Iustin Pop | instance_name = _ExpandInstanceName(self.lu.cfg, self.instance_name) |
5402 | cf26a87a | Iustin Pop | instance = self.cfg.GetInstanceInfo(instance_name)
|
5403 | cf26a87a | Iustin Pop | assert instance is not None |
5404 | 53c776b5 | Iustin Pop | |
5405 | 53c776b5 | Iustin Pop | if instance.disk_template != constants.DT_DRBD8:
|
5406 | 53c776b5 | Iustin Pop | raise errors.OpPrereqError("Instance's disk layout is not" |
5407 | 5c983ee5 | Iustin Pop | " drbd8, cannot migrate.", errors.ECODE_STATE)
|
5408 | 53c776b5 | Iustin Pop | |
5409 | 53c776b5 | Iustin Pop | secondary_nodes = instance.secondary_nodes |
5410 | 53c776b5 | Iustin Pop | if not secondary_nodes: |
5411 | 733a2b6a | Iustin Pop | raise errors.ConfigurationError("No secondary node but using" |
5412 | 733a2b6a | Iustin Pop | " drbd8 disk template")
|
5413 | 53c776b5 | Iustin Pop | |
5414 | 53c776b5 | Iustin Pop | i_be = self.cfg.GetClusterInfo().FillBE(instance)
|
5415 | 53c776b5 | Iustin Pop | |
5416 | 53c776b5 | Iustin Pop | target_node = secondary_nodes[0]
|
5417 | 53c776b5 | Iustin Pop | # check memory requirements on the secondary node
|
5418 | 53c776b5 | Iustin Pop | _CheckNodeFreeMemory(self, target_node, "migrating instance %s" % |
5419 | 53c776b5 | Iustin Pop | instance.name, i_be[constants.BE_MEMORY], |
5420 | 53c776b5 | Iustin Pop | instance.hypervisor) |
5421 | 53c776b5 | Iustin Pop | |
5422 | 53c776b5 | Iustin Pop | # check bridge existance
|
5423 | b165e77e | Guido Trotter | _CheckInstanceBridgesExist(self, instance, node=target_node)
|
5424 | 53c776b5 | Iustin Pop | |
5425 | 3e06e001 | Michael Hanselmann | if not self.cleanup: |
5426 | 733a2b6a | Iustin Pop | _CheckNodeNotDrained(self, target_node)
|
5427 | 53c776b5 | Iustin Pop | result = self.rpc.call_instance_migratable(instance.primary_node,
|
5428 | 53c776b5 | Iustin Pop | instance) |
5429 | 045dd6d9 | Iustin Pop | result.Raise("Can't migrate, please use failover",
|
5430 | 045dd6d9 | Iustin Pop | prereq=True, ecode=errors.ECODE_STATE)
|
5431 | 53c776b5 | Iustin Pop | |
5432 | 53c776b5 | Iustin Pop | self.instance = instance
|
5433 | 53c776b5 | Iustin Pop | |
5434 | 53c776b5 | Iustin Pop | def _WaitUntilSync(self): |
5435 | 53c776b5 | Iustin Pop | """Poll with custom rpc for disk sync.
|
5436 | 53c776b5 | Iustin Pop |
|
5437 | 53c776b5 | Iustin Pop | This uses our own step-based rpc call.
|
5438 | 53c776b5 | Iustin Pop |
|
5439 | 53c776b5 | Iustin Pop | """
|
5440 | 53c776b5 | Iustin Pop | self.feedback_fn("* wait until resync is done") |
5441 | 53c776b5 | Iustin Pop | all_done = False
|
5442 | 53c776b5 | Iustin Pop | while not all_done: |
5443 | 53c776b5 | Iustin Pop | all_done = True
|
5444 | 53c776b5 | Iustin Pop | result = self.rpc.call_drbd_wait_sync(self.all_nodes, |
5445 | 53c776b5 | Iustin Pop | self.nodes_ip,
|
5446 | 53c776b5 | Iustin Pop | self.instance.disks)
|
5447 | 53c776b5 | Iustin Pop | min_percent = 100
|
5448 | 53c776b5 | Iustin Pop | for node, nres in result.items(): |
5449 | 4c4e4e1e | Iustin Pop | nres.Raise("Cannot resync disks on node %s" % node)
|
5450 | 0959c824 | Iustin Pop | node_done, node_percent = nres.payload |
5451 | 53c776b5 | Iustin Pop | all_done = all_done and node_done
|
5452 | 53c776b5 | Iustin Pop | if node_percent is not None: |
5453 | 53c776b5 | Iustin Pop | min_percent = min(min_percent, node_percent)
|
5454 | 53c776b5 | Iustin Pop | if not all_done: |
5455 | 53c776b5 | Iustin Pop | if min_percent < 100: |
5456 | 53c776b5 | Iustin Pop | self.feedback_fn(" - progress: %.1f%%" % min_percent) |
5457 | 53c776b5 | Iustin Pop | time.sleep(2)
|
5458 | 53c776b5 | Iustin Pop | |
5459 | 53c776b5 | Iustin Pop | def _EnsureSecondary(self, node): |
5460 | 53c776b5 | Iustin Pop | """Demote a node to secondary.
|
5461 | 53c776b5 | Iustin Pop |
|
5462 | 53c776b5 | Iustin Pop | """
|
5463 | 53c776b5 | Iustin Pop | self.feedback_fn("* switching node %s to secondary mode" % node) |
5464 | 53c776b5 | Iustin Pop | |
5465 | 53c776b5 | Iustin Pop | for dev in self.instance.disks: |
5466 | 53c776b5 | Iustin Pop | self.cfg.SetDiskID(dev, node)
|
5467 | 53c776b5 | Iustin Pop | |
5468 | 53c776b5 | Iustin Pop | result = self.rpc.call_blockdev_close(node, self.instance.name, |
5469 | 53c776b5 | Iustin Pop | self.instance.disks)
|
5470 | 4c4e4e1e | Iustin Pop | result.Raise("Cannot change disk to secondary on node %s" % node)
|
5471 | 53c776b5 | Iustin Pop | |
5472 | 53c776b5 | Iustin Pop | def _GoStandalone(self): |
5473 | 53c776b5 | Iustin Pop | """Disconnect from the network.
|
5474 | 53c776b5 | Iustin Pop |
|
5475 | 53c776b5 | Iustin Pop | """
|
5476 | 53c776b5 | Iustin Pop | self.feedback_fn("* changing into standalone mode") |
5477 | 53c776b5 | Iustin Pop | result = self.rpc.call_drbd_disconnect_net(self.all_nodes, self.nodes_ip, |
5478 | 53c776b5 | Iustin Pop | self.instance.disks)
|
5479 | 53c776b5 | Iustin Pop | for node, nres in result.items(): |
5480 | 4c4e4e1e | Iustin Pop | nres.Raise("Cannot disconnect disks node %s" % node)
|
5481 | 53c776b5 | Iustin Pop | |
5482 | 53c776b5 | Iustin Pop | def _GoReconnect(self, multimaster): |
5483 | 53c776b5 | Iustin Pop | """Reconnect to the network.
|
5484 | 53c776b5 | Iustin Pop |
|
5485 | 53c776b5 | Iustin Pop | """
|
5486 | 53c776b5 | Iustin Pop | if multimaster:
|
5487 | 53c776b5 | Iustin Pop | msg = "dual-master"
|
5488 | 53c776b5 | Iustin Pop | else:
|
5489 | 53c776b5 | Iustin Pop | msg = "single-master"
|
5490 | 53c776b5 | Iustin Pop | self.feedback_fn("* changing disks into %s mode" % msg) |
5491 | 53c776b5 | Iustin Pop | result = self.rpc.call_drbd_attach_net(self.all_nodes, self.nodes_ip, |
5492 | 53c776b5 | Iustin Pop | self.instance.disks,
|
5493 | 53c776b5 | Iustin Pop | self.instance.name, multimaster)
|
5494 | 53c776b5 | Iustin Pop | for node, nres in result.items(): |
5495 | 4c4e4e1e | Iustin Pop | nres.Raise("Cannot change disks config on node %s" % node)
|
5496 | 53c776b5 | Iustin Pop | |
5497 | 53c776b5 | Iustin Pop | def _ExecCleanup(self): |
5498 | 53c776b5 | Iustin Pop | """Try to cleanup after a failed migration.
|
5499 | 53c776b5 | Iustin Pop |
|
5500 | 53c776b5 | Iustin Pop | The cleanup is done by:
|
5501 | 53c776b5 | Iustin Pop | - check that the instance is running only on one node
|
5502 | 53c776b5 | Iustin Pop | (and update the config if needed)
|
5503 | 53c776b5 | Iustin Pop | - change disks on its secondary node to secondary
|
5504 | 53c776b5 | Iustin Pop | - wait until disks are fully synchronized
|
5505 | 53c776b5 | Iustin Pop | - disconnect from the network
|
5506 | 53c776b5 | Iustin Pop | - change disks into single-master mode
|
5507 | 53c776b5 | Iustin Pop | - wait again until disks are fully synchronized
|
5508 | 53c776b5 | Iustin Pop |
|
5509 | 53c776b5 | Iustin Pop | """
|
5510 | 53c776b5 | Iustin Pop | instance = self.instance
|
5511 | 53c776b5 | Iustin Pop | target_node = self.target_node
|
5512 | 53c776b5 | Iustin Pop | source_node = self.source_node
|
5513 | 53c776b5 | Iustin Pop | |
5514 | 53c776b5 | Iustin Pop | # check running on only one node
|
5515 | 53c776b5 | Iustin Pop | self.feedback_fn("* checking where the instance actually runs" |
5516 | 53c776b5 | Iustin Pop | " (if this hangs, the hypervisor might be in"
|
5517 | 53c776b5 | Iustin Pop | " a bad state)")
|
5518 | 53c776b5 | Iustin Pop | ins_l = self.rpc.call_instance_list(self.all_nodes, [instance.hypervisor]) |
5519 | 53c776b5 | Iustin Pop | for node, result in ins_l.items(): |
5520 | 4c4e4e1e | Iustin Pop | result.Raise("Can't contact node %s" % node)
|
5521 | 53c776b5 | Iustin Pop | |
5522 | aca13712 | Iustin Pop | runningon_source = instance.name in ins_l[source_node].payload
|
5523 | aca13712 | Iustin Pop | runningon_target = instance.name in ins_l[target_node].payload
|
5524 | 53c776b5 | Iustin Pop | |
5525 | 53c776b5 | Iustin Pop | if runningon_source and runningon_target: |
5526 | 53c776b5 | Iustin Pop | raise errors.OpExecError("Instance seems to be running on two nodes," |
5527 | 53c776b5 | Iustin Pop | " or the hypervisor is confused. You will have"
|
5528 | 53c776b5 | Iustin Pop | " to ensure manually that it runs only on one"
|
5529 | 53c776b5 | Iustin Pop | " and restart this operation.")
|
5530 | 53c776b5 | Iustin Pop | |
5531 | 53c776b5 | Iustin Pop | if not (runningon_source or runningon_target): |
5532 | 53c776b5 | Iustin Pop | raise errors.OpExecError("Instance does not seem to be running at all." |
5533 | 53c776b5 | Iustin Pop | " In this case, it's safer to repair by"
|
5534 | 53c776b5 | Iustin Pop | " running 'gnt-instance stop' to ensure disk"
|
5535 | 53c776b5 | Iustin Pop | " shutdown, and then restarting it.")
|
5536 | 53c776b5 | Iustin Pop | |
5537 | 53c776b5 | Iustin Pop | if runningon_target:
|
5538 | 53c776b5 | Iustin Pop | # the migration has actually succeeded, we need to update the config
|
5539 | 53c776b5 | Iustin Pop | self.feedback_fn("* instance running on secondary node (%s)," |
5540 | 53c776b5 | Iustin Pop | " updating config" % target_node)
|
5541 | 53c776b5 | Iustin Pop | instance.primary_node = target_node |
5542 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, self.feedback_fn) |
5543 | 53c776b5 | Iustin Pop | demoted_node = source_node |
5544 | 53c776b5 | Iustin Pop | else:
|
5545 | 53c776b5 | Iustin Pop | self.feedback_fn("* instance confirmed to be running on its" |
5546 | 53c776b5 | Iustin Pop | " primary node (%s)" % source_node)
|
5547 | 53c776b5 | Iustin Pop | demoted_node = target_node |
5548 | 53c776b5 | Iustin Pop | |
5549 | 53c776b5 | Iustin Pop | self._EnsureSecondary(demoted_node)
|
5550 | 53c776b5 | Iustin Pop | try:
|
5551 | 53c776b5 | Iustin Pop | self._WaitUntilSync()
|
5552 | 53c776b5 | Iustin Pop | except errors.OpExecError:
|
5553 | 53c776b5 | Iustin Pop | # we ignore here errors, since if the device is standalone, it
|
5554 | 53c776b5 | Iustin Pop | # won't be able to sync
|
5555 | 53c776b5 | Iustin Pop | pass
|
5556 | 53c776b5 | Iustin Pop | self._GoStandalone()
|
5557 | 53c776b5 | Iustin Pop | self._GoReconnect(False) |
5558 | 53c776b5 | Iustin Pop | self._WaitUntilSync()
|
5559 | 53c776b5 | Iustin Pop | |
5560 | 53c776b5 | Iustin Pop | self.feedback_fn("* done") |
5561 | 53c776b5 | Iustin Pop | |
5562 | 6906a9d8 | Guido Trotter | def _RevertDiskStatus(self): |
5563 | 6906a9d8 | Guido Trotter | """Try to revert the disk status after a failed migration.
|
5564 | 6906a9d8 | Guido Trotter |
|
5565 | 6906a9d8 | Guido Trotter | """
|
5566 | 6906a9d8 | Guido Trotter | target_node = self.target_node
|
5567 | 6906a9d8 | Guido Trotter | try:
|
5568 | 6906a9d8 | Guido Trotter | self._EnsureSecondary(target_node)
|
5569 | 6906a9d8 | Guido Trotter | self._GoStandalone()
|
5570 | 6906a9d8 | Guido Trotter | self._GoReconnect(False) |
5571 | 6906a9d8 | Guido Trotter | self._WaitUntilSync()
|
5572 | 6906a9d8 | Guido Trotter | except errors.OpExecError, err:
|
5573 | 3e06e001 | Michael Hanselmann | self.lu.LogWarning("Migration failed and I can't reconnect the" |
5574 | 3e06e001 | Michael Hanselmann | " drives: error '%s'\n"
|
5575 | 3e06e001 | Michael Hanselmann | "Please look and recover the instance status" %
|
5576 | 3e06e001 | Michael Hanselmann | str(err))
|
5577 | 6906a9d8 | Guido Trotter | |
5578 | 6906a9d8 | Guido Trotter | def _AbortMigration(self): |
5579 | 6906a9d8 | Guido Trotter | """Call the hypervisor code to abort a started migration.
|
5580 | 6906a9d8 | Guido Trotter |
|
5581 | 6906a9d8 | Guido Trotter | """
|
5582 | 6906a9d8 | Guido Trotter | instance = self.instance
|
5583 | 6906a9d8 | Guido Trotter | target_node = self.target_node
|
5584 | 6906a9d8 | Guido Trotter | migration_info = self.migration_info
|
5585 | 6906a9d8 | Guido Trotter | |
5586 | 6906a9d8 | Guido Trotter | abort_result = self.rpc.call_finalize_migration(target_node,
|
5587 | 6906a9d8 | Guido Trotter | instance, |
5588 | 6906a9d8 | Guido Trotter | migration_info, |
5589 | 6906a9d8 | Guido Trotter | False)
|
5590 | 4c4e4e1e | Iustin Pop | abort_msg = abort_result.fail_msg |
5591 | 6906a9d8 | Guido Trotter | if abort_msg:
|
5592 | 099c52ad | Iustin Pop | logging.error("Aborting migration failed on target node %s: %s",
|
5593 | 099c52ad | Iustin Pop | target_node, abort_msg) |
5594 | 6906a9d8 | Guido Trotter | # Don't raise an exception here, as we stil have to try to revert the
|
5595 | 6906a9d8 | Guido Trotter | # disk status, even if this step failed.
|
5596 | 6906a9d8 | Guido Trotter | |
5597 | 53c776b5 | Iustin Pop | def _ExecMigration(self): |
5598 | 53c776b5 | Iustin Pop | """Migrate an instance.
|
5599 | 53c776b5 | Iustin Pop |
|
5600 | 53c776b5 | Iustin Pop | The migrate is done by:
|
5601 | 53c776b5 | Iustin Pop | - change the disks into dual-master mode
|
5602 | 53c776b5 | Iustin Pop | - wait until disks are fully synchronized again
|
5603 | 53c776b5 | Iustin Pop | - migrate the instance
|
5604 | 53c776b5 | Iustin Pop | - change disks on the new secondary node (the old primary) to secondary
|
5605 | 53c776b5 | Iustin Pop | - wait until disks are fully synchronized
|
5606 | 53c776b5 | Iustin Pop | - change disks into single-master mode
|
5607 | 53c776b5 | Iustin Pop |
|
5608 | 53c776b5 | Iustin Pop | """
|
5609 | 53c776b5 | Iustin Pop | instance = self.instance
|
5610 | 53c776b5 | Iustin Pop | target_node = self.target_node
|
5611 | 53c776b5 | Iustin Pop | source_node = self.source_node
|
5612 | 53c776b5 | Iustin Pop | |
5613 | 53c776b5 | Iustin Pop | self.feedback_fn("* checking disk consistency between source and target") |
5614 | 53c776b5 | Iustin Pop | for dev in instance.disks: |
5615 | 53c776b5 | Iustin Pop | if not _CheckDiskConsistency(self, dev, target_node, False): |
5616 | 53c776b5 | Iustin Pop | raise errors.OpExecError("Disk %s is degraded or not fully" |
5617 | 53c776b5 | Iustin Pop | " synchronized on target node,"
|
5618 | 53c776b5 | Iustin Pop | " aborting migrate." % dev.iv_name)
|
5619 | 53c776b5 | Iustin Pop | |
5620 | 6906a9d8 | Guido Trotter | # First get the migration information from the remote node
|
5621 | 6906a9d8 | Guido Trotter | result = self.rpc.call_migration_info(source_node, instance)
|
5622 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
5623 | 6906a9d8 | Guido Trotter | if msg:
|
5624 | 6906a9d8 | Guido Trotter | log_err = ("Failed fetching source migration information from %s: %s" %
|
5625 | 0959c824 | Iustin Pop | (source_node, msg)) |
5626 | 6906a9d8 | Guido Trotter | logging.error(log_err) |
5627 | 6906a9d8 | Guido Trotter | raise errors.OpExecError(log_err)
|
5628 | 6906a9d8 | Guido Trotter | |
5629 | 0959c824 | Iustin Pop | self.migration_info = migration_info = result.payload
|
5630 | 6906a9d8 | Guido Trotter | |
5631 | 6906a9d8 | Guido Trotter | # Then switch the disks to master/master mode
|
5632 | 53c776b5 | Iustin Pop | self._EnsureSecondary(target_node)
|
5633 | 53c776b5 | Iustin Pop | self._GoStandalone()
|
5634 | 53c776b5 | Iustin Pop | self._GoReconnect(True) |
5635 | 53c776b5 | Iustin Pop | self._WaitUntilSync()
|
5636 | 53c776b5 | Iustin Pop | |
5637 | 6906a9d8 | Guido Trotter | self.feedback_fn("* preparing %s to accept the instance" % target_node) |
5638 | 6906a9d8 | Guido Trotter | result = self.rpc.call_accept_instance(target_node,
|
5639 | 6906a9d8 | Guido Trotter | instance, |
5640 | 6906a9d8 | Guido Trotter | migration_info, |
5641 | 6906a9d8 | Guido Trotter | self.nodes_ip[target_node])
|
5642 | 6906a9d8 | Guido Trotter | |
5643 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
5644 | 6906a9d8 | Guido Trotter | if msg:
|
5645 | 6906a9d8 | Guido Trotter | logging.error("Instance pre-migration failed, trying to revert"
|
5646 | 6906a9d8 | Guido Trotter | " disk status: %s", msg)
|
5647 | 78212a5d | Iustin Pop | self.feedback_fn("Pre-migration failed, aborting") |
5648 | 6906a9d8 | Guido Trotter | self._AbortMigration()
|
5649 | 6906a9d8 | Guido Trotter | self._RevertDiskStatus()
|
5650 | 6906a9d8 | Guido Trotter | raise errors.OpExecError("Could not pre-migrate instance %s: %s" % |
5651 | 6906a9d8 | Guido Trotter | (instance.name, msg)) |
5652 | 6906a9d8 | Guido Trotter | |
5653 | 53c776b5 | Iustin Pop | self.feedback_fn("* migrating instance to %s" % target_node) |
5654 | 53c776b5 | Iustin Pop | time.sleep(10)
|
5655 | 53c776b5 | Iustin Pop | result = self.rpc.call_instance_migrate(source_node, instance,
|
5656 | 53c776b5 | Iustin Pop | self.nodes_ip[target_node],
|
5657 | 3e06e001 | Michael Hanselmann | self.live)
|
5658 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
5659 | 53c776b5 | Iustin Pop | if msg:
|
5660 | 53c776b5 | Iustin Pop | logging.error("Instance migration failed, trying to revert"
|
5661 | 53c776b5 | Iustin Pop | " disk status: %s", msg)
|
5662 | 78212a5d | Iustin Pop | self.feedback_fn("Migration failed, aborting") |
5663 | 6906a9d8 | Guido Trotter | self._AbortMigration()
|
5664 | 6906a9d8 | Guido Trotter | self._RevertDiskStatus()
|
5665 | 53c776b5 | Iustin Pop | raise errors.OpExecError("Could not migrate instance %s: %s" % |
5666 | 53c776b5 | Iustin Pop | (instance.name, msg)) |
5667 | 53c776b5 | Iustin Pop | time.sleep(10)
|
5668 | 53c776b5 | Iustin Pop | |
5669 | 53c776b5 | Iustin Pop | instance.primary_node = target_node |
5670 | 53c776b5 | Iustin Pop | # distribute new instance config to the other nodes
|
5671 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, self.feedback_fn) |
5672 | 53c776b5 | Iustin Pop | |
5673 | 6906a9d8 | Guido Trotter | result = self.rpc.call_finalize_migration(target_node,
|
5674 | 6906a9d8 | Guido Trotter | instance, |
5675 | 6906a9d8 | Guido Trotter | migration_info, |
5676 | 6906a9d8 | Guido Trotter | True)
|
5677 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
5678 | 6906a9d8 | Guido Trotter | if msg:
|
5679 | 6906a9d8 | Guido Trotter | logging.error("Instance migration succeeded, but finalization failed:"
|
5680 | 099c52ad | Iustin Pop | " %s", msg)
|
5681 | 6906a9d8 | Guido Trotter | raise errors.OpExecError("Could not finalize instance migration: %s" % |
5682 | 6906a9d8 | Guido Trotter | msg) |
5683 | 6906a9d8 | Guido Trotter | |
5684 | 53c776b5 | Iustin Pop | self._EnsureSecondary(source_node)
|
5685 | 53c776b5 | Iustin Pop | self._WaitUntilSync()
|
5686 | 53c776b5 | Iustin Pop | self._GoStandalone()
|
5687 | 53c776b5 | Iustin Pop | self._GoReconnect(False) |
5688 | 53c776b5 | Iustin Pop | self._WaitUntilSync()
|
5689 | 53c776b5 | Iustin Pop | |
5690 | 53c776b5 | Iustin Pop | self.feedback_fn("* done") |
5691 | 53c776b5 | Iustin Pop | |
5692 | 53c776b5 | Iustin Pop | def Exec(self, feedback_fn): |
5693 | 53c776b5 | Iustin Pop | """Perform the migration.
|
5694 | 53c776b5 | Iustin Pop |
|
5695 | 53c776b5 | Iustin Pop | """
|
5696 | 80cb875c | Michael Hanselmann | feedback_fn("Migrating instance %s" % self.instance.name) |
5697 | 80cb875c | Michael Hanselmann | |
5698 | 53c776b5 | Iustin Pop | self.feedback_fn = feedback_fn
|
5699 | 53c776b5 | Iustin Pop | |
5700 | 53c776b5 | Iustin Pop | self.source_node = self.instance.primary_node |
5701 | 53c776b5 | Iustin Pop | self.target_node = self.instance.secondary_nodes[0] |
5702 | 53c776b5 | Iustin Pop | self.all_nodes = [self.source_node, self.target_node] |
5703 | 53c776b5 | Iustin Pop | self.nodes_ip = {
|
5704 | 53c776b5 | Iustin Pop | self.source_node: self.cfg.GetNodeInfo(self.source_node).secondary_ip, |
5705 | 53c776b5 | Iustin Pop | self.target_node: self.cfg.GetNodeInfo(self.target_node).secondary_ip, |
5706 | 53c776b5 | Iustin Pop | } |
5707 | 3e06e001 | Michael Hanselmann | |
5708 | 3e06e001 | Michael Hanselmann | if self.cleanup: |
5709 | 53c776b5 | Iustin Pop | return self._ExecCleanup() |
5710 | 53c776b5 | Iustin Pop | else:
|
5711 | 53c776b5 | Iustin Pop | return self._ExecMigration() |
5712 | 53c776b5 | Iustin Pop | |
5713 | 53c776b5 | Iustin Pop | |
5714 | 428958aa | Iustin Pop | def _CreateBlockDev(lu, node, instance, device, force_create, |
5715 | 428958aa | Iustin Pop | info, force_open): |
5716 | 428958aa | Iustin Pop | """Create a tree of block devices on a given node.
|
5717 | a8083063 | Iustin Pop |
|
5718 | a8083063 | Iustin Pop | If this device type has to be created on secondaries, create it and
|
5719 | a8083063 | Iustin Pop | all its children.
|
5720 | a8083063 | Iustin Pop |
|
5721 | a8083063 | Iustin Pop | If not, just recurse to children keeping the same 'force' value.
|
5722 | a8083063 | Iustin Pop |
|
5723 | 428958aa | Iustin Pop | @param lu: the lu on whose behalf we execute
|
5724 | 428958aa | Iustin Pop | @param node: the node on which to create the device
|
5725 | 428958aa | Iustin Pop | @type instance: L{objects.Instance}
|
5726 | 428958aa | Iustin Pop | @param instance: the instance which owns the device
|
5727 | 428958aa | Iustin Pop | @type device: L{objects.Disk}
|
5728 | 428958aa | Iustin Pop | @param device: the device to create
|
5729 | 428958aa | Iustin Pop | @type force_create: boolean
|
5730 | 428958aa | Iustin Pop | @param force_create: whether to force creation of this device; this
|
5731 | 428958aa | Iustin Pop | will be change to True whenever we find a device which has
|
5732 | 428958aa | Iustin Pop | CreateOnSecondary() attribute
|
5733 | 428958aa | Iustin Pop | @param info: the extra 'metadata' we should attach to the device
|
5734 | 428958aa | Iustin Pop | (this will be represented as a LVM tag)
|
5735 | 428958aa | Iustin Pop | @type force_open: boolean
|
5736 | 428958aa | Iustin Pop | @param force_open: this parameter will be passes to the
|
5737 | 821d1bd1 | Iustin Pop | L{backend.BlockdevCreate} function where it specifies
|
5738 | 428958aa | Iustin Pop | whether we run on primary or not, and it affects both
|
5739 | 428958aa | Iustin Pop | the child assembly and the device own Open() execution
|
5740 | 428958aa | Iustin Pop |
|
5741 | a8083063 | Iustin Pop | """
|
5742 | a8083063 | Iustin Pop | if device.CreateOnSecondary():
|
5743 | 428958aa | Iustin Pop | force_create = True
|
5744 | 796cab27 | Iustin Pop | |
5745 | a8083063 | Iustin Pop | if device.children:
|
5746 | a8083063 | Iustin Pop | for child in device.children: |
5747 | 428958aa | Iustin Pop | _CreateBlockDev(lu, node, instance, child, force_create, |
5748 | 428958aa | Iustin Pop | info, force_open) |
5749 | a8083063 | Iustin Pop | |
5750 | 428958aa | Iustin Pop | if not force_create: |
5751 | 796cab27 | Iustin Pop | return
|
5752 | 796cab27 | Iustin Pop | |
5753 | de12473a | Iustin Pop | _CreateSingleBlockDev(lu, node, instance, device, info, force_open) |
5754 | de12473a | Iustin Pop | |
5755 | de12473a | Iustin Pop | |
5756 | de12473a | Iustin Pop | def _CreateSingleBlockDev(lu, node, instance, device, info, force_open): |
5757 | de12473a | Iustin Pop | """Create a single block device on a given node.
|
5758 | de12473a | Iustin Pop |
|
5759 | de12473a | Iustin Pop | This will not recurse over children of the device, so they must be
|
5760 | de12473a | Iustin Pop | created in advance.
|
5761 | de12473a | Iustin Pop |
|
5762 | de12473a | Iustin Pop | @param lu: the lu on whose behalf we execute
|
5763 | de12473a | Iustin Pop | @param node: the node on which to create the device
|
5764 | de12473a | Iustin Pop | @type instance: L{objects.Instance}
|
5765 | de12473a | Iustin Pop | @param instance: the instance which owns the device
|
5766 | de12473a | Iustin Pop | @type device: L{objects.Disk}
|
5767 | de12473a | Iustin Pop | @param device: the device to create
|
5768 | de12473a | Iustin Pop | @param info: the extra 'metadata' we should attach to the device
|
5769 | de12473a | Iustin Pop | (this will be represented as a LVM tag)
|
5770 | de12473a | Iustin Pop | @type force_open: boolean
|
5771 | de12473a | Iustin Pop | @param force_open: this parameter will be passes to the
|
5772 | 821d1bd1 | Iustin Pop | L{backend.BlockdevCreate} function where it specifies
|
5773 | de12473a | Iustin Pop | whether we run on primary or not, and it affects both
|
5774 | de12473a | Iustin Pop | the child assembly and the device own Open() execution
|
5775 | de12473a | Iustin Pop |
|
5776 | de12473a | Iustin Pop | """
|
5777 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(device, node) |
5778 | 7d81697f | Iustin Pop | result = lu.rpc.call_blockdev_create(node, device, device.size, |
5779 | 428958aa | Iustin Pop | instance.name, force_open, info) |
5780 | 4c4e4e1e | Iustin Pop | result.Raise("Can't create block device %s on"
|
5781 | 4c4e4e1e | Iustin Pop | " node %s for instance %s" % (device, node, instance.name))
|
5782 | a8083063 | Iustin Pop | if device.physical_id is None: |
5783 | 0959c824 | Iustin Pop | device.physical_id = result.payload |
5784 | a8083063 | Iustin Pop | |
5785 | a8083063 | Iustin Pop | |
5786 | b9bddb6b | Iustin Pop | def _GenerateUniqueNames(lu, exts): |
5787 | 923b1523 | Iustin Pop | """Generate a suitable LV name.
|
5788 | 923b1523 | Iustin Pop |
|
5789 | 923b1523 | Iustin Pop | This will generate a logical volume name for the given instance.
|
5790 | 923b1523 | Iustin Pop |
|
5791 | 923b1523 | Iustin Pop | """
|
5792 | 923b1523 | Iustin Pop | results = [] |
5793 | 923b1523 | Iustin Pop | for val in exts: |
5794 | 4fae38c5 | Guido Trotter | new_id = lu.cfg.GenerateUniqueID(lu.proc.GetECId()) |
5795 | 923b1523 | Iustin Pop | results.append("%s%s" % (new_id, val))
|
5796 | 923b1523 | Iustin Pop | return results
|
5797 | 923b1523 | Iustin Pop | |
5798 | 923b1523 | Iustin Pop | |
5799 | b9bddb6b | Iustin Pop | def _GenerateDRBD8Branch(lu, primary, secondary, size, names, iv_name, |
5800 | ffa1c0dc | Iustin Pop | p_minor, s_minor): |
5801 | a1f445d3 | Iustin Pop | """Generate a drbd8 device complete with its children.
|
5802 | a1f445d3 | Iustin Pop |
|
5803 | a1f445d3 | Iustin Pop | """
|
5804 | b9bddb6b | Iustin Pop | port = lu.cfg.AllocatePort() |
5805 | b9bddb6b | Iustin Pop | vgname = lu.cfg.GetVGName() |
5806 | afa1386e | Guido Trotter | shared_secret = lu.cfg.GenerateDRBDSecret(lu.proc.GetECId()) |
5807 | a1f445d3 | Iustin Pop | dev_data = objects.Disk(dev_type=constants.LD_LV, size=size, |
5808 | a1f445d3 | Iustin Pop | logical_id=(vgname, names[0]))
|
5809 | a1f445d3 | Iustin Pop | dev_meta = objects.Disk(dev_type=constants.LD_LV, size=128,
|
5810 | a1f445d3 | Iustin Pop | logical_id=(vgname, names[1]))
|
5811 | a1f445d3 | Iustin Pop | drbd_dev = objects.Disk(dev_type=constants.LD_DRBD8, size=size, |
5812 | ffa1c0dc | Iustin Pop | logical_id=(primary, secondary, port, |
5813 | f9518d38 | Iustin Pop | p_minor, s_minor, |
5814 | f9518d38 | Iustin Pop | shared_secret), |
5815 | ffa1c0dc | Iustin Pop | children=[dev_data, dev_meta], |
5816 | a1f445d3 | Iustin Pop | iv_name=iv_name) |
5817 | a1f445d3 | Iustin Pop | return drbd_dev
|
5818 | a1f445d3 | Iustin Pop | |
5819 | 7c0d6283 | Michael Hanselmann | |
5820 | b9bddb6b | Iustin Pop | def _GenerateDiskTemplate(lu, template_name, |
5821 | a8083063 | Iustin Pop | instance_name, primary_node, |
5822 | 08db7c5c | Iustin Pop | secondary_nodes, disk_info, |
5823 | e2a65344 | Iustin Pop | file_storage_dir, file_driver, |
5824 | e2a65344 | Iustin Pop | base_index): |
5825 | a8083063 | Iustin Pop | """Generate the entire disk layout for a given template type.
|
5826 | a8083063 | Iustin Pop |
|
5827 | a8083063 | Iustin Pop | """
|
5828 | a8083063 | Iustin Pop | #TODO: compute space requirements
|
5829 | a8083063 | Iustin Pop | |
5830 | b9bddb6b | Iustin Pop | vgname = lu.cfg.GetVGName() |
5831 | 08db7c5c | Iustin Pop | disk_count = len(disk_info)
|
5832 | 08db7c5c | Iustin Pop | disks = [] |
5833 | 3517d9b9 | Manuel Franceschini | if template_name == constants.DT_DISKLESS:
|
5834 | 08db7c5c | Iustin Pop | pass
|
5835 | 3517d9b9 | Manuel Franceschini | elif template_name == constants.DT_PLAIN:
|
5836 | a8083063 | Iustin Pop | if len(secondary_nodes) != 0: |
5837 | a8083063 | Iustin Pop | raise errors.ProgrammerError("Wrong template configuration") |
5838 | 923b1523 | Iustin Pop | |
5839 | fb4b324b | Guido Trotter | names = _GenerateUniqueNames(lu, [".disk%d" % (base_index + i)
|
5840 | 08db7c5c | Iustin Pop | for i in range(disk_count)]) |
5841 | 08db7c5c | Iustin Pop | for idx, disk in enumerate(disk_info): |
5842 | e2a65344 | Iustin Pop | disk_index = idx + base_index |
5843 | 08db7c5c | Iustin Pop | disk_dev = objects.Disk(dev_type=constants.LD_LV, size=disk["size"],
|
5844 | 08db7c5c | Iustin Pop | logical_id=(vgname, names[idx]), |
5845 | 6ec66eae | Iustin Pop | iv_name="disk/%d" % disk_index,
|
5846 | 6ec66eae | Iustin Pop | mode=disk["mode"])
|
5847 | 08db7c5c | Iustin Pop | disks.append(disk_dev) |
5848 | a1f445d3 | Iustin Pop | elif template_name == constants.DT_DRBD8:
|
5849 | a1f445d3 | Iustin Pop | if len(secondary_nodes) != 1: |
5850 | a1f445d3 | Iustin Pop | raise errors.ProgrammerError("Wrong template configuration") |
5851 | a1f445d3 | Iustin Pop | remote_node = secondary_nodes[0]
|
5852 | 08db7c5c | Iustin Pop | minors = lu.cfg.AllocateDRBDMinor( |
5853 | 08db7c5c | Iustin Pop | [primary_node, remote_node] * len(disk_info), instance_name)
|
5854 | 08db7c5c | Iustin Pop | |
5855 | e6c1ff2f | Iustin Pop | names = [] |
5856 | fb4b324b | Guido Trotter | for lv_prefix in _GenerateUniqueNames(lu, [".disk%d" % (base_index + i) |
5857 | e6c1ff2f | Iustin Pop | for i in range(disk_count)]): |
5858 | e6c1ff2f | Iustin Pop | names.append(lv_prefix + "_data")
|
5859 | e6c1ff2f | Iustin Pop | names.append(lv_prefix + "_meta")
|
5860 | 08db7c5c | Iustin Pop | for idx, disk in enumerate(disk_info): |
5861 | 112050d9 | Iustin Pop | disk_index = idx + base_index |
5862 | 08db7c5c | Iustin Pop | disk_dev = _GenerateDRBD8Branch(lu, primary_node, remote_node, |
5863 | 08db7c5c | Iustin Pop | disk["size"], names[idx*2:idx*2+2], |
5864 | e2a65344 | Iustin Pop | "disk/%d" % disk_index,
|
5865 | 08db7c5c | Iustin Pop | minors[idx*2], minors[idx*2+1]) |
5866 | 6ec66eae | Iustin Pop | disk_dev.mode = disk["mode"]
|
5867 | 08db7c5c | Iustin Pop | disks.append(disk_dev) |
5868 | 0f1a06e3 | Manuel Franceschini | elif template_name == constants.DT_FILE:
|
5869 | 0f1a06e3 | Manuel Franceschini | if len(secondary_nodes) != 0: |
5870 | 0f1a06e3 | Manuel Franceschini | raise errors.ProgrammerError("Wrong template configuration") |
5871 | 0f1a06e3 | Manuel Franceschini | |
5872 | 0e3baaf3 | Iustin Pop | _RequireFileStorage() |
5873 | 0e3baaf3 | Iustin Pop | |
5874 | 08db7c5c | Iustin Pop | for idx, disk in enumerate(disk_info): |
5875 | 112050d9 | Iustin Pop | disk_index = idx + base_index |
5876 | 08db7c5c | Iustin Pop | disk_dev = objects.Disk(dev_type=constants.LD_FILE, size=disk["size"],
|
5877 | e2a65344 | Iustin Pop | iv_name="disk/%d" % disk_index,
|
5878 | 08db7c5c | Iustin Pop | logical_id=(file_driver, |
5879 | 08db7c5c | Iustin Pop | "%s/disk%d" % (file_storage_dir,
|
5880 | 43e99cff | Guido Trotter | disk_index)), |
5881 | 6ec66eae | Iustin Pop | mode=disk["mode"])
|
5882 | 08db7c5c | Iustin Pop | disks.append(disk_dev) |
5883 | a8083063 | Iustin Pop | else:
|
5884 | a8083063 | Iustin Pop | raise errors.ProgrammerError("Invalid disk template '%s'" % template_name) |
5885 | a8083063 | Iustin Pop | return disks
|
5886 | a8083063 | Iustin Pop | |
5887 | a8083063 | Iustin Pop | |
5888 | a0c3fea1 | Michael Hanselmann | def _GetInstanceInfoText(instance): |
5889 | 3ecf6786 | Iustin Pop | """Compute that text that should be added to the disk's metadata.
|
5890 | 3ecf6786 | Iustin Pop |
|
5891 | 3ecf6786 | Iustin Pop | """
|
5892 | a0c3fea1 | Michael Hanselmann | return "originstname+%s" % instance.name |
5893 | a0c3fea1 | Michael Hanselmann | |
5894 | a0c3fea1 | Michael Hanselmann | |
5895 | 621b7678 | Iustin Pop | def _CreateDisks(lu, instance, to_skip=None, target_node=None): |
5896 | a8083063 | Iustin Pop | """Create all disks for an instance.
|
5897 | a8083063 | Iustin Pop |
|
5898 | a8083063 | Iustin Pop | This abstracts away some work from AddInstance.
|
5899 | a8083063 | Iustin Pop |
|
5900 | e4376078 | Iustin Pop | @type lu: L{LogicalUnit}
|
5901 | e4376078 | Iustin Pop | @param lu: the logical unit on whose behalf we execute
|
5902 | e4376078 | Iustin Pop | @type instance: L{objects.Instance}
|
5903 | e4376078 | Iustin Pop | @param instance: the instance whose disks we should create
|
5904 | bd315bfa | Iustin Pop | @type to_skip: list
|
5905 | bd315bfa | Iustin Pop | @param to_skip: list of indices to skip
|
5906 | 621b7678 | Iustin Pop | @type target_node: string
|
5907 | 621b7678 | Iustin Pop | @param target_node: if passed, overrides the target node for creation
|
5908 | e4376078 | Iustin Pop | @rtype: boolean
|
5909 | e4376078 | Iustin Pop | @return: the success of the creation
|
5910 | a8083063 | Iustin Pop |
|
5911 | a8083063 | Iustin Pop | """
|
5912 | a0c3fea1 | Michael Hanselmann | info = _GetInstanceInfoText(instance) |
5913 | 621b7678 | Iustin Pop | if target_node is None: |
5914 | 621b7678 | Iustin Pop | pnode = instance.primary_node |
5915 | 621b7678 | Iustin Pop | all_nodes = instance.all_nodes |
5916 | 621b7678 | Iustin Pop | else:
|
5917 | 621b7678 | Iustin Pop | pnode = target_node |
5918 | 621b7678 | Iustin Pop | all_nodes = [pnode] |
5919 | a0c3fea1 | Michael Hanselmann | |
5920 | 0f1a06e3 | Manuel Franceschini | if instance.disk_template == constants.DT_FILE:
|
5921 | 0f1a06e3 | Manuel Franceschini | file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1]) |
5922 | 428958aa | Iustin Pop | result = lu.rpc.call_file_storage_dir_create(pnode, file_storage_dir) |
5923 | 0f1a06e3 | Manuel Franceschini | |
5924 | 4c4e4e1e | Iustin Pop | result.Raise("Failed to create directory '%s' on"
|
5925 | 9b4127eb | Guido Trotter | " node %s" % (file_storage_dir, pnode))
|
5926 | 0f1a06e3 | Manuel Franceschini | |
5927 | 24991749 | Iustin Pop | # Note: this needs to be kept in sync with adding of disks in
|
5928 | 24991749 | Iustin Pop | # LUSetInstanceParams
|
5929 | bd315bfa | Iustin Pop | for idx, device in enumerate(instance.disks): |
5930 | bd315bfa | Iustin Pop | if to_skip and idx in to_skip: |
5931 | bd315bfa | Iustin Pop | continue
|
5932 | 9a4f63d1 | Iustin Pop | logging.info("Creating volume %s for instance %s",
|
5933 | 9a4f63d1 | Iustin Pop | device.iv_name, instance.name) |
5934 | a8083063 | Iustin Pop | #HARDCODE
|
5935 | 621b7678 | Iustin Pop | for node in all_nodes: |
5936 | 428958aa | Iustin Pop | f_create = node == pnode |
5937 | 428958aa | Iustin Pop | _CreateBlockDev(lu, node, instance, device, f_create, info, f_create) |
5938 | a8083063 | Iustin Pop | |
5939 | a8083063 | Iustin Pop | |
5940 | 621b7678 | Iustin Pop | def _RemoveDisks(lu, instance, target_node=None): |
5941 | a8083063 | Iustin Pop | """Remove all disks for an instance.
|
5942 | a8083063 | Iustin Pop |
|
5943 | a8083063 | Iustin Pop | This abstracts away some work from `AddInstance()` and
|
5944 | a8083063 | Iustin Pop | `RemoveInstance()`. Note that in case some of the devices couldn't
|
5945 | 1d67656e | Iustin Pop | be removed, the removal will continue with the other ones (compare
|
5946 | a8083063 | Iustin Pop | with `_CreateDisks()`).
|
5947 | a8083063 | Iustin Pop |
|
5948 | e4376078 | Iustin Pop | @type lu: L{LogicalUnit}
|
5949 | e4376078 | Iustin Pop | @param lu: the logical unit on whose behalf we execute
|
5950 | e4376078 | Iustin Pop | @type instance: L{objects.Instance}
|
5951 | e4376078 | Iustin Pop | @param instance: the instance whose disks we should remove
|
5952 | 621b7678 | Iustin Pop | @type target_node: string
|
5953 | 621b7678 | Iustin Pop | @param target_node: used to override the node on which to remove the disks
|
5954 | e4376078 | Iustin Pop | @rtype: boolean
|
5955 | e4376078 | Iustin Pop | @return: the success of the removal
|
5956 | a8083063 | Iustin Pop |
|
5957 | a8083063 | Iustin Pop | """
|
5958 | 9a4f63d1 | Iustin Pop | logging.info("Removing block devices for instance %s", instance.name)
|
5959 | a8083063 | Iustin Pop | |
5960 | e1bc0878 | Iustin Pop | all_result = True
|
5961 | a8083063 | Iustin Pop | for device in instance.disks: |
5962 | 621b7678 | Iustin Pop | if target_node:
|
5963 | 621b7678 | Iustin Pop | edata = [(target_node, device)] |
5964 | 621b7678 | Iustin Pop | else:
|
5965 | 621b7678 | Iustin Pop | edata = device.ComputeNodeTree(instance.primary_node) |
5966 | 621b7678 | Iustin Pop | for node, disk in edata: |
5967 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(disk, node) |
5968 | 4c4e4e1e | Iustin Pop | msg = lu.rpc.call_blockdev_remove(node, disk).fail_msg |
5969 | e1bc0878 | Iustin Pop | if msg:
|
5970 | e1bc0878 | Iustin Pop | lu.LogWarning("Could not remove block device %s on node %s,"
|
5971 | e1bc0878 | Iustin Pop | " continuing anyway: %s", device.iv_name, node, msg)
|
5972 | e1bc0878 | Iustin Pop | all_result = False
|
5973 | 0f1a06e3 | Manuel Franceschini | |
5974 | 0f1a06e3 | Manuel Franceschini | if instance.disk_template == constants.DT_FILE:
|
5975 | 0f1a06e3 | Manuel Franceschini | file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1]) |
5976 | dfc2a24c | Guido Trotter | if target_node:
|
5977 | dfc2a24c | Guido Trotter | tgt = target_node |
5978 | 621b7678 | Iustin Pop | else:
|
5979 | dfc2a24c | Guido Trotter | tgt = instance.primary_node |
5980 | 621b7678 | Iustin Pop | result = lu.rpc.call_file_storage_dir_remove(tgt, file_storage_dir) |
5981 | 621b7678 | Iustin Pop | if result.fail_msg:
|
5982 | b2b8bcce | Iustin Pop | lu.LogWarning("Could not remove directory '%s' on node %s: %s",
|
5983 | 621b7678 | Iustin Pop | file_storage_dir, instance.primary_node, result.fail_msg) |
5984 | e1bc0878 | Iustin Pop | all_result = False
|
5985 | 0f1a06e3 | Manuel Franceschini | |
5986 | e1bc0878 | Iustin Pop | return all_result
|
5987 | a8083063 | Iustin Pop | |
5988 | a8083063 | Iustin Pop | |
5989 | 08db7c5c | Iustin Pop | def _ComputeDiskSize(disk_template, disks): |
5990 | e2fe6369 | Iustin Pop | """Compute disk size requirements in the volume group
|
5991 | e2fe6369 | Iustin Pop |
|
5992 | e2fe6369 | Iustin Pop | """
|
5993 | e2fe6369 | Iustin Pop | # Required free disk space as a function of disk and swap space
|
5994 | e2fe6369 | Iustin Pop | req_size_dict = { |
5995 | e2fe6369 | Iustin Pop | constants.DT_DISKLESS: None,
|
5996 | 08db7c5c | Iustin Pop | constants.DT_PLAIN: sum(d["size"] for d in disks), |
5997 | 08db7c5c | Iustin Pop | # 128 MB are added for drbd metadata for each disk
|
5998 | 08db7c5c | Iustin Pop | constants.DT_DRBD8: sum(d["size"] + 128 for d in disks), |
5999 | e2fe6369 | Iustin Pop | constants.DT_FILE: None,
|
6000 | e2fe6369 | Iustin Pop | } |
6001 | e2fe6369 | Iustin Pop | |
6002 | e2fe6369 | Iustin Pop | if disk_template not in req_size_dict: |
6003 | e2fe6369 | Iustin Pop | raise errors.ProgrammerError("Disk template '%s' size requirement" |
6004 | e2fe6369 | Iustin Pop | " is unknown" % disk_template)
|
6005 | e2fe6369 | Iustin Pop | |
6006 | e2fe6369 | Iustin Pop | return req_size_dict[disk_template]
|
6007 | e2fe6369 | Iustin Pop | |
6008 | e2fe6369 | Iustin Pop | |
6009 | 74409b12 | Iustin Pop | def _CheckHVParams(lu, nodenames, hvname, hvparams): |
6010 | 74409b12 | Iustin Pop | """Hypervisor parameter validation.
|
6011 | 74409b12 | Iustin Pop |
|
6012 | 74409b12 | Iustin Pop | This function abstract the hypervisor parameter validation to be
|
6013 | 74409b12 | Iustin Pop | used in both instance create and instance modify.
|
6014 | 74409b12 | Iustin Pop |
|
6015 | 74409b12 | Iustin Pop | @type lu: L{LogicalUnit}
|
6016 | 74409b12 | Iustin Pop | @param lu: the logical unit for which we check
|
6017 | 74409b12 | Iustin Pop | @type nodenames: list
|
6018 | 74409b12 | Iustin Pop | @param nodenames: the list of nodes on which we should check
|
6019 | 74409b12 | Iustin Pop | @type hvname: string
|
6020 | 74409b12 | Iustin Pop | @param hvname: the name of the hypervisor we should use
|
6021 | 74409b12 | Iustin Pop | @type hvparams: dict
|
6022 | 74409b12 | Iustin Pop | @param hvparams: the parameters which we need to check
|
6023 | 74409b12 | Iustin Pop | @raise errors.OpPrereqError: if the parameters are not valid
|
6024 | 74409b12 | Iustin Pop |
|
6025 | 74409b12 | Iustin Pop | """
|
6026 | 74409b12 | Iustin Pop | hvinfo = lu.rpc.call_hypervisor_validate_params(nodenames, |
6027 | 74409b12 | Iustin Pop | hvname, |
6028 | 74409b12 | Iustin Pop | hvparams) |
6029 | 74409b12 | Iustin Pop | for node in nodenames: |
6030 | 781de953 | Iustin Pop | info = hvinfo[node] |
6031 | 68c6f21c | Iustin Pop | if info.offline:
|
6032 | 68c6f21c | Iustin Pop | continue
|
6033 | 4c4e4e1e | Iustin Pop | info.Raise("Hypervisor parameter validation failed on node %s" % node)
|
6034 | 74409b12 | Iustin Pop | |
6035 | 74409b12 | Iustin Pop | |
6036 | a8083063 | Iustin Pop | class LUCreateInstance(LogicalUnit): |
6037 | a8083063 | Iustin Pop | """Create an instance.
|
6038 | a8083063 | Iustin Pop |
|
6039 | a8083063 | Iustin Pop | """
|
6040 | a8083063 | Iustin Pop | HPATH = "instance-add"
|
6041 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
6042 | f276c4b5 | Iustin Pop | _OP_REQP = ["instance_name", "disks", |
6043 | 08db7c5c | Iustin Pop | "mode", "start", |
6044 | 08db7c5c | Iustin Pop | "wait_for_sync", "ip_check", "nics", |
6045 | 338e51e8 | Iustin Pop | "hvparams", "beparams"] |
6046 | 7baf741d | Guido Trotter | REQ_BGL = False
|
6047 | 7baf741d | Guido Trotter | |
6048 | 5f23e043 | Iustin Pop | def CheckArguments(self): |
6049 | 5f23e043 | Iustin Pop | """Check arguments.
|
6050 | 5f23e043 | Iustin Pop |
|
6051 | 5f23e043 | Iustin Pop | """
|
6052 | df4272e5 | Iustin Pop | # set optional parameters to none if they don't exist
|
6053 | f276c4b5 | Iustin Pop | for attr in ["pnode", "snode", "iallocator", "hypervisor", |
6054 | e588764d | Iustin Pop | "disk_template", "identify_defaults"]: |
6055 | df4272e5 | Iustin Pop | if not hasattr(self.op, attr): |
6056 | df4272e5 | Iustin Pop | setattr(self.op, attr, None) |
6057 | df4272e5 | Iustin Pop | |
6058 | 5f23e043 | Iustin Pop | # do not require name_check to ease forward/backward compatibility
|
6059 | 5f23e043 | Iustin Pop | # for tools
|
6060 | 5f23e043 | Iustin Pop | if not hasattr(self.op, "name_check"): |
6061 | 5f23e043 | Iustin Pop | self.op.name_check = True |
6062 | 25a8792c | Iustin Pop | if not hasattr(self.op, "no_install"): |
6063 | 25a8792c | Iustin Pop | self.op.no_install = False |
6064 | 25a8792c | Iustin Pop | if self.op.no_install and self.op.start: |
6065 | 25a8792c | Iustin Pop | self.LogInfo("No-installation mode selected, disabling startup") |
6066 | 25a8792c | Iustin Pop | self.op.start = False |
6067 | 44caf5a8 | Iustin Pop | # validate/normalize the instance name
|
6068 | 44caf5a8 | Iustin Pop | self.op.instance_name = utils.HostInfo.NormalizeName(self.op.instance_name) |
6069 | 5f23e043 | Iustin Pop | if self.op.ip_check and not self.op.name_check: |
6070 | 5f23e043 | Iustin Pop | # TODO: make the ip check more flexible and not depend on the name check
|
6071 | 5f23e043 | Iustin Pop | raise errors.OpPrereqError("Cannot do ip checks without a name check", |
6072 | 5f23e043 | Iustin Pop | errors.ECODE_INVAL) |
6073 | c3589cf8 | Iustin Pop | # check disk information: either all adopt, or no adopt
|
6074 | c3589cf8 | Iustin Pop | has_adopt = has_no_adopt = False
|
6075 | c3589cf8 | Iustin Pop | for disk in self.op.disks: |
6076 | c3589cf8 | Iustin Pop | if "adopt" in disk: |
6077 | c3589cf8 | Iustin Pop | has_adopt = True
|
6078 | c3589cf8 | Iustin Pop | else:
|
6079 | c3589cf8 | Iustin Pop | has_no_adopt = True
|
6080 | c3589cf8 | Iustin Pop | if has_adopt and has_no_adopt: |
6081 | 417eabe2 | Iustin Pop | raise errors.OpPrereqError("Either all disks are adopted or none is", |
6082 | c3589cf8 | Iustin Pop | errors.ECODE_INVAL) |
6083 | c3589cf8 | Iustin Pop | if has_adopt:
|
6084 | c3589cf8 | Iustin Pop | if self.op.disk_template != constants.DT_PLAIN: |
6085 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("Disk adoption is only supported for the" |
6086 | c3589cf8 | Iustin Pop | " 'plain' disk template",
|
6087 | c3589cf8 | Iustin Pop | errors.ECODE_INVAL) |
6088 | c3589cf8 | Iustin Pop | if self.op.iallocator is not None: |
6089 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("Disk adoption not allowed with an" |
6090 | c3589cf8 | Iustin Pop | " iallocator script", errors.ECODE_INVAL)
|
6091 | c3589cf8 | Iustin Pop | if self.op.mode == constants.INSTANCE_IMPORT: |
6092 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("Disk adoption not allowed for" |
6093 | c3589cf8 | Iustin Pop | " instance import", errors.ECODE_INVAL)
|
6094 | c3589cf8 | Iustin Pop | |
6095 | c3589cf8 | Iustin Pop | self.adopt_disks = has_adopt
|
6096 | 5f23e043 | Iustin Pop | |
6097 | 417eabe2 | Iustin Pop | # verify creation mode
|
6098 | 417eabe2 | Iustin Pop | if self.op.mode not in (constants.INSTANCE_CREATE, |
6099 | 417eabe2 | Iustin Pop | constants.INSTANCE_IMPORT): |
6100 | 417eabe2 | Iustin Pop | raise errors.OpPrereqError("Invalid instance creation mode '%s'" % |
6101 | 417eabe2 | Iustin Pop | self.op.mode, errors.ECODE_INVAL)
|
6102 | 417eabe2 | Iustin Pop | |
6103 | 417eabe2 | Iustin Pop | # instance name verification
|
6104 | 417eabe2 | Iustin Pop | if self.op.name_check: |
6105 | 417eabe2 | Iustin Pop | self.hostname1 = utils.GetHostInfo(self.op.instance_name) |
6106 | 417eabe2 | Iustin Pop | self.op.instance_name = self.hostname1.name |
6107 | 417eabe2 | Iustin Pop | # used in CheckPrereq for ip ping check
|
6108 | 417eabe2 | Iustin Pop | self.check_ip = self.hostname1.ip |
6109 | 417eabe2 | Iustin Pop | else:
|
6110 | 417eabe2 | Iustin Pop | self.check_ip = None |
6111 | 417eabe2 | Iustin Pop | |
6112 | 417eabe2 | Iustin Pop | # file storage checks
|
6113 | 417eabe2 | Iustin Pop | if (self.op.file_driver and |
6114 | 417eabe2 | Iustin Pop | not self.op.file_driver in constants.FILE_DRIVER): |
6115 | 417eabe2 | Iustin Pop | raise errors.OpPrereqError("Invalid file driver name '%s'" % |
6116 | 417eabe2 | Iustin Pop | self.op.file_driver, errors.ECODE_INVAL)
|
6117 | 417eabe2 | Iustin Pop | |
6118 | 417eabe2 | Iustin Pop | if self.op.file_storage_dir and os.path.isabs(self.op.file_storage_dir): |
6119 | 417eabe2 | Iustin Pop | raise errors.OpPrereqError("File storage directory path not absolute", |
6120 | 417eabe2 | Iustin Pop | errors.ECODE_INVAL) |
6121 | 417eabe2 | Iustin Pop | |
6122 | 417eabe2 | Iustin Pop | ### Node/iallocator related checks
|
6123 | 417eabe2 | Iustin Pop | if [self.op.iallocator, self.op.pnode].count(None) != 1: |
6124 | 417eabe2 | Iustin Pop | raise errors.OpPrereqError("One and only one of iallocator and primary" |
6125 | 417eabe2 | Iustin Pop | " node must be given",
|
6126 | 417eabe2 | Iustin Pop | errors.ECODE_INVAL) |
6127 | 417eabe2 | Iustin Pop | |
6128 | 417eabe2 | Iustin Pop | if self.op.mode == constants.INSTANCE_IMPORT: |
6129 | 417eabe2 | Iustin Pop | # On import force_variant must be True, because if we forced it at
|
6130 | 417eabe2 | Iustin Pop | # initial install, our only chance when importing it back is that it
|
6131 | 417eabe2 | Iustin Pop | # works again!
|
6132 | 417eabe2 | Iustin Pop | self.op.force_variant = True |
6133 | 417eabe2 | Iustin Pop | |
6134 | 417eabe2 | Iustin Pop | if self.op.no_install: |
6135 | 417eabe2 | Iustin Pop | self.LogInfo("No-installation mode has no effect during import") |
6136 | 417eabe2 | Iustin Pop | |
6137 | 417eabe2 | Iustin Pop | else: # INSTANCE_CREATE |
6138 | 417eabe2 | Iustin Pop | if getattr(self.op, "os_type", None) is None: |
6139 | 417eabe2 | Iustin Pop | raise errors.OpPrereqError("No guest OS specified", |
6140 | 417eabe2 | Iustin Pop | errors.ECODE_INVAL) |
6141 | 417eabe2 | Iustin Pop | self.op.force_variant = getattr(self.op, "force_variant", False) |
6142 | f276c4b5 | Iustin Pop | if self.op.disk_template is None: |
6143 | f276c4b5 | Iustin Pop | raise errors.OpPrereqError("No disk template specified", |
6144 | f276c4b5 | Iustin Pop | errors.ECODE_INVAL) |
6145 | 417eabe2 | Iustin Pop | |
6146 | 7baf741d | Guido Trotter | def ExpandNames(self): |
6147 | 7baf741d | Guido Trotter | """ExpandNames for CreateInstance.
|
6148 | 7baf741d | Guido Trotter |
|
6149 | 7baf741d | Guido Trotter | Figure out the right locks for instance creation.
|
6150 | 7baf741d | Guido Trotter |
|
6151 | 7baf741d | Guido Trotter | """
|
6152 | 7baf741d | Guido Trotter | self.needed_locks = {}
|
6153 | 7baf741d | Guido Trotter | |
6154 | 417eabe2 | Iustin Pop | instance_name = self.op.instance_name
|
6155 | 7baf741d | Guido Trotter | # this is just a preventive check, but someone might still add this
|
6156 | 7baf741d | Guido Trotter | # instance in the meantime, and creation will fail at lock-add time
|
6157 | 7baf741d | Guido Trotter | if instance_name in self.cfg.GetInstanceList(): |
6158 | 7baf741d | Guido Trotter | raise errors.OpPrereqError("Instance '%s' is already in the cluster" % |
6159 | 5c983ee5 | Iustin Pop | instance_name, errors.ECODE_EXISTS) |
6160 | 7baf741d | Guido Trotter | |
6161 | 7baf741d | Guido Trotter | self.add_locks[locking.LEVEL_INSTANCE] = instance_name
|
6162 | 7baf741d | Guido Trotter | |
6163 | 7baf741d | Guido Trotter | if self.op.iallocator: |
6164 | 7baf741d | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
6165 | 7baf741d | Guido Trotter | else:
|
6166 | cf26a87a | Iustin Pop | self.op.pnode = _ExpandNodeName(self.cfg, self.op.pnode) |
6167 | 7baf741d | Guido Trotter | nodelist = [self.op.pnode]
|
6168 | 7baf741d | Guido Trotter | if self.op.snode is not None: |
6169 | cf26a87a | Iustin Pop | self.op.snode = _ExpandNodeName(self.cfg, self.op.snode) |
6170 | 7baf741d | Guido Trotter | nodelist.append(self.op.snode)
|
6171 | 7baf741d | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = nodelist
|
6172 | 7baf741d | Guido Trotter | |
6173 | 7baf741d | Guido Trotter | # in case of import lock the source node too
|
6174 | 7baf741d | Guido Trotter | if self.op.mode == constants.INSTANCE_IMPORT: |
6175 | 7baf741d | Guido Trotter | src_node = getattr(self.op, "src_node", None) |
6176 | 7baf741d | Guido Trotter | src_path = getattr(self.op, "src_path", None) |
6177 | 7baf741d | Guido Trotter | |
6178 | b9322a9f | Guido Trotter | if src_path is None: |
6179 | b9322a9f | Guido Trotter | self.op.src_path = src_path = self.op.instance_name |
6180 | b9322a9f | Guido Trotter | |
6181 | b9322a9f | Guido Trotter | if src_node is None: |
6182 | b9322a9f | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
6183 | b9322a9f | Guido Trotter | self.op.src_node = None |
6184 | b9322a9f | Guido Trotter | if os.path.isabs(src_path):
|
6185 | b9322a9f | Guido Trotter | raise errors.OpPrereqError("Importing an instance from an absolute" |
6186 | 5c983ee5 | Iustin Pop | " path requires a source node option.",
|
6187 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
6188 | b9322a9f | Guido Trotter | else:
|
6189 | cf26a87a | Iustin Pop | self.op.src_node = src_node = _ExpandNodeName(self.cfg, src_node) |
6190 | b9322a9f | Guido Trotter | if self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET: |
6191 | b9322a9f | Guido Trotter | self.needed_locks[locking.LEVEL_NODE].append(src_node)
|
6192 | b9322a9f | Guido Trotter | if not os.path.isabs(src_path): |
6193 | b9322a9f | Guido Trotter | self.op.src_path = src_path = \
|
6194 | c4feafe8 | Iustin Pop | utils.PathJoin(constants.EXPORT_DIR, src_path) |
6195 | 7baf741d | Guido Trotter | |
6196 | 538475ca | Iustin Pop | def _RunAllocator(self): |
6197 | 538475ca | Iustin Pop | """Run the allocator based on input opcode.
|
6198 | 538475ca | Iustin Pop |
|
6199 | 538475ca | Iustin Pop | """
|
6200 | 08db7c5c | Iustin Pop | nics = [n.ToDict() for n in self.nics] |
6201 | 923ddac0 | Michael Hanselmann | ial = IAllocator(self.cfg, self.rpc, |
6202 | 29859cb7 | Iustin Pop | mode=constants.IALLOCATOR_MODE_ALLOC, |
6203 | d1c2dd75 | Iustin Pop | name=self.op.instance_name,
|
6204 | d1c2dd75 | Iustin Pop | disk_template=self.op.disk_template,
|
6205 | d1c2dd75 | Iustin Pop | tags=[], |
6206 | d1c2dd75 | Iustin Pop | os=self.op.os_type,
|
6207 | 338e51e8 | Iustin Pop | vcpus=self.be_full[constants.BE_VCPUS],
|
6208 | 338e51e8 | Iustin Pop | mem_size=self.be_full[constants.BE_MEMORY],
|
6209 | 08db7c5c | Iustin Pop | disks=self.disks,
|
6210 | d1c2dd75 | Iustin Pop | nics=nics, |
6211 | 8cc7e742 | Guido Trotter | hypervisor=self.op.hypervisor,
|
6212 | 29859cb7 | Iustin Pop | ) |
6213 | d1c2dd75 | Iustin Pop | |
6214 | d1c2dd75 | Iustin Pop | ial.Run(self.op.iallocator)
|
6215 | d1c2dd75 | Iustin Pop | |
6216 | d1c2dd75 | Iustin Pop | if not ial.success: |
6217 | 538475ca | Iustin Pop | raise errors.OpPrereqError("Can't compute nodes using" |
6218 | 5c983ee5 | Iustin Pop | " iallocator '%s': %s" %
|
6219 | 5c983ee5 | Iustin Pop | (self.op.iallocator, ial.info),
|
6220 | 5c983ee5 | Iustin Pop | errors.ECODE_NORES) |
6221 | 680f0a89 | Iustin Pop | if len(ial.result) != ial.required_nodes: |
6222 | 538475ca | Iustin Pop | raise errors.OpPrereqError("iallocator '%s' returned invalid number" |
6223 | 538475ca | Iustin Pop | " of nodes (%s), required %s" %
|
6224 | 680f0a89 | Iustin Pop | (self.op.iallocator, len(ial.result), |
6225 | 5c983ee5 | Iustin Pop | ial.required_nodes), errors.ECODE_FAULT) |
6226 | 680f0a89 | Iustin Pop | self.op.pnode = ial.result[0] |
6227 | 86d9d3bb | Iustin Pop | self.LogInfo("Selected nodes for instance %s via iallocator %s: %s", |
6228 | 86d9d3bb | Iustin Pop | self.op.instance_name, self.op.iallocator, |
6229 | 680f0a89 | Iustin Pop | utils.CommaJoin(ial.result)) |
6230 | 27579978 | Iustin Pop | if ial.required_nodes == 2: |
6231 | 680f0a89 | Iustin Pop | self.op.snode = ial.result[1] |
6232 | 538475ca | Iustin Pop | |
6233 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
6234 | a8083063 | Iustin Pop | """Build hooks env.
|
6235 | a8083063 | Iustin Pop |
|
6236 | a8083063 | Iustin Pop | This runs on master, primary and secondary nodes of the instance.
|
6237 | a8083063 | Iustin Pop |
|
6238 | a8083063 | Iustin Pop | """
|
6239 | a8083063 | Iustin Pop | env = { |
6240 | 2c2690c9 | Iustin Pop | "ADD_MODE": self.op.mode, |
6241 | a8083063 | Iustin Pop | } |
6242 | a8083063 | Iustin Pop | if self.op.mode == constants.INSTANCE_IMPORT: |
6243 | 2c2690c9 | Iustin Pop | env["SRC_NODE"] = self.op.src_node |
6244 | 2c2690c9 | Iustin Pop | env["SRC_PATH"] = self.op.src_path |
6245 | 2c2690c9 | Iustin Pop | env["SRC_IMAGES"] = self.src_images |
6246 | 396e1b78 | Michael Hanselmann | |
6247 | 2c2690c9 | Iustin Pop | env.update(_BuildInstanceHookEnv( |
6248 | 2c2690c9 | Iustin Pop | name=self.op.instance_name,
|
6249 | 396e1b78 | Michael Hanselmann | primary_node=self.op.pnode,
|
6250 | 396e1b78 | Michael Hanselmann | secondary_nodes=self.secondaries,
|
6251 | 4978db17 | Iustin Pop | status=self.op.start,
|
6252 | ecb215b5 | Michael Hanselmann | os_type=self.op.os_type,
|
6253 | 338e51e8 | Iustin Pop | memory=self.be_full[constants.BE_MEMORY],
|
6254 | 338e51e8 | Iustin Pop | vcpus=self.be_full[constants.BE_VCPUS],
|
6255 | f9b10246 | Guido Trotter | nics=_NICListToTuple(self, self.nics), |
6256 | 2c2690c9 | Iustin Pop | disk_template=self.op.disk_template,
|
6257 | 2c2690c9 | Iustin Pop | disks=[(d["size"], d["mode"]) for d in self.disks], |
6258 | 67fc3042 | Iustin Pop | bep=self.be_full,
|
6259 | 67fc3042 | Iustin Pop | hvp=self.hv_full,
|
6260 | 3df6e710 | Iustin Pop | hypervisor_name=self.op.hypervisor,
|
6261 | 396e1b78 | Michael Hanselmann | )) |
6262 | a8083063 | Iustin Pop | |
6263 | d6a02168 | Michael Hanselmann | nl = ([self.cfg.GetMasterNode(), self.op.pnode] + |
6264 | a8083063 | Iustin Pop | self.secondaries)
|
6265 | a8083063 | Iustin Pop | return env, nl, nl
|
6266 | a8083063 | Iustin Pop | |
6267 | c1c31426 | Iustin Pop | def _ReadExportInfo(self): |
6268 | c1c31426 | Iustin Pop | """Reads the export information from disk.
|
6269 | c1c31426 | Iustin Pop |
|
6270 | c1c31426 | Iustin Pop | It will override the opcode source node and path with the actual
|
6271 | c1c31426 | Iustin Pop | information, if these two were not specified before.
|
6272 | c1c31426 | Iustin Pop |
|
6273 | c1c31426 | Iustin Pop | @return: the export information
|
6274 | c1c31426 | Iustin Pop |
|
6275 | c1c31426 | Iustin Pop | """
|
6276 | c1c31426 | Iustin Pop | assert self.op.mode == constants.INSTANCE_IMPORT |
6277 | c1c31426 | Iustin Pop | |
6278 | c1c31426 | Iustin Pop | src_node = self.op.src_node
|
6279 | c1c31426 | Iustin Pop | src_path = self.op.src_path
|
6280 | c1c31426 | Iustin Pop | |
6281 | c1c31426 | Iustin Pop | if src_node is None: |
6282 | c1c31426 | Iustin Pop | locked_nodes = self.acquired_locks[locking.LEVEL_NODE]
|
6283 | c1c31426 | Iustin Pop | exp_list = self.rpc.call_export_list(locked_nodes)
|
6284 | c1c31426 | Iustin Pop | found = False
|
6285 | c1c31426 | Iustin Pop | for node in exp_list: |
6286 | c1c31426 | Iustin Pop | if exp_list[node].fail_msg:
|
6287 | c1c31426 | Iustin Pop | continue
|
6288 | c1c31426 | Iustin Pop | if src_path in exp_list[node].payload: |
6289 | c1c31426 | Iustin Pop | found = True
|
6290 | c1c31426 | Iustin Pop | self.op.src_node = src_node = node
|
6291 | c1c31426 | Iustin Pop | self.op.src_path = src_path = utils.PathJoin(constants.EXPORT_DIR,
|
6292 | c1c31426 | Iustin Pop | src_path) |
6293 | c1c31426 | Iustin Pop | break
|
6294 | c1c31426 | Iustin Pop | if not found: |
6295 | c1c31426 | Iustin Pop | raise errors.OpPrereqError("No export found for relative path %s" % |
6296 | c1c31426 | Iustin Pop | src_path, errors.ECODE_INVAL) |
6297 | c1c31426 | Iustin Pop | |
6298 | c1c31426 | Iustin Pop | _CheckNodeOnline(self, src_node)
|
6299 | c1c31426 | Iustin Pop | result = self.rpc.call_export_info(src_node, src_path)
|
6300 | c1c31426 | Iustin Pop | result.Raise("No export or invalid export found in dir %s" % src_path)
|
6301 | c1c31426 | Iustin Pop | |
6302 | c1c31426 | Iustin Pop | export_info = objects.SerializableConfigParser.Loads(str(result.payload))
|
6303 | c1c31426 | Iustin Pop | if not export_info.has_section(constants.INISECT_EXP): |
6304 | c1c31426 | Iustin Pop | raise errors.ProgrammerError("Corrupted export config", |
6305 | c1c31426 | Iustin Pop | errors.ECODE_ENVIRON) |
6306 | c1c31426 | Iustin Pop | |
6307 | c1c31426 | Iustin Pop | ei_version = export_info.get(constants.INISECT_EXP, "version")
|
6308 | c1c31426 | Iustin Pop | if (int(ei_version) != constants.EXPORT_VERSION): |
6309 | c1c31426 | Iustin Pop | raise errors.OpPrereqError("Wrong export version %s (wanted %d)" % |
6310 | c1c31426 | Iustin Pop | (ei_version, constants.EXPORT_VERSION), |
6311 | c1c31426 | Iustin Pop | errors.ECODE_ENVIRON) |
6312 | c1c31426 | Iustin Pop | return export_info
|
6313 | a8083063 | Iustin Pop | |
6314 | f276c4b5 | Iustin Pop | def _ReadExportParams(self, einfo): |
6315 | f276c4b5 | Iustin Pop | """Use export parameters as defaults.
|
6316 | f276c4b5 | Iustin Pop |
|
6317 | f276c4b5 | Iustin Pop | In case the opcode doesn't specify (as in override) some instance
|
6318 | f276c4b5 | Iustin Pop | parameters, then try to use them from the export information, if
|
6319 | f276c4b5 | Iustin Pop | that declares them.
|
6320 | f276c4b5 | Iustin Pop |
|
6321 | f276c4b5 | Iustin Pop | """
|
6322 | b6cd72b2 | Iustin Pop | self.op.os_type = einfo.get(constants.INISECT_EXP, "os") |
6323 | b6cd72b2 | Iustin Pop | |
6324 | f276c4b5 | Iustin Pop | if self.op.disk_template is None: |
6325 | f276c4b5 | Iustin Pop | if einfo.has_option(constants.INISECT_INS, "disk_template"): |
6326 | f276c4b5 | Iustin Pop | self.op.disk_template = einfo.get(constants.INISECT_INS,
|
6327 | f276c4b5 | Iustin Pop | "disk_template")
|
6328 | f276c4b5 | Iustin Pop | else:
|
6329 | f276c4b5 | Iustin Pop | raise errors.OpPrereqError("No disk template specified and the export" |
6330 | f276c4b5 | Iustin Pop | " is missing the disk_template information",
|
6331 | f276c4b5 | Iustin Pop | errors.ECODE_INVAL) |
6332 | f276c4b5 | Iustin Pop | |
6333 | 9b12ed0f | Iustin Pop | if not self.op.disks: |
6334 | 9b12ed0f | Iustin Pop | if einfo.has_option(constants.INISECT_INS, "disk_count"): |
6335 | 9b12ed0f | Iustin Pop | disks = [] |
6336 | 9b12ed0f | Iustin Pop | # TODO: import the disk iv_name too
|
6337 | 9b12ed0f | Iustin Pop | for idx in range(einfo.getint(constants.INISECT_INS, "disk_count")): |
6338 | 9b12ed0f | Iustin Pop | disk_sz = einfo.getint(constants.INISECT_INS, "disk%d_size" % idx)
|
6339 | 9b12ed0f | Iustin Pop | disks.append({"size": disk_sz})
|
6340 | 9b12ed0f | Iustin Pop | self.op.disks = disks
|
6341 | 9b12ed0f | Iustin Pop | else:
|
6342 | 9b12ed0f | Iustin Pop | raise errors.OpPrereqError("No disk info specified and the export" |
6343 | 9b12ed0f | Iustin Pop | " is missing the disk information",
|
6344 | 9b12ed0f | Iustin Pop | errors.ECODE_INVAL) |
6345 | 9b12ed0f | Iustin Pop | |
6346 | 0af0f641 | Iustin Pop | if (not self.op.nics and |
6347 | 0af0f641 | Iustin Pop | einfo.has_option(constants.INISECT_INS, "nic_count")):
|
6348 | 0af0f641 | Iustin Pop | nics = [] |
6349 | 0af0f641 | Iustin Pop | for idx in range(einfo.getint(constants.INISECT_INS, "nic_count")): |
6350 | 0af0f641 | Iustin Pop | ndict = {} |
6351 | 0af0f641 | Iustin Pop | for name in list(constants.NICS_PARAMETERS) + ["ip", "mac"]: |
6352 | 0af0f641 | Iustin Pop | v = einfo.get(constants.INISECT_INS, "nic%d_%s" % (idx, name))
|
6353 | 0af0f641 | Iustin Pop | ndict[name] = v |
6354 | 0af0f641 | Iustin Pop | nics.append(ndict) |
6355 | 0af0f641 | Iustin Pop | self.op.nics = nics
|
6356 | 0af0f641 | Iustin Pop | |
6357 | 9f88b0e8 | Iustin Pop | if (self.op.hypervisor is None and |
6358 | 9f88b0e8 | Iustin Pop | einfo.has_option(constants.INISECT_INS, "hypervisor")):
|
6359 | 9f88b0e8 | Iustin Pop | self.op.hypervisor = einfo.get(constants.INISECT_INS, "hypervisor") |
6360 | 9f88b0e8 | Iustin Pop | if einfo.has_section(constants.INISECT_HYP):
|
6361 | 9f88b0e8 | Iustin Pop | # use the export parameters but do not override the ones
|
6362 | 9f88b0e8 | Iustin Pop | # specified by the user
|
6363 | 9f88b0e8 | Iustin Pop | for name, value in einfo.items(constants.INISECT_HYP): |
6364 | 9f88b0e8 | Iustin Pop | if name not in self.op.hvparams: |
6365 | 9f88b0e8 | Iustin Pop | self.op.hvparams[name] = value
|
6366 | 9f88b0e8 | Iustin Pop | |
6367 | cc0d88e9 | Iustin Pop | if einfo.has_section(constants.INISECT_BEP):
|
6368 | cc0d88e9 | Iustin Pop | # use the parameters, without overriding
|
6369 | cc0d88e9 | Iustin Pop | for name, value in einfo.items(constants.INISECT_BEP): |
6370 | cc0d88e9 | Iustin Pop | if name not in self.op.beparams: |
6371 | cc0d88e9 | Iustin Pop | self.op.beparams[name] = value
|
6372 | cc0d88e9 | Iustin Pop | else:
|
6373 | cc0d88e9 | Iustin Pop | # try to read the parameters old style, from the main section
|
6374 | cc0d88e9 | Iustin Pop | for name in constants.BES_PARAMETERS: |
6375 | cc0d88e9 | Iustin Pop | if (name not in self.op.beparams and |
6376 | cc0d88e9 | Iustin Pop | einfo.has_option(constants.INISECT_INS, name)): |
6377 | cc0d88e9 | Iustin Pop | self.op.beparams[name] = einfo.get(constants.INISECT_INS, name)
|
6378 | cc0d88e9 | Iustin Pop | |
6379 | e588764d | Iustin Pop | def _RevertToDefaults(self, cluster): |
6380 | e588764d | Iustin Pop | """Revert the instance parameters to the default values.
|
6381 | e588764d | Iustin Pop |
|
6382 | e588764d | Iustin Pop | """
|
6383 | e588764d | Iustin Pop | # hvparams
|
6384 | e588764d | Iustin Pop | hv_defs = cluster.GetHVDefaults(self.op.hypervisor, self.op.os_type) |
6385 | e588764d | Iustin Pop | for name in self.op.hvparams.keys(): |
6386 | e588764d | Iustin Pop | if name in hv_defs and hv_defs[name] == self.op.hvparams[name]: |
6387 | e588764d | Iustin Pop | del self.op.hvparams[name] |
6388 | e588764d | Iustin Pop | # beparams
|
6389 | e588764d | Iustin Pop | be_defs = cluster.beparams.get(constants.PP_DEFAULT, {}) |
6390 | e588764d | Iustin Pop | for name in self.op.beparams.keys(): |
6391 | e588764d | Iustin Pop | if name in be_defs and be_defs[name] == self.op.beparams[name]: |
6392 | e588764d | Iustin Pop | del self.op.beparams[name] |
6393 | e588764d | Iustin Pop | # nic params
|
6394 | e588764d | Iustin Pop | nic_defs = cluster.nicparams.get(constants.PP_DEFAULT, {}) |
6395 | e588764d | Iustin Pop | for nic in self.op.nics: |
6396 | e588764d | Iustin Pop | for name in constants.NICS_PARAMETERS: |
6397 | e588764d | Iustin Pop | if name in nic and name in nic_defs and nic[name] == nic_defs[name]: |
6398 | e588764d | Iustin Pop | del nic[name]
|
6399 | e588764d | Iustin Pop | |
6400 | a8083063 | Iustin Pop | def CheckPrereq(self): |
6401 | a8083063 | Iustin Pop | """Check prerequisites.
|
6402 | a8083063 | Iustin Pop |
|
6403 | a8083063 | Iustin Pop | """
|
6404 | c1c31426 | Iustin Pop | if self.op.mode == constants.INSTANCE_IMPORT: |
6405 | c1c31426 | Iustin Pop | export_info = self._ReadExportInfo()
|
6406 | f276c4b5 | Iustin Pop | self._ReadExportParams(export_info)
|
6407 | f276c4b5 | Iustin Pop | |
6408 | f276c4b5 | Iustin Pop | _CheckDiskTemplate(self.op.disk_template)
|
6409 | c1c31426 | Iustin Pop | |
6410 | eedc99de | Manuel Franceschini | if (not self.cfg.GetVGName() and |
6411 | eedc99de | Manuel Franceschini | self.op.disk_template not in constants.DTS_NOT_LVM): |
6412 | eedc99de | Manuel Franceschini | raise errors.OpPrereqError("Cluster does not support lvm-based" |
6413 | 5c983ee5 | Iustin Pop | " instances", errors.ECODE_STATE)
|
6414 | eedc99de | Manuel Franceschini | |
6415 | 22f50b1d | Iustin Pop | if self.op.hypervisor is None: |
6416 | 22f50b1d | Iustin Pop | self.op.hypervisor = self.cfg.GetHypervisorType() |
6417 | 22f50b1d | Iustin Pop | |
6418 | 22f50b1d | Iustin Pop | cluster = self.cfg.GetClusterInfo()
|
6419 | 22f50b1d | Iustin Pop | enabled_hvs = cluster.enabled_hypervisors |
6420 | 22f50b1d | Iustin Pop | if self.op.hypervisor not in enabled_hvs: |
6421 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Selected hypervisor (%s) not enabled in the" |
6422 | 22f50b1d | Iustin Pop | " cluster (%s)" % (self.op.hypervisor, |
6423 | 22f50b1d | Iustin Pop | ",".join(enabled_hvs)),
|
6424 | 22f50b1d | Iustin Pop | errors.ECODE_STATE) |
6425 | 22f50b1d | Iustin Pop | |
6426 | 22f50b1d | Iustin Pop | # check hypervisor parameter syntax (locally)
|
6427 | 22f50b1d | Iustin Pop | utils.ForceDictType(self.op.hvparams, constants.HVS_PARAMETER_TYPES)
|
6428 | b6cd72b2 | Iustin Pop | filled_hvp = objects.FillDict(cluster.GetHVDefaults(self.op.hypervisor,
|
6429 | b6cd72b2 | Iustin Pop | self.op.os_type),
|
6430 | 22f50b1d | Iustin Pop | self.op.hvparams)
|
6431 | 22f50b1d | Iustin Pop | hv_type = hypervisor.GetHypervisor(self.op.hypervisor)
|
6432 | 22f50b1d | Iustin Pop | hv_type.CheckParameterSyntax(filled_hvp) |
6433 | 22f50b1d | Iustin Pop | self.hv_full = filled_hvp
|
6434 | 22f50b1d | Iustin Pop | # check that we don't specify global parameters on an instance
|
6435 | 22f50b1d | Iustin Pop | _CheckGlobalHvParams(self.op.hvparams)
|
6436 | 22f50b1d | Iustin Pop | |
6437 | 22f50b1d | Iustin Pop | # fill and remember the beparams dict
|
6438 | 22f50b1d | Iustin Pop | utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
|
6439 | 22f50b1d | Iustin Pop | self.be_full = objects.FillDict(cluster.beparams[constants.PP_DEFAULT],
|
6440 | 22f50b1d | Iustin Pop | self.op.beparams)
|
6441 | 22f50b1d | Iustin Pop | |
6442 | e588764d | Iustin Pop | # now that hvp/bep are in final format, let's reset to defaults,
|
6443 | e588764d | Iustin Pop | # if told to do so
|
6444 | e588764d | Iustin Pop | if self.op.identify_defaults: |
6445 | e588764d | Iustin Pop | self._RevertToDefaults(cluster)
|
6446 | e588764d | Iustin Pop | |
6447 | 22f50b1d | Iustin Pop | # NIC buildup
|
6448 | 22f50b1d | Iustin Pop | self.nics = []
|
6449 | 22f50b1d | Iustin Pop | for idx, nic in enumerate(self.op.nics): |
6450 | 22f50b1d | Iustin Pop | nic_mode_req = nic.get("mode", None) |
6451 | 22f50b1d | Iustin Pop | nic_mode = nic_mode_req |
6452 | 22f50b1d | Iustin Pop | if nic_mode is None: |
6453 | 22f50b1d | Iustin Pop | nic_mode = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_MODE] |
6454 | 22f50b1d | Iustin Pop | |
6455 | 22f50b1d | Iustin Pop | # in routed mode, for the first nic, the default ip is 'auto'
|
6456 | 22f50b1d | Iustin Pop | if nic_mode == constants.NIC_MODE_ROUTED and idx == 0: |
6457 | 22f50b1d | Iustin Pop | default_ip_mode = constants.VALUE_AUTO |
6458 | 22f50b1d | Iustin Pop | else:
|
6459 | 22f50b1d | Iustin Pop | default_ip_mode = constants.VALUE_NONE |
6460 | 22f50b1d | Iustin Pop | |
6461 | 22f50b1d | Iustin Pop | # ip validity checks
|
6462 | 22f50b1d | Iustin Pop | ip = nic.get("ip", default_ip_mode)
|
6463 | 22f50b1d | Iustin Pop | if ip is None or ip.lower() == constants.VALUE_NONE: |
6464 | 22f50b1d | Iustin Pop | nic_ip = None
|
6465 | 22f50b1d | Iustin Pop | elif ip.lower() == constants.VALUE_AUTO:
|
6466 | 22f50b1d | Iustin Pop | if not self.op.name_check: |
6467 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("IP address set to auto but name checks" |
6468 | 22f50b1d | Iustin Pop | " have been skipped. Aborting.",
|
6469 | 22f50b1d | Iustin Pop | errors.ECODE_INVAL) |
6470 | 22f50b1d | Iustin Pop | nic_ip = self.hostname1.ip
|
6471 | 22f50b1d | Iustin Pop | else:
|
6472 | 22f50b1d | Iustin Pop | if not utils.IsValidIP(ip): |
6473 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Given IP address '%s' doesn't look" |
6474 | 22f50b1d | Iustin Pop | " like a valid IP" % ip,
|
6475 | 22f50b1d | Iustin Pop | errors.ECODE_INVAL) |
6476 | 22f50b1d | Iustin Pop | nic_ip = ip |
6477 | 22f50b1d | Iustin Pop | |
6478 | 22f50b1d | Iustin Pop | # TODO: check the ip address for uniqueness
|
6479 | 22f50b1d | Iustin Pop | if nic_mode == constants.NIC_MODE_ROUTED and not nic_ip: |
6480 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Routed nic mode requires an ip address", |
6481 | 22f50b1d | Iustin Pop | errors.ECODE_INVAL) |
6482 | 22f50b1d | Iustin Pop | |
6483 | 22f50b1d | Iustin Pop | # MAC address verification
|
6484 | 22f50b1d | Iustin Pop | mac = nic.get("mac", constants.VALUE_AUTO)
|
6485 | 22f50b1d | Iustin Pop | if mac not in (constants.VALUE_AUTO, constants.VALUE_GENERATE): |
6486 | 22f50b1d | Iustin Pop | mac = utils.NormalizeAndValidateMac(mac) |
6487 | 22f50b1d | Iustin Pop | |
6488 | 22f50b1d | Iustin Pop | try:
|
6489 | 22f50b1d | Iustin Pop | self.cfg.ReserveMAC(mac, self.proc.GetECId()) |
6490 | 22f50b1d | Iustin Pop | except errors.ReservationError:
|
6491 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("MAC address %s already in use" |
6492 | 22f50b1d | Iustin Pop | " in cluster" % mac,
|
6493 | 22f50b1d | Iustin Pop | errors.ECODE_NOTUNIQUE) |
6494 | 22f50b1d | Iustin Pop | |
6495 | 22f50b1d | Iustin Pop | # bridge verification
|
6496 | 22f50b1d | Iustin Pop | bridge = nic.get("bridge", None) |
6497 | 22f50b1d | Iustin Pop | link = nic.get("link", None) |
6498 | 22f50b1d | Iustin Pop | if bridge and link: |
6499 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'" |
6500 | 22f50b1d | Iustin Pop | " at the same time", errors.ECODE_INVAL)
|
6501 | 22f50b1d | Iustin Pop | elif bridge and nic_mode == constants.NIC_MODE_ROUTED: |
6502 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic", |
6503 | 22f50b1d | Iustin Pop | errors.ECODE_INVAL) |
6504 | 22f50b1d | Iustin Pop | elif bridge:
|
6505 | 22f50b1d | Iustin Pop | link = bridge |
6506 | 22f50b1d | Iustin Pop | |
6507 | 22f50b1d | Iustin Pop | nicparams = {} |
6508 | 22f50b1d | Iustin Pop | if nic_mode_req:
|
6509 | 22f50b1d | Iustin Pop | nicparams[constants.NIC_MODE] = nic_mode_req |
6510 | 22f50b1d | Iustin Pop | if link:
|
6511 | 22f50b1d | Iustin Pop | nicparams[constants.NIC_LINK] = link |
6512 | 22f50b1d | Iustin Pop | |
6513 | 22f50b1d | Iustin Pop | check_params = objects.FillDict(cluster.nicparams[constants.PP_DEFAULT], |
6514 | 22f50b1d | Iustin Pop | nicparams) |
6515 | 22f50b1d | Iustin Pop | objects.NIC.CheckParameterSyntax(check_params) |
6516 | 22f50b1d | Iustin Pop | self.nics.append(objects.NIC(mac=mac, ip=nic_ip, nicparams=nicparams))
|
6517 | 22f50b1d | Iustin Pop | |
6518 | 22f50b1d | Iustin Pop | # disk checks/pre-build
|
6519 | 22f50b1d | Iustin Pop | self.disks = []
|
6520 | 22f50b1d | Iustin Pop | for disk in self.op.disks: |
6521 | 22f50b1d | Iustin Pop | mode = disk.get("mode", constants.DISK_RDWR)
|
6522 | 22f50b1d | Iustin Pop | if mode not in constants.DISK_ACCESS_SET: |
6523 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Invalid disk access mode '%s'" % |
6524 | 22f50b1d | Iustin Pop | mode, errors.ECODE_INVAL) |
6525 | 22f50b1d | Iustin Pop | size = disk.get("size", None) |
6526 | 22f50b1d | Iustin Pop | if size is None: |
6527 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Missing disk size", errors.ECODE_INVAL) |
6528 | 22f50b1d | Iustin Pop | try:
|
6529 | 22f50b1d | Iustin Pop | size = int(size)
|
6530 | 22f50b1d | Iustin Pop | except (TypeError, ValueError): |
6531 | 22f50b1d | Iustin Pop | raise errors.OpPrereqError("Invalid disk size '%s'" % size, |
6532 | 22f50b1d | Iustin Pop | errors.ECODE_INVAL) |
6533 | 22f50b1d | Iustin Pop | new_disk = {"size": size, "mode": mode} |
6534 | 22f50b1d | Iustin Pop | if "adopt" in disk: |
6535 | 22f50b1d | Iustin Pop | new_disk["adopt"] = disk["adopt"] |
6536 | 22f50b1d | Iustin Pop | self.disks.append(new_disk)
|
6537 | 22f50b1d | Iustin Pop | |
6538 | a8083063 | Iustin Pop | if self.op.mode == constants.INSTANCE_IMPORT: |
6539 | a8083063 | Iustin Pop | |
6540 | 09acf207 | Guido Trotter | # Check that the new instance doesn't have less disks than the export
|
6541 | 08db7c5c | Iustin Pop | instance_disks = len(self.disks) |
6542 | 09acf207 | Guido Trotter | export_disks = export_info.getint(constants.INISECT_INS, 'disk_count')
|
6543 | 09acf207 | Guido Trotter | if instance_disks < export_disks:
|
6544 | 09acf207 | Guido Trotter | raise errors.OpPrereqError("Not enough disks to import." |
6545 | 09acf207 | Guido Trotter | " (instance: %d, export: %d)" %
|
6546 | 5c983ee5 | Iustin Pop | (instance_disks, export_disks), |
6547 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
6548 | a8083063 | Iustin Pop | |
6549 | 09acf207 | Guido Trotter | disk_images = [] |
6550 | 09acf207 | Guido Trotter | for idx in range(export_disks): |
6551 | 09acf207 | Guido Trotter | option = 'disk%d_dump' % idx
|
6552 | 09acf207 | Guido Trotter | if export_info.has_option(constants.INISECT_INS, option):
|
6553 | 09acf207 | Guido Trotter | # FIXME: are the old os-es, disk sizes, etc. useful?
|
6554 | 09acf207 | Guido Trotter | export_name = export_info.get(constants.INISECT_INS, option) |
6555 | c1c31426 | Iustin Pop | image = utils.PathJoin(self.op.src_path, export_name)
|
6556 | 09acf207 | Guido Trotter | disk_images.append(image) |
6557 | 09acf207 | Guido Trotter | else:
|
6558 | 09acf207 | Guido Trotter | disk_images.append(False)
|
6559 | 09acf207 | Guido Trotter | |
6560 | 09acf207 | Guido Trotter | self.src_images = disk_images
|
6561 | 901a65c1 | Iustin Pop | |
6562 | b4364a6b | Guido Trotter | old_name = export_info.get(constants.INISECT_INS, 'name')
|
6563 | 2a518543 | Iustin Pop | try:
|
6564 | 2a518543 | Iustin Pop | exp_nic_count = export_info.getint(constants.INISECT_INS, 'nic_count')
|
6565 | 2a518543 | Iustin Pop | except (TypeError, ValueError), err: |
6566 | 2a518543 | Iustin Pop | raise errors.OpPrereqError("Invalid export file, nic_count is not" |
6567 | 2a518543 | Iustin Pop | " an integer: %s" % str(err), |
6568 | 2a518543 | Iustin Pop | errors.ECODE_STATE) |
6569 | b4364a6b | Guido Trotter | if self.op.instance_name == old_name: |
6570 | b4364a6b | Guido Trotter | for idx, nic in enumerate(self.nics): |
6571 | b4364a6b | Guido Trotter | if nic.mac == constants.VALUE_AUTO and exp_nic_count >= idx: |
6572 | b4364a6b | Guido Trotter | nic_mac_ini = 'nic%d_mac' % idx
|
6573 | b4364a6b | Guido Trotter | nic.mac = export_info.get(constants.INISECT_INS, nic_mac_ini) |
6574 | bc89efc3 | Guido Trotter | |
6575 | 295728df | Guido Trotter | # ENDIF: self.op.mode == constants.INSTANCE_IMPORT
|
6576 | 901a65c1 | Iustin Pop | |
6577 | 18c8f361 | Iustin Pop | # ip ping checks (we use the same ip that was resolved in ExpandNames)
|
6578 | 901a65c1 | Iustin Pop | if self.op.ip_check: |
6579 | 7baf741d | Guido Trotter | if utils.TcpPing(self.check_ip, constants.DEFAULT_NODED_PORT): |
6580 | 901a65c1 | Iustin Pop | raise errors.OpPrereqError("IP %s of instance %s already in use" % |
6581 | 5c983ee5 | Iustin Pop | (self.check_ip, self.op.instance_name), |
6582 | 5c983ee5 | Iustin Pop | errors.ECODE_NOTUNIQUE) |
6583 | 901a65c1 | Iustin Pop | |
6584 | 295728df | Guido Trotter | #### mac address generation
|
6585 | 295728df | Guido Trotter | # By generating here the mac address both the allocator and the hooks get
|
6586 | 295728df | Guido Trotter | # the real final mac address rather than the 'auto' or 'generate' value.
|
6587 | 295728df | Guido Trotter | # There is a race condition between the generation and the instance object
|
6588 | 295728df | Guido Trotter | # creation, which means that we know the mac is valid now, but we're not
|
6589 | 295728df | Guido Trotter | # sure it will be when we actually add the instance. If things go bad
|
6590 | 295728df | Guido Trotter | # adding the instance will abort because of a duplicate mac, and the
|
6591 | 295728df | Guido Trotter | # creation job will fail.
|
6592 | 295728df | Guido Trotter | for nic in self.nics: |
6593 | 295728df | Guido Trotter | if nic.mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE): |
6594 | 36b66e6e | Guido Trotter | nic.mac = self.cfg.GenerateMAC(self.proc.GetECId()) |
6595 | 295728df | Guido Trotter | |
6596 | 538475ca | Iustin Pop | #### allocator run
|
6597 | 538475ca | Iustin Pop | |
6598 | 538475ca | Iustin Pop | if self.op.iallocator is not None: |
6599 | 538475ca | Iustin Pop | self._RunAllocator()
|
6600 | 0f1a06e3 | Manuel Franceschini | |
6601 | 901a65c1 | Iustin Pop | #### node related checks
|
6602 | 901a65c1 | Iustin Pop | |
6603 | 901a65c1 | Iustin Pop | # check primary node
|
6604 | 7baf741d | Guido Trotter | self.pnode = pnode = self.cfg.GetNodeInfo(self.op.pnode) |
6605 | 7baf741d | Guido Trotter | assert self.pnode is not None, \ |
6606 | 7baf741d | Guido Trotter | "Cannot retrieve locked node %s" % self.op.pnode |
6607 | 7527a8a4 | Iustin Pop | if pnode.offline:
|
6608 | 7527a8a4 | Iustin Pop | raise errors.OpPrereqError("Cannot use offline primary node '%s'" % |
6609 | 5c983ee5 | Iustin Pop | pnode.name, errors.ECODE_STATE) |
6610 | 733a2b6a | Iustin Pop | if pnode.drained:
|
6611 | 733a2b6a | Iustin Pop | raise errors.OpPrereqError("Cannot use drained primary node '%s'" % |
6612 | 5c983ee5 | Iustin Pop | pnode.name, errors.ECODE_STATE) |
6613 | 7527a8a4 | Iustin Pop | |
6614 | 901a65c1 | Iustin Pop | self.secondaries = []
|
6615 | 901a65c1 | Iustin Pop | |
6616 | 901a65c1 | Iustin Pop | # mirror node verification
|
6617 | a1f445d3 | Iustin Pop | if self.op.disk_template in constants.DTS_NET_MIRROR: |
6618 | 7baf741d | Guido Trotter | if self.op.snode is None: |
6619 | a1f445d3 | Iustin Pop | raise errors.OpPrereqError("The networked disk templates need" |
6620 | 5c983ee5 | Iustin Pop | " a mirror node", errors.ECODE_INVAL)
|
6621 | 7baf741d | Guido Trotter | if self.op.snode == pnode.name: |
6622 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("The secondary node cannot be the" |
6623 | 5c983ee5 | Iustin Pop | " primary node.", errors.ECODE_INVAL)
|
6624 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, self.op.snode) |
6625 | 733a2b6a | Iustin Pop | _CheckNodeNotDrained(self, self.op.snode) |
6626 | 733a2b6a | Iustin Pop | self.secondaries.append(self.op.snode) |
6627 | a8083063 | Iustin Pop | |
6628 | 6785674e | Iustin Pop | nodenames = [pnode.name] + self.secondaries
|
6629 | 6785674e | Iustin Pop | |
6630 | e2fe6369 | Iustin Pop | req_size = _ComputeDiskSize(self.op.disk_template,
|
6631 | 08db7c5c | Iustin Pop | self.disks)
|
6632 | ed1ebc60 | Guido Trotter | |
6633 | c3589cf8 | Iustin Pop | # Check lv size requirements, if not adopting
|
6634 | c3589cf8 | Iustin Pop | if req_size is not None and not self.adopt_disks: |
6635 | 701384a9 | Iustin Pop | _CheckNodesFreeDisk(self, nodenames, req_size)
|
6636 | ed1ebc60 | Guido Trotter | |
6637 | c3589cf8 | Iustin Pop | if self.adopt_disks: # instead, we must check the adoption data |
6638 | c3589cf8 | Iustin Pop | all_lvs = set([i["adopt"] for i in self.disks]) |
6639 | c3589cf8 | Iustin Pop | if len(all_lvs) != len(self.disks): |
6640 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("Duplicate volume names given for adoption", |
6641 | c3589cf8 | Iustin Pop | errors.ECODE_INVAL) |
6642 | c3589cf8 | Iustin Pop | for lv_name in all_lvs: |
6643 | c3589cf8 | Iustin Pop | try:
|
6644 | c3589cf8 | Iustin Pop | self.cfg.ReserveLV(lv_name, self.proc.GetECId()) |
6645 | c3589cf8 | Iustin Pop | except errors.ReservationError:
|
6646 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("LV named %s used by another instance" % |
6647 | c3589cf8 | Iustin Pop | lv_name, errors.ECODE_NOTUNIQUE) |
6648 | c3589cf8 | Iustin Pop | |
6649 | c3589cf8 | Iustin Pop | node_lvs = self.rpc.call_lv_list([pnode.name],
|
6650 | c3589cf8 | Iustin Pop | self.cfg.GetVGName())[pnode.name]
|
6651 | c3589cf8 | Iustin Pop | node_lvs.Raise("Cannot get LV information from node %s" % pnode.name)
|
6652 | c3589cf8 | Iustin Pop | node_lvs = node_lvs.payload |
6653 | c3589cf8 | Iustin Pop | delta = all_lvs.difference(node_lvs.keys()) |
6654 | c3589cf8 | Iustin Pop | if delta:
|
6655 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("Missing logical volume(s): %s" % |
6656 | c3589cf8 | Iustin Pop | utils.CommaJoin(delta), |
6657 | c3589cf8 | Iustin Pop | errors.ECODE_INVAL) |
6658 | c3589cf8 | Iustin Pop | online_lvs = [lv for lv in all_lvs if node_lvs[lv][2]] |
6659 | c3589cf8 | Iustin Pop | if online_lvs:
|
6660 | c3589cf8 | Iustin Pop | raise errors.OpPrereqError("Online logical volumes found, cannot" |
6661 | c3589cf8 | Iustin Pop | " adopt: %s" % utils.CommaJoin(online_lvs),
|
6662 | c3589cf8 | Iustin Pop | errors.ECODE_STATE) |
6663 | c3589cf8 | Iustin Pop | # update the size of disk based on what is found
|
6664 | c3589cf8 | Iustin Pop | for dsk in self.disks: |
6665 | c3589cf8 | Iustin Pop | dsk["size"] = int(float(node_lvs[dsk["adopt"]][0])) |
6666 | c3589cf8 | Iustin Pop | |
6667 | 74409b12 | Iustin Pop | _CheckHVParams(self, nodenames, self.op.hypervisor, self.op.hvparams) |
6668 | 6785674e | Iustin Pop | |
6669 | 231cd901 | Iustin Pop | _CheckNodeHasOS(self, pnode.name, self.op.os_type, self.op.force_variant) |
6670 | a8083063 | Iustin Pop | |
6671 | b165e77e | Guido Trotter | _CheckNicsBridgesExist(self, self.nics, self.pnode.name) |
6672 | a8083063 | Iustin Pop | |
6673 | 49ce1563 | Iustin Pop | # memory check on primary node
|
6674 | 49ce1563 | Iustin Pop | if self.op.start: |
6675 | b9bddb6b | Iustin Pop | _CheckNodeFreeMemory(self, self.pnode.name, |
6676 | 49ce1563 | Iustin Pop | "creating instance %s" % self.op.instance_name, |
6677 | 338e51e8 | Iustin Pop | self.be_full[constants.BE_MEMORY],
|
6678 | 338e51e8 | Iustin Pop | self.op.hypervisor)
|
6679 | 49ce1563 | Iustin Pop | |
6680 | 08896026 | Iustin Pop | self.dry_run_result = list(nodenames) |
6681 | 08896026 | Iustin Pop | |
6682 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
6683 | a8083063 | Iustin Pop | """Create and add the instance to the cluster.
|
6684 | a8083063 | Iustin Pop |
|
6685 | a8083063 | Iustin Pop | """
|
6686 | a8083063 | Iustin Pop | instance = self.op.instance_name
|
6687 | a8083063 | Iustin Pop | pnode_name = self.pnode.name
|
6688 | a8083063 | Iustin Pop | |
6689 | e69d05fd | Iustin Pop | ht_kind = self.op.hypervisor
|
6690 | 2a6469d5 | Alexander Schreiber | if ht_kind in constants.HTS_REQ_PORT: |
6691 | 2a6469d5 | Alexander Schreiber | network_port = self.cfg.AllocatePort()
|
6692 | 2a6469d5 | Alexander Schreiber | else:
|
6693 | 2a6469d5 | Alexander Schreiber | network_port = None
|
6694 | 58acb49d | Alexander Schreiber | |
6695 | 0e3baaf3 | Iustin Pop | if constants.ENABLE_FILE_STORAGE:
|
6696 | 0e3baaf3 | Iustin Pop | # this is needed because os.path.join does not accept None arguments
|
6697 | 0e3baaf3 | Iustin Pop | if self.op.file_storage_dir is None: |
6698 | 0e3baaf3 | Iustin Pop | string_file_storage_dir = ""
|
6699 | 0e3baaf3 | Iustin Pop | else:
|
6700 | 0e3baaf3 | Iustin Pop | string_file_storage_dir = self.op.file_storage_dir
|
6701 | 31a853d2 | Iustin Pop | |
6702 | 0e3baaf3 | Iustin Pop | # build the full file storage dir path
|
6703 | 0e3baaf3 | Iustin Pop | file_storage_dir = utils.PathJoin(self.cfg.GetFileStorageDir(),
|
6704 | 0e3baaf3 | Iustin Pop | string_file_storage_dir, instance) |
6705 | 2c313123 | Manuel Franceschini | else:
|
6706 | 0e3baaf3 | Iustin Pop | file_storage_dir = ""
|
6707 | 0f1a06e3 | Manuel Franceschini | |
6708 | 0f1a06e3 | Manuel Franceschini | |
6709 | b9bddb6b | Iustin Pop | disks = _GenerateDiskTemplate(self,
|
6710 | a8083063 | Iustin Pop | self.op.disk_template,
|
6711 | a8083063 | Iustin Pop | instance, pnode_name, |
6712 | 08db7c5c | Iustin Pop | self.secondaries,
|
6713 | 08db7c5c | Iustin Pop | self.disks,
|
6714 | 0f1a06e3 | Manuel Franceschini | file_storage_dir, |
6715 | e2a65344 | Iustin Pop | self.op.file_driver,
|
6716 | e2a65344 | Iustin Pop | 0)
|
6717 | a8083063 | Iustin Pop | |
6718 | a8083063 | Iustin Pop | iobj = objects.Instance(name=instance, os=self.op.os_type,
|
6719 | a8083063 | Iustin Pop | primary_node=pnode_name, |
6720 | 08db7c5c | Iustin Pop | nics=self.nics, disks=disks,
|
6721 | a8083063 | Iustin Pop | disk_template=self.op.disk_template,
|
6722 | 4978db17 | Iustin Pop | admin_up=False,
|
6723 | 58acb49d | Alexander Schreiber | network_port=network_port, |
6724 | 338e51e8 | Iustin Pop | beparams=self.op.beparams,
|
6725 | 6785674e | Iustin Pop | hvparams=self.op.hvparams,
|
6726 | e69d05fd | Iustin Pop | hypervisor=self.op.hypervisor,
|
6727 | a8083063 | Iustin Pop | ) |
6728 | a8083063 | Iustin Pop | |
6729 | c3589cf8 | Iustin Pop | if self.adopt_disks: |
6730 | c3589cf8 | Iustin Pop | # rename LVs to the newly-generated names; we need to construct
|
6731 | c3589cf8 | Iustin Pop | # 'fake' LV disks with the old data, plus the new unique_id
|
6732 | c3589cf8 | Iustin Pop | tmp_disks = [objects.Disk.FromDict(v.ToDict()) for v in disks] |
6733 | c3589cf8 | Iustin Pop | rename_to = [] |
6734 | c3589cf8 | Iustin Pop | for t_dsk, a_dsk in zip (tmp_disks, self.disks): |
6735 | c3589cf8 | Iustin Pop | rename_to.append(t_dsk.logical_id) |
6736 | c3589cf8 | Iustin Pop | t_dsk.logical_id = (t_dsk.logical_id[0], a_dsk["adopt"]) |
6737 | c3589cf8 | Iustin Pop | self.cfg.SetDiskID(t_dsk, pnode_name)
|
6738 | c3589cf8 | Iustin Pop | result = self.rpc.call_blockdev_rename(pnode_name,
|
6739 | c3589cf8 | Iustin Pop | zip(tmp_disks, rename_to))
|
6740 | c3589cf8 | Iustin Pop | result.Raise("Failed to rename adoped LVs")
|
6741 | c3589cf8 | Iustin Pop | else:
|
6742 | c3589cf8 | Iustin Pop | feedback_fn("* creating instance disks...")
|
6743 | 796cab27 | Iustin Pop | try:
|
6744 | c3589cf8 | Iustin Pop | _CreateDisks(self, iobj)
|
6745 | c3589cf8 | Iustin Pop | except errors.OpExecError:
|
6746 | c3589cf8 | Iustin Pop | self.LogWarning("Device creation failed, reverting...") |
6747 | c3589cf8 | Iustin Pop | try:
|
6748 | c3589cf8 | Iustin Pop | _RemoveDisks(self, iobj)
|
6749 | c3589cf8 | Iustin Pop | finally:
|
6750 | c3589cf8 | Iustin Pop | self.cfg.ReleaseDRBDMinors(instance)
|
6751 | c3589cf8 | Iustin Pop | raise
|
6752 | a8083063 | Iustin Pop | |
6753 | a8083063 | Iustin Pop | feedback_fn("adding instance %s to cluster config" % instance)
|
6754 | a8083063 | Iustin Pop | |
6755 | 0debfb35 | Guido Trotter | self.cfg.AddInstance(iobj, self.proc.GetECId()) |
6756 | 0debfb35 | Guido Trotter | |
6757 | 7baf741d | Guido Trotter | # Declare that we don't want to remove the instance lock anymore, as we've
|
6758 | 7baf741d | Guido Trotter | # added the instance to the config
|
6759 | 7baf741d | Guido Trotter | del self.remove_locks[locking.LEVEL_INSTANCE] |
6760 | e36e96b4 | Guido Trotter | # Unlock all the nodes
|
6761 | 9c8971d7 | Guido Trotter | if self.op.mode == constants.INSTANCE_IMPORT: |
6762 | 9c8971d7 | Guido Trotter | nodes_keep = [self.op.src_node]
|
6763 | 9c8971d7 | Guido Trotter | nodes_release = [node for node in self.acquired_locks[locking.LEVEL_NODE] |
6764 | 9c8971d7 | Guido Trotter | if node != self.op.src_node] |
6765 | 9c8971d7 | Guido Trotter | self.context.glm.release(locking.LEVEL_NODE, nodes_release)
|
6766 | 9c8971d7 | Guido Trotter | self.acquired_locks[locking.LEVEL_NODE] = nodes_keep
|
6767 | 9c8971d7 | Guido Trotter | else:
|
6768 | 9c8971d7 | Guido Trotter | self.context.glm.release(locking.LEVEL_NODE)
|
6769 | 9c8971d7 | Guido Trotter | del self.acquired_locks[locking.LEVEL_NODE] |
6770 | a8083063 | Iustin Pop | |
6771 | a8083063 | Iustin Pop | if self.op.wait_for_sync: |
6772 | b9bddb6b | Iustin Pop | disk_abort = not _WaitForSync(self, iobj) |
6773 | a1f445d3 | Iustin Pop | elif iobj.disk_template in constants.DTS_NET_MIRROR: |
6774 | a8083063 | Iustin Pop | # make sure the disks are not degraded (still sync-ing is ok)
|
6775 | a8083063 | Iustin Pop | time.sleep(15)
|
6776 | a8083063 | Iustin Pop | feedback_fn("* checking mirrors status")
|
6777 | b9bddb6b | Iustin Pop | disk_abort = not _WaitForSync(self, iobj, oneshot=True) |
6778 | a8083063 | Iustin Pop | else:
|
6779 | a8083063 | Iustin Pop | disk_abort = False
|
6780 | a8083063 | Iustin Pop | |
6781 | a8083063 | Iustin Pop | if disk_abort:
|
6782 | b9bddb6b | Iustin Pop | _RemoveDisks(self, iobj)
|
6783 | a8083063 | Iustin Pop | self.cfg.RemoveInstance(iobj.name)
|
6784 | 7baf741d | Guido Trotter | # Make sure the instance lock gets removed
|
6785 | 7baf741d | Guido Trotter | self.remove_locks[locking.LEVEL_INSTANCE] = iobj.name
|
6786 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("There are some degraded disks for" |
6787 | 3ecf6786 | Iustin Pop | " this instance")
|
6788 | a8083063 | Iustin Pop | |
6789 | c3589cf8 | Iustin Pop | if iobj.disk_template != constants.DT_DISKLESS and not self.adopt_disks: |
6790 | a8083063 | Iustin Pop | if self.op.mode == constants.INSTANCE_CREATE: |
6791 | 25a8792c | Iustin Pop | if not self.op.no_install: |
6792 | 25a8792c | Iustin Pop | feedback_fn("* running the instance OS create scripts...")
|
6793 | 25a8792c | Iustin Pop | # FIXME: pass debug option from opcode to backend
|
6794 | 25a8792c | Iustin Pop | result = self.rpc.call_instance_os_add(pnode_name, iobj, False, |
6795 | 25a8792c | Iustin Pop | self.op.debug_level)
|
6796 | 25a8792c | Iustin Pop | result.Raise("Could not add os for instance %s"
|
6797 | 25a8792c | Iustin Pop | " on node %s" % (instance, pnode_name))
|
6798 | a8083063 | Iustin Pop | |
6799 | a8083063 | Iustin Pop | elif self.op.mode == constants.INSTANCE_IMPORT: |
6800 | a8083063 | Iustin Pop | feedback_fn("* running the instance OS import scripts...")
|
6801 | a8083063 | Iustin Pop | src_node = self.op.src_node
|
6802 | 09acf207 | Guido Trotter | src_images = self.src_images
|
6803 | 62c9ec92 | Iustin Pop | cluster_name = self.cfg.GetClusterName()
|
6804 | 4a0e011f | Iustin Pop | # FIXME: pass debug option from opcode to backend
|
6805 | 6c0af70e | Guido Trotter | import_result = self.rpc.call_instance_os_import(pnode_name, iobj,
|
6806 | 09acf207 | Guido Trotter | src_node, src_images, |
6807 | dd713605 | Iustin Pop | cluster_name, |
6808 | dd713605 | Iustin Pop | self.op.debug_level)
|
6809 | 4c4e4e1e | Iustin Pop | msg = import_result.fail_msg |
6810 | 944bf548 | Iustin Pop | if msg:
|
6811 | 944bf548 | Iustin Pop | self.LogWarning("Error while importing the disk images for instance" |
6812 | 944bf548 | Iustin Pop | " %s on node %s: %s" % (instance, pnode_name, msg))
|
6813 | a8083063 | Iustin Pop | else:
|
6814 | a8083063 | Iustin Pop | # also checked in the prereq part
|
6815 | 3ecf6786 | Iustin Pop | raise errors.ProgrammerError("Unknown OS initialization mode '%s'" |
6816 | 3ecf6786 | Iustin Pop | % self.op.mode)
|
6817 | a8083063 | Iustin Pop | |
6818 | a8083063 | Iustin Pop | if self.op.start: |
6819 | 4978db17 | Iustin Pop | iobj.admin_up = True
|
6820 | a4eae71f | Michael Hanselmann | self.cfg.Update(iobj, feedback_fn)
|
6821 | 9a4f63d1 | Iustin Pop | logging.info("Starting instance %s on node %s", instance, pnode_name)
|
6822 | a8083063 | Iustin Pop | feedback_fn("* starting instance...")
|
6823 | 0eca8e0c | Iustin Pop | result = self.rpc.call_instance_start(pnode_name, iobj, None, None) |
6824 | 4c4e4e1e | Iustin Pop | result.Raise("Could not start instance")
|
6825 | a8083063 | Iustin Pop | |
6826 | 08896026 | Iustin Pop | return list(iobj.all_nodes) |
6827 | 08896026 | Iustin Pop | |
6828 | a8083063 | Iustin Pop | |
6829 | a8083063 | Iustin Pop | class LUConnectConsole(NoHooksLU): |
6830 | a8083063 | Iustin Pop | """Connect to an instance's console.
|
6831 | a8083063 | Iustin Pop |
|
6832 | a8083063 | Iustin Pop | This is somewhat special in that it returns the command line that
|
6833 | a8083063 | Iustin Pop | you need to run on the master node in order to connect to the
|
6834 | a8083063 | Iustin Pop | console.
|
6835 | a8083063 | Iustin Pop |
|
6836 | a8083063 | Iustin Pop | """
|
6837 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name"]
|
6838 | 8659b73e | Guido Trotter | REQ_BGL = False
|
6839 | 8659b73e | Guido Trotter | |
6840 | 8659b73e | Guido Trotter | def ExpandNames(self): |
6841 | 8659b73e | Guido Trotter | self._ExpandAndLockInstance()
|
6842 | a8083063 | Iustin Pop | |
6843 | a8083063 | Iustin Pop | def CheckPrereq(self): |
6844 | a8083063 | Iustin Pop | """Check prerequisites.
|
6845 | a8083063 | Iustin Pop |
|
6846 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
6847 | a8083063 | Iustin Pop |
|
6848 | a8083063 | Iustin Pop | """
|
6849 | 8659b73e | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
6850 | 8659b73e | Guido Trotter | assert self.instance is not None, \ |
6851 | 8659b73e | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
6852 | 513e896d | Guido Trotter | _CheckNodeOnline(self, self.instance.primary_node) |
6853 | a8083063 | Iustin Pop | |
6854 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
6855 | a8083063 | Iustin Pop | """Connect to the console of an instance
|
6856 | a8083063 | Iustin Pop |
|
6857 | a8083063 | Iustin Pop | """
|
6858 | a8083063 | Iustin Pop | instance = self.instance
|
6859 | a8083063 | Iustin Pop | node = instance.primary_node |
6860 | a8083063 | Iustin Pop | |
6861 | 72737a7f | Iustin Pop | node_insts = self.rpc.call_instance_list([node],
|
6862 | 72737a7f | Iustin Pop | [instance.hypervisor])[node] |
6863 | 4c4e4e1e | Iustin Pop | node_insts.Raise("Can't get node information from %s" % node)
|
6864 | a8083063 | Iustin Pop | |
6865 | aca13712 | Iustin Pop | if instance.name not in node_insts.payload: |
6866 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Instance %s is not running." % instance.name) |
6867 | a8083063 | Iustin Pop | |
6868 | 9a4f63d1 | Iustin Pop | logging.debug("Connecting to console of %s on %s", instance.name, node)
|
6869 | a8083063 | Iustin Pop | |
6870 | e69d05fd | Iustin Pop | hyper = hypervisor.GetHypervisor(instance.hypervisor) |
6871 | 5431b2e4 | Guido Trotter | cluster = self.cfg.GetClusterInfo()
|
6872 | 5431b2e4 | Guido Trotter | # beparams and hvparams are passed separately, to avoid editing the
|
6873 | 5431b2e4 | Guido Trotter | # instance and then saving the defaults in the instance itself.
|
6874 | 5431b2e4 | Guido Trotter | hvparams = cluster.FillHV(instance) |
6875 | 5431b2e4 | Guido Trotter | beparams = cluster.FillBE(instance) |
6876 | 5431b2e4 | Guido Trotter | console_cmd = hyper.GetShellCommandForConsole(instance, hvparams, beparams) |
6877 | b047857b | Michael Hanselmann | |
6878 | 82122173 | Iustin Pop | # build ssh cmdline
|
6879 | 0a80a26f | Michael Hanselmann | return self.ssh.BuildCmd(node, "root", console_cmd, batch=True, tty=True) |
6880 | a8083063 | Iustin Pop | |
6881 | a8083063 | Iustin Pop | |
6882 | a8083063 | Iustin Pop | class LUReplaceDisks(LogicalUnit): |
6883 | a8083063 | Iustin Pop | """Replace the disks of an instance.
|
6884 | a8083063 | Iustin Pop |
|
6885 | a8083063 | Iustin Pop | """
|
6886 | a8083063 | Iustin Pop | HPATH = "mirrors-replace"
|
6887 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
6888 | a9e0c397 | Iustin Pop | _OP_REQP = ["instance_name", "mode", "disks"] |
6889 | efd990e4 | Guido Trotter | REQ_BGL = False
|
6890 | efd990e4 | Guido Trotter | |
6891 | 7e9366f7 | Iustin Pop | def CheckArguments(self): |
6892 | efd990e4 | Guido Trotter | if not hasattr(self.op, "remote_node"): |
6893 | efd990e4 | Guido Trotter | self.op.remote_node = None |
6894 | 7e9366f7 | Iustin Pop | if not hasattr(self.op, "iallocator"): |
6895 | 7e9366f7 | Iustin Pop | self.op.iallocator = None |
6896 | 7ea7bcf6 | Iustin Pop | if not hasattr(self.op, "early_release"): |
6897 | 7ea7bcf6 | Iustin Pop | self.op.early_release = False |
6898 | 7e9366f7 | Iustin Pop | |
6899 | c68174b6 | Michael Hanselmann | TLReplaceDisks.CheckArguments(self.op.mode, self.op.remote_node, |
6900 | c68174b6 | Michael Hanselmann | self.op.iallocator)
|
6901 | 7e9366f7 | Iustin Pop | |
6902 | 7e9366f7 | Iustin Pop | def ExpandNames(self): |
6903 | 7e9366f7 | Iustin Pop | self._ExpandAndLockInstance()
|
6904 | 7e9366f7 | Iustin Pop | |
6905 | 7e9366f7 | Iustin Pop | if self.op.iallocator is not None: |
6906 | efd990e4 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
6907 | 2bb5c911 | Michael Hanselmann | |
6908 | efd990e4 | Guido Trotter | elif self.op.remote_node is not None: |
6909 | cf26a87a | Iustin Pop | remote_node = _ExpandNodeName(self.cfg, self.op.remote_node) |
6910 | efd990e4 | Guido Trotter | self.op.remote_node = remote_node
|
6911 | 2bb5c911 | Michael Hanselmann | |
6912 | 3b559640 | Iustin Pop | # Warning: do not remove the locking of the new secondary here
|
6913 | 3b559640 | Iustin Pop | # unless DRBD8.AddChildren is changed to work in parallel;
|
6914 | 3b559640 | Iustin Pop | # currently it doesn't since parallel invocations of
|
6915 | 3b559640 | Iustin Pop | # FindUnusedMinor will conflict
|
6916 | efd990e4 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = [remote_node]
|
6917 | efd990e4 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_APPEND
|
6918 | 2bb5c911 | Michael Hanselmann | |
6919 | efd990e4 | Guido Trotter | else:
|
6920 | efd990e4 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
6921 | efd990e4 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
6922 | efd990e4 | Guido Trotter | |
6923 | c68174b6 | Michael Hanselmann | self.replacer = TLReplaceDisks(self, self.op.instance_name, self.op.mode, |
6924 | c68174b6 | Michael Hanselmann | self.op.iallocator, self.op.remote_node, |
6925 | 7ea7bcf6 | Iustin Pop | self.op.disks, False, self.op.early_release) |
6926 | c68174b6 | Michael Hanselmann | |
6927 | 3a012b41 | Michael Hanselmann | self.tasklets = [self.replacer] |
6928 | 2bb5c911 | Michael Hanselmann | |
6929 | efd990e4 | Guido Trotter | def DeclareLocks(self, level): |
6930 | efd990e4 | Guido Trotter | # If we're not already locking all nodes in the set we have to declare the
|
6931 | efd990e4 | Guido Trotter | # instance's primary/secondary nodes.
|
6932 | efd990e4 | Guido Trotter | if (level == locking.LEVEL_NODE and |
6933 | efd990e4 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET): |
6934 | efd990e4 | Guido Trotter | self._LockInstancesNodes()
|
6935 | a8083063 | Iustin Pop | |
6936 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
6937 | a8083063 | Iustin Pop | """Build hooks env.
|
6938 | a8083063 | Iustin Pop |
|
6939 | a8083063 | Iustin Pop | This runs on the master, the primary and all the secondaries.
|
6940 | a8083063 | Iustin Pop |
|
6941 | a8083063 | Iustin Pop | """
|
6942 | 2bb5c911 | Michael Hanselmann | instance = self.replacer.instance
|
6943 | a8083063 | Iustin Pop | env = { |
6944 | a9e0c397 | Iustin Pop | "MODE": self.op.mode, |
6945 | a8083063 | Iustin Pop | "NEW_SECONDARY": self.op.remote_node, |
6946 | 2bb5c911 | Michael Hanselmann | "OLD_SECONDARY": instance.secondary_nodes[0], |
6947 | a8083063 | Iustin Pop | } |
6948 | 2bb5c911 | Michael Hanselmann | env.update(_BuildInstanceHookEnvByObject(self, instance))
|
6949 | 0834c866 | Iustin Pop | nl = [ |
6950 | d6a02168 | Michael Hanselmann | self.cfg.GetMasterNode(),
|
6951 | 2bb5c911 | Michael Hanselmann | instance.primary_node, |
6952 | 0834c866 | Iustin Pop | ] |
6953 | 0834c866 | Iustin Pop | if self.op.remote_node is not None: |
6954 | 0834c866 | Iustin Pop | nl.append(self.op.remote_node)
|
6955 | a8083063 | Iustin Pop | return env, nl, nl
|
6956 | a8083063 | Iustin Pop | |
6957 | 2bb5c911 | Michael Hanselmann | |
6958 | 7ffc5a86 | Michael Hanselmann | class LUEvacuateNode(LogicalUnit): |
6959 | 7ffc5a86 | Michael Hanselmann | """Relocate the secondary instances from a node.
|
6960 | 7ffc5a86 | Michael Hanselmann |
|
6961 | 7ffc5a86 | Michael Hanselmann | """
|
6962 | 7ffc5a86 | Michael Hanselmann | HPATH = "node-evacuate"
|
6963 | 7ffc5a86 | Michael Hanselmann | HTYPE = constants.HTYPE_NODE |
6964 | 7ffc5a86 | Michael Hanselmann | _OP_REQP = ["node_name"]
|
6965 | 7ffc5a86 | Michael Hanselmann | REQ_BGL = False
|
6966 | 7ffc5a86 | Michael Hanselmann | |
6967 | 7ffc5a86 | Michael Hanselmann | def CheckArguments(self): |
6968 | 7ffc5a86 | Michael Hanselmann | if not hasattr(self.op, "remote_node"): |
6969 | 7ffc5a86 | Michael Hanselmann | self.op.remote_node = None |
6970 | 7ffc5a86 | Michael Hanselmann | if not hasattr(self.op, "iallocator"): |
6971 | 7ffc5a86 | Michael Hanselmann | self.op.iallocator = None |
6972 | 7ea7bcf6 | Iustin Pop | if not hasattr(self.op, "early_release"): |
6973 | 7ea7bcf6 | Iustin Pop | self.op.early_release = False |
6974 | 7ffc5a86 | Michael Hanselmann | |
6975 | 7ffc5a86 | Michael Hanselmann | TLReplaceDisks.CheckArguments(constants.REPLACE_DISK_CHG, |
6976 | 7ffc5a86 | Michael Hanselmann | self.op.remote_node,
|
6977 | 7ffc5a86 | Michael Hanselmann | self.op.iallocator)
|
6978 | 7ffc5a86 | Michael Hanselmann | |
6979 | 7ffc5a86 | Michael Hanselmann | def ExpandNames(self): |
6980 | cf26a87a | Iustin Pop | self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name) |
6981 | 7ffc5a86 | Michael Hanselmann | |
6982 | 7ffc5a86 | Michael Hanselmann | self.needed_locks = {}
|
6983 | 7ffc5a86 | Michael Hanselmann | |
6984 | 7ffc5a86 | Michael Hanselmann | # Declare node locks
|
6985 | 7ffc5a86 | Michael Hanselmann | if self.op.iallocator is not None: |
6986 | 7ffc5a86 | Michael Hanselmann | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
6987 | 7ffc5a86 | Michael Hanselmann | |
6988 | 7ffc5a86 | Michael Hanselmann | elif self.op.remote_node is not None: |
6989 | cf26a87a | Iustin Pop | self.op.remote_node = _ExpandNodeName(self.cfg, self.op.remote_node) |
6990 | 7ffc5a86 | Michael Hanselmann | |
6991 | 7ffc5a86 | Michael Hanselmann | # Warning: do not remove the locking of the new secondary here
|
6992 | 7ffc5a86 | Michael Hanselmann | # unless DRBD8.AddChildren is changed to work in parallel;
|
6993 | 7ffc5a86 | Michael Hanselmann | # currently it doesn't since parallel invocations of
|
6994 | 7ffc5a86 | Michael Hanselmann | # FindUnusedMinor will conflict
|
6995 | cf26a87a | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = [self.op.remote_node] |
6996 | 7ffc5a86 | Michael Hanselmann | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_APPEND
|
6997 | 7ffc5a86 | Michael Hanselmann | |
6998 | 7ffc5a86 | Michael Hanselmann | else:
|
6999 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid parameters", errors.ECODE_INVAL) |
7000 | 7ffc5a86 | Michael Hanselmann | |
7001 | 7ffc5a86 | Michael Hanselmann | # Create tasklets for replacing disks for all secondary instances on this
|
7002 | 7ffc5a86 | Michael Hanselmann | # node
|
7003 | 7ffc5a86 | Michael Hanselmann | names = [] |
7004 | 3a012b41 | Michael Hanselmann | tasklets = [] |
7005 | 7ffc5a86 | Michael Hanselmann | |
7006 | 7ffc5a86 | Michael Hanselmann | for inst in _GetNodeSecondaryInstances(self.cfg, self.op.node_name): |
7007 | 7ffc5a86 | Michael Hanselmann | logging.debug("Replacing disks for instance %s", inst.name)
|
7008 | 7ffc5a86 | Michael Hanselmann | names.append(inst.name) |
7009 | 7ffc5a86 | Michael Hanselmann | |
7010 | 7ffc5a86 | Michael Hanselmann | replacer = TLReplaceDisks(self, inst.name, constants.REPLACE_DISK_CHG,
|
7011 | 94a1b377 | Michael Hanselmann | self.op.iallocator, self.op.remote_node, [], |
7012 | 7ea7bcf6 | Iustin Pop | True, self.op.early_release) |
7013 | 3a012b41 | Michael Hanselmann | tasklets.append(replacer) |
7014 | 7ffc5a86 | Michael Hanselmann | |
7015 | 3a012b41 | Michael Hanselmann | self.tasklets = tasklets
|
7016 | 7ffc5a86 | Michael Hanselmann | self.instance_names = names
|
7017 | 7ffc5a86 | Michael Hanselmann | |
7018 | 7ffc5a86 | Michael Hanselmann | # Declare instance locks
|
7019 | 7ffc5a86 | Michael Hanselmann | self.needed_locks[locking.LEVEL_INSTANCE] = self.instance_names |
7020 | 7ffc5a86 | Michael Hanselmann | |
7021 | 7ffc5a86 | Michael Hanselmann | def DeclareLocks(self, level): |
7022 | 7ffc5a86 | Michael Hanselmann | # If we're not already locking all nodes in the set we have to declare the
|
7023 | 7ffc5a86 | Michael Hanselmann | # instance's primary/secondary nodes.
|
7024 | 7ffc5a86 | Michael Hanselmann | if (level == locking.LEVEL_NODE and |
7025 | 7ffc5a86 | Michael Hanselmann | self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET): |
7026 | 7ffc5a86 | Michael Hanselmann | self._LockInstancesNodes()
|
7027 | 7ffc5a86 | Michael Hanselmann | |
7028 | 7ffc5a86 | Michael Hanselmann | def BuildHooksEnv(self): |
7029 | 7ffc5a86 | Michael Hanselmann | """Build hooks env.
|
7030 | 7ffc5a86 | Michael Hanselmann |
|
7031 | 7ffc5a86 | Michael Hanselmann | This runs on the master, the primary and all the secondaries.
|
7032 | 7ffc5a86 | Michael Hanselmann |
|
7033 | 7ffc5a86 | Michael Hanselmann | """
|
7034 | 7ffc5a86 | Michael Hanselmann | env = { |
7035 | 7ffc5a86 | Michael Hanselmann | "NODE_NAME": self.op.node_name, |
7036 | 7ffc5a86 | Michael Hanselmann | } |
7037 | 7ffc5a86 | Michael Hanselmann | |
7038 | 7ffc5a86 | Michael Hanselmann | nl = [self.cfg.GetMasterNode()]
|
7039 | 7ffc5a86 | Michael Hanselmann | |
7040 | 7ffc5a86 | Michael Hanselmann | if self.op.remote_node is not None: |
7041 | 7ffc5a86 | Michael Hanselmann | env["NEW_SECONDARY"] = self.op.remote_node |
7042 | 7ffc5a86 | Michael Hanselmann | nl.append(self.op.remote_node)
|
7043 | 7ffc5a86 | Michael Hanselmann | |
7044 | 7ffc5a86 | Michael Hanselmann | return (env, nl, nl)
|
7045 | 7ffc5a86 | Michael Hanselmann | |
7046 | 7ffc5a86 | Michael Hanselmann | |
7047 | c68174b6 | Michael Hanselmann | class TLReplaceDisks(Tasklet): |
7048 | 2bb5c911 | Michael Hanselmann | """Replaces disks for an instance.
|
7049 | 2bb5c911 | Michael Hanselmann |
|
7050 | 2bb5c911 | Michael Hanselmann | Note: Locking is not within the scope of this class.
|
7051 | 2bb5c911 | Michael Hanselmann |
|
7052 | 2bb5c911 | Michael Hanselmann | """
|
7053 | 2bb5c911 | Michael Hanselmann | def __init__(self, lu, instance_name, mode, iallocator_name, remote_node, |
7054 | 7ea7bcf6 | Iustin Pop | disks, delay_iallocator, early_release): |
7055 | 2bb5c911 | Michael Hanselmann | """Initializes this class.
|
7056 | 2bb5c911 | Michael Hanselmann |
|
7057 | 2bb5c911 | Michael Hanselmann | """
|
7058 | 464243a7 | Michael Hanselmann | Tasklet.__init__(self, lu)
|
7059 | 464243a7 | Michael Hanselmann | |
7060 | 2bb5c911 | Michael Hanselmann | # Parameters
|
7061 | 2bb5c911 | Michael Hanselmann | self.instance_name = instance_name
|
7062 | 2bb5c911 | Michael Hanselmann | self.mode = mode
|
7063 | 2bb5c911 | Michael Hanselmann | self.iallocator_name = iallocator_name
|
7064 | 2bb5c911 | Michael Hanselmann | self.remote_node = remote_node
|
7065 | 2bb5c911 | Michael Hanselmann | self.disks = disks
|
7066 | 94a1b377 | Michael Hanselmann | self.delay_iallocator = delay_iallocator
|
7067 | 7ea7bcf6 | Iustin Pop | self.early_release = early_release
|
7068 | 2bb5c911 | Michael Hanselmann | |
7069 | 2bb5c911 | Michael Hanselmann | # Runtime data
|
7070 | 2bb5c911 | Michael Hanselmann | self.instance = None |
7071 | 2bb5c911 | Michael Hanselmann | self.new_node = None |
7072 | 2bb5c911 | Michael Hanselmann | self.target_node = None |
7073 | 2bb5c911 | Michael Hanselmann | self.other_node = None |
7074 | 2bb5c911 | Michael Hanselmann | self.remote_node_info = None |
7075 | 2bb5c911 | Michael Hanselmann | self.node_secondary_ip = None |
7076 | 2bb5c911 | Michael Hanselmann | |
7077 | 2bb5c911 | Michael Hanselmann | @staticmethod
|
7078 | 2bb5c911 | Michael Hanselmann | def CheckArguments(mode, remote_node, iallocator): |
7079 | c68174b6 | Michael Hanselmann | """Helper function for users of this class.
|
7080 | c68174b6 | Michael Hanselmann |
|
7081 | c68174b6 | Michael Hanselmann | """
|
7082 | 2bb5c911 | Michael Hanselmann | # check for valid parameter combination
|
7083 | 2bb5c911 | Michael Hanselmann | if mode == constants.REPLACE_DISK_CHG:
|
7084 | 02a00186 | Michael Hanselmann | if remote_node is None and iallocator is None: |
7085 | 2bb5c911 | Michael Hanselmann | raise errors.OpPrereqError("When changing the secondary either an" |
7086 | 2bb5c911 | Michael Hanselmann | " iallocator script must be used or the"
|
7087 | 5c983ee5 | Iustin Pop | " new node given", errors.ECODE_INVAL)
|
7088 | 02a00186 | Michael Hanselmann | |
7089 | 02a00186 | Michael Hanselmann | if remote_node is not None and iallocator is not None: |
7090 | 2bb5c911 | Michael Hanselmann | raise errors.OpPrereqError("Give either the iallocator or the new" |
7091 | 5c983ee5 | Iustin Pop | " secondary, not both", errors.ECODE_INVAL)
|
7092 | 02a00186 | Michael Hanselmann | |
7093 | 02a00186 | Michael Hanselmann | elif remote_node is not None or iallocator is not None: |
7094 | 02a00186 | Michael Hanselmann | # Not replacing the secondary
|
7095 | 02a00186 | Michael Hanselmann | raise errors.OpPrereqError("The iallocator and new node options can" |
7096 | 02a00186 | Michael Hanselmann | " only be used when changing the"
|
7097 | 5c983ee5 | Iustin Pop | " secondary node", errors.ECODE_INVAL)
|
7098 | 2bb5c911 | Michael Hanselmann | |
7099 | 2bb5c911 | Michael Hanselmann | @staticmethod
|
7100 | 2bb5c911 | Michael Hanselmann | def _RunAllocator(lu, iallocator_name, instance_name, relocate_from): |
7101 | 2bb5c911 | Michael Hanselmann | """Compute a new secondary node using an IAllocator.
|
7102 | 2bb5c911 | Michael Hanselmann |
|
7103 | 2bb5c911 | Michael Hanselmann | """
|
7104 | 2bb5c911 | Michael Hanselmann | ial = IAllocator(lu.cfg, lu.rpc, |
7105 | 2bb5c911 | Michael Hanselmann | mode=constants.IALLOCATOR_MODE_RELOC, |
7106 | 2bb5c911 | Michael Hanselmann | name=instance_name, |
7107 | 2bb5c911 | Michael Hanselmann | relocate_from=relocate_from) |
7108 | 2bb5c911 | Michael Hanselmann | |
7109 | 2bb5c911 | Michael Hanselmann | ial.Run(iallocator_name) |
7110 | 2bb5c911 | Michael Hanselmann | |
7111 | 2bb5c911 | Michael Hanselmann | if not ial.success: |
7112 | 2bb5c911 | Michael Hanselmann | raise errors.OpPrereqError("Can't compute nodes using iallocator '%s':" |
7113 | 5c983ee5 | Iustin Pop | " %s" % (iallocator_name, ial.info),
|
7114 | 5c983ee5 | Iustin Pop | errors.ECODE_NORES) |
7115 | 2bb5c911 | Michael Hanselmann | |
7116 | 680f0a89 | Iustin Pop | if len(ial.result) != ial.required_nodes: |
7117 | 2bb5c911 | Michael Hanselmann | raise errors.OpPrereqError("iallocator '%s' returned invalid number" |
7118 | 2bb5c911 | Michael Hanselmann | " of nodes (%s), required %s" %
|
7119 | d984846d | Iustin Pop | (iallocator_name, |
7120 | 680f0a89 | Iustin Pop | len(ial.result), ial.required_nodes),
|
7121 | 5c983ee5 | Iustin Pop | errors.ECODE_FAULT) |
7122 | 2bb5c911 | Michael Hanselmann | |
7123 | 680f0a89 | Iustin Pop | remote_node_name = ial.result[0]
|
7124 | 2bb5c911 | Michael Hanselmann | |
7125 | 2bb5c911 | Michael Hanselmann | lu.LogInfo("Selected new secondary for instance '%s': %s",
|
7126 | 2bb5c911 | Michael Hanselmann | instance_name, remote_node_name) |
7127 | 2bb5c911 | Michael Hanselmann | |
7128 | 2bb5c911 | Michael Hanselmann | return remote_node_name
|
7129 | 2bb5c911 | Michael Hanselmann | |
7130 | 942be002 | Michael Hanselmann | def _FindFaultyDisks(self, node_name): |
7131 | 2d9005d8 | Michael Hanselmann | return _FindFaultyInstanceDisks(self.cfg, self.rpc, self.instance, |
7132 | 2d9005d8 | Michael Hanselmann | node_name, True)
|
7133 | 942be002 | Michael Hanselmann | |
7134 | 2bb5c911 | Michael Hanselmann | def CheckPrereq(self): |
7135 | 2bb5c911 | Michael Hanselmann | """Check prerequisites.
|
7136 | 2bb5c911 | Michael Hanselmann |
|
7137 | 2bb5c911 | Michael Hanselmann | This checks that the instance is in the cluster.
|
7138 | 2bb5c911 | Michael Hanselmann |
|
7139 | 2bb5c911 | Michael Hanselmann | """
|
7140 | e9022531 | Iustin Pop | self.instance = instance = self.cfg.GetInstanceInfo(self.instance_name) |
7141 | e9022531 | Iustin Pop | assert instance is not None, \ |
7142 | 20eca47d | Iustin Pop | "Cannot retrieve locked instance %s" % self.instance_name |
7143 | 2bb5c911 | Michael Hanselmann | |
7144 | e9022531 | Iustin Pop | if instance.disk_template != constants.DT_DRBD8:
|
7145 | 7e9366f7 | Iustin Pop | raise errors.OpPrereqError("Can only run replace disks for DRBD8-based" |
7146 | 5c983ee5 | Iustin Pop | " instances", errors.ECODE_INVAL)
|
7147 | a8083063 | Iustin Pop | |
7148 | e9022531 | Iustin Pop | if len(instance.secondary_nodes) != 1: |
7149 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("The instance has a strange layout," |
7150 | 3ecf6786 | Iustin Pop | " expected one secondary but found %d" %
|
7151 | 5c983ee5 | Iustin Pop | len(instance.secondary_nodes),
|
7152 | 5c983ee5 | Iustin Pop | errors.ECODE_FAULT) |
7153 | a8083063 | Iustin Pop | |
7154 | 94a1b377 | Michael Hanselmann | if not self.delay_iallocator: |
7155 | 94a1b377 | Michael Hanselmann | self._CheckPrereq2()
|
7156 | 94a1b377 | Michael Hanselmann | |
7157 | 94a1b377 | Michael Hanselmann | def _CheckPrereq2(self): |
7158 | 94a1b377 | Michael Hanselmann | """Check prerequisites, second part.
|
7159 | 94a1b377 | Michael Hanselmann |
|
7160 | 94a1b377 | Michael Hanselmann | This function should always be part of CheckPrereq. It was separated and is
|
7161 | 94a1b377 | Michael Hanselmann | now called from Exec because during node evacuation iallocator was only
|
7162 | 94a1b377 | Michael Hanselmann | called with an unmodified cluster model, not taking planned changes into
|
7163 | 94a1b377 | Michael Hanselmann | account.
|
7164 | 94a1b377 | Michael Hanselmann |
|
7165 | 94a1b377 | Michael Hanselmann | """
|
7166 | 94a1b377 | Michael Hanselmann | instance = self.instance
|
7167 | e9022531 | Iustin Pop | secondary_node = instance.secondary_nodes[0]
|
7168 | a9e0c397 | Iustin Pop | |
7169 | 2bb5c911 | Michael Hanselmann | if self.iallocator_name is None: |
7170 | 2bb5c911 | Michael Hanselmann | remote_node = self.remote_node
|
7171 | 2bb5c911 | Michael Hanselmann | else:
|
7172 | 2bb5c911 | Michael Hanselmann | remote_node = self._RunAllocator(self.lu, self.iallocator_name, |
7173 | e9022531 | Iustin Pop | instance.name, instance.secondary_nodes) |
7174 | b6e82a65 | Iustin Pop | |
7175 | a9e0c397 | Iustin Pop | if remote_node is not None: |
7176 | a9e0c397 | Iustin Pop | self.remote_node_info = self.cfg.GetNodeInfo(remote_node) |
7177 | efd990e4 | Guido Trotter | assert self.remote_node_info is not None, \ |
7178 | efd990e4 | Guido Trotter | "Cannot retrieve locked node %s" % remote_node
|
7179 | a9e0c397 | Iustin Pop | else:
|
7180 | a9e0c397 | Iustin Pop | self.remote_node_info = None |
7181 | 2bb5c911 | Michael Hanselmann | |
7182 | 2bb5c911 | Michael Hanselmann | if remote_node == self.instance.primary_node: |
7183 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("The specified node is the primary node of" |
7184 | 5c983ee5 | Iustin Pop | " the instance.", errors.ECODE_INVAL)
|
7185 | 2bb5c911 | Michael Hanselmann | |
7186 | 2bb5c911 | Michael Hanselmann | if remote_node == secondary_node:
|
7187 | 7e9366f7 | Iustin Pop | raise errors.OpPrereqError("The specified node is already the" |
7188 | 5c983ee5 | Iustin Pop | " secondary node of the instance.",
|
7189 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
7190 | 7e9366f7 | Iustin Pop | |
7191 | 2945fd2d | Michael Hanselmann | if self.disks and self.mode in (constants.REPLACE_DISK_AUTO, |
7192 | 2945fd2d | Michael Hanselmann | constants.REPLACE_DISK_CHG): |
7193 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Cannot specify disks to be replaced", |
7194 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
7195 | 942be002 | Michael Hanselmann | |
7196 | 2945fd2d | Michael Hanselmann | if self.mode == constants.REPLACE_DISK_AUTO: |
7197 | e9022531 | Iustin Pop | faulty_primary = self._FindFaultyDisks(instance.primary_node)
|
7198 | 942be002 | Michael Hanselmann | faulty_secondary = self._FindFaultyDisks(secondary_node)
|
7199 | 942be002 | Michael Hanselmann | |
7200 | 942be002 | Michael Hanselmann | if faulty_primary and faulty_secondary: |
7201 | 942be002 | Michael Hanselmann | raise errors.OpPrereqError("Instance %s has faulty disks on more than" |
7202 | 942be002 | Michael Hanselmann | " one node and can not be repaired"
|
7203 | 5c983ee5 | Iustin Pop | " automatically" % self.instance_name, |
7204 | 5c983ee5 | Iustin Pop | errors.ECODE_STATE) |
7205 | 942be002 | Michael Hanselmann | |
7206 | 942be002 | Michael Hanselmann | if faulty_primary:
|
7207 | 942be002 | Michael Hanselmann | self.disks = faulty_primary
|
7208 | e9022531 | Iustin Pop | self.target_node = instance.primary_node
|
7209 | 942be002 | Michael Hanselmann | self.other_node = secondary_node
|
7210 | 942be002 | Michael Hanselmann | check_nodes = [self.target_node, self.other_node] |
7211 | 942be002 | Michael Hanselmann | elif faulty_secondary:
|
7212 | 942be002 | Michael Hanselmann | self.disks = faulty_secondary
|
7213 | 942be002 | Michael Hanselmann | self.target_node = secondary_node
|
7214 | e9022531 | Iustin Pop | self.other_node = instance.primary_node
|
7215 | 942be002 | Michael Hanselmann | check_nodes = [self.target_node, self.other_node] |
7216 | 942be002 | Michael Hanselmann | else:
|
7217 | 942be002 | Michael Hanselmann | self.disks = []
|
7218 | 942be002 | Michael Hanselmann | check_nodes = [] |
7219 | 942be002 | Michael Hanselmann | |
7220 | 942be002 | Michael Hanselmann | else:
|
7221 | 942be002 | Michael Hanselmann | # Non-automatic modes
|
7222 | 942be002 | Michael Hanselmann | if self.mode == constants.REPLACE_DISK_PRI: |
7223 | e9022531 | Iustin Pop | self.target_node = instance.primary_node
|
7224 | 942be002 | Michael Hanselmann | self.other_node = secondary_node
|
7225 | 942be002 | Michael Hanselmann | check_nodes = [self.target_node, self.other_node] |
7226 | 7e9366f7 | Iustin Pop | |
7227 | 942be002 | Michael Hanselmann | elif self.mode == constants.REPLACE_DISK_SEC: |
7228 | 942be002 | Michael Hanselmann | self.target_node = secondary_node
|
7229 | e9022531 | Iustin Pop | self.other_node = instance.primary_node
|
7230 | 942be002 | Michael Hanselmann | check_nodes = [self.target_node, self.other_node] |
7231 | a9e0c397 | Iustin Pop | |
7232 | 942be002 | Michael Hanselmann | elif self.mode == constants.REPLACE_DISK_CHG: |
7233 | 942be002 | Michael Hanselmann | self.new_node = remote_node
|
7234 | e9022531 | Iustin Pop | self.other_node = instance.primary_node
|
7235 | 942be002 | Michael Hanselmann | self.target_node = secondary_node
|
7236 | 942be002 | Michael Hanselmann | check_nodes = [self.new_node, self.other_node] |
7237 | 54155f52 | Iustin Pop | |
7238 | 942be002 | Michael Hanselmann | _CheckNodeNotDrained(self.lu, remote_node)
|
7239 | a8083063 | Iustin Pop | |
7240 | 9af0fa6a | Iustin Pop | old_node_info = self.cfg.GetNodeInfo(secondary_node)
|
7241 | 9af0fa6a | Iustin Pop | assert old_node_info is not None |
7242 | 9af0fa6a | Iustin Pop | if old_node_info.offline and not self.early_release: |
7243 | 9af0fa6a | Iustin Pop | # doesn't make sense to delay the release
|
7244 | 9af0fa6a | Iustin Pop | self.early_release = True |
7245 | 9af0fa6a | Iustin Pop | self.lu.LogInfo("Old secondary %s is offline, automatically enabling" |
7246 | 9af0fa6a | Iustin Pop | " early-release mode", secondary_node)
|
7247 | 9af0fa6a | Iustin Pop | |
7248 | 942be002 | Michael Hanselmann | else:
|
7249 | 942be002 | Michael Hanselmann | raise errors.ProgrammerError("Unhandled disk replace mode (%s)" % |
7250 | 942be002 | Michael Hanselmann | self.mode)
|
7251 | 942be002 | Michael Hanselmann | |
7252 | 942be002 | Michael Hanselmann | # If not specified all disks should be replaced
|
7253 | 942be002 | Michael Hanselmann | if not self.disks: |
7254 | 942be002 | Michael Hanselmann | self.disks = range(len(self.instance.disks)) |
7255 | a9e0c397 | Iustin Pop | |
7256 | 2bb5c911 | Michael Hanselmann | for node in check_nodes: |
7257 | 2bb5c911 | Michael Hanselmann | _CheckNodeOnline(self.lu, node)
|
7258 | e4376078 | Iustin Pop | |
7259 | 2bb5c911 | Michael Hanselmann | # Check whether disks are valid
|
7260 | 2bb5c911 | Michael Hanselmann | for disk_idx in self.disks: |
7261 | e9022531 | Iustin Pop | instance.FindDisk(disk_idx) |
7262 | e4376078 | Iustin Pop | |
7263 | 2bb5c911 | Michael Hanselmann | # Get secondary node IP addresses
|
7264 | 2bb5c911 | Michael Hanselmann | node_2nd_ip = {} |
7265 | e4376078 | Iustin Pop | |
7266 | 2bb5c911 | Michael Hanselmann | for node_name in [self.target_node, self.other_node, self.new_node]: |
7267 | 2bb5c911 | Michael Hanselmann | if node_name is not None: |
7268 | 2bb5c911 | Michael Hanselmann | node_2nd_ip[node_name] = self.cfg.GetNodeInfo(node_name).secondary_ip
|
7269 | e4376078 | Iustin Pop | |
7270 | 2bb5c911 | Michael Hanselmann | self.node_secondary_ip = node_2nd_ip
|
7271 | a9e0c397 | Iustin Pop | |
7272 | c68174b6 | Michael Hanselmann | def Exec(self, feedback_fn): |
7273 | 2bb5c911 | Michael Hanselmann | """Execute disk replacement.
|
7274 | 2bb5c911 | Michael Hanselmann |
|
7275 | 2bb5c911 | Michael Hanselmann | This dispatches the disk replacement to the appropriate handler.
|
7276 | cff90b79 | Iustin Pop |
|
7277 | a9e0c397 | Iustin Pop | """
|
7278 | 94a1b377 | Michael Hanselmann | if self.delay_iallocator: |
7279 | 94a1b377 | Michael Hanselmann | self._CheckPrereq2()
|
7280 | 94a1b377 | Michael Hanselmann | |
7281 | 942be002 | Michael Hanselmann | if not self.disks: |
7282 | 942be002 | Michael Hanselmann | feedback_fn("No disks need replacement")
|
7283 | 942be002 | Michael Hanselmann | return
|
7284 | 942be002 | Michael Hanselmann | |
7285 | 942be002 | Michael Hanselmann | feedback_fn("Replacing disk(s) %s for %s" %
|
7286 | 1f864b60 | Iustin Pop | (utils.CommaJoin(self.disks), self.instance.name)) |
7287 | 7ffc5a86 | Michael Hanselmann | |
7288 | 2bb5c911 | Michael Hanselmann | activate_disks = (not self.instance.admin_up) |
7289 | 2bb5c911 | Michael Hanselmann | |
7290 | 2bb5c911 | Michael Hanselmann | # Activate the instance disks if we're replacing them on a down instance
|
7291 | 2bb5c911 | Michael Hanselmann | if activate_disks:
|
7292 | 2bb5c911 | Michael Hanselmann | _StartInstanceDisks(self.lu, self.instance, True) |
7293 | 2bb5c911 | Michael Hanselmann | |
7294 | 2bb5c911 | Michael Hanselmann | try:
|
7295 | 942be002 | Michael Hanselmann | # Should we replace the secondary node?
|
7296 | 942be002 | Michael Hanselmann | if self.new_node is not None: |
7297 | a4eae71f | Michael Hanselmann | fn = self._ExecDrbd8Secondary
|
7298 | 2bb5c911 | Michael Hanselmann | else:
|
7299 | a4eae71f | Michael Hanselmann | fn = self._ExecDrbd8DiskOnly
|
7300 | a4eae71f | Michael Hanselmann | |
7301 | a4eae71f | Michael Hanselmann | return fn(feedback_fn)
|
7302 | 2bb5c911 | Michael Hanselmann | |
7303 | 2bb5c911 | Michael Hanselmann | finally:
|
7304 | 5c983ee5 | Iustin Pop | # Deactivate the instance disks if we're replacing them on a
|
7305 | 5c983ee5 | Iustin Pop | # down instance
|
7306 | 2bb5c911 | Michael Hanselmann | if activate_disks:
|
7307 | 2bb5c911 | Michael Hanselmann | _SafeShutdownInstanceDisks(self.lu, self.instance) |
7308 | 2bb5c911 | Michael Hanselmann | |
7309 | 2bb5c911 | Michael Hanselmann | def _CheckVolumeGroup(self, nodes): |
7310 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Checking volume groups") |
7311 | 2bb5c911 | Michael Hanselmann | |
7312 | a9e0c397 | Iustin Pop | vgname = self.cfg.GetVGName()
|
7313 | cff90b79 | Iustin Pop | |
7314 | 2bb5c911 | Michael Hanselmann | # Make sure volume group exists on all involved nodes
|
7315 | 2bb5c911 | Michael Hanselmann | results = self.rpc.call_vg_list(nodes)
|
7316 | cff90b79 | Iustin Pop | if not results: |
7317 | cff90b79 | Iustin Pop | raise errors.OpExecError("Can't list volume groups on the nodes") |
7318 | 2bb5c911 | Michael Hanselmann | |
7319 | 2bb5c911 | Michael Hanselmann | for node in nodes: |
7320 | 781de953 | Iustin Pop | res = results[node] |
7321 | 4c4e4e1e | Iustin Pop | res.Raise("Error checking node %s" % node)
|
7322 | 2bb5c911 | Michael Hanselmann | if vgname not in res.payload: |
7323 | 2bb5c911 | Michael Hanselmann | raise errors.OpExecError("Volume group '%s' not found on node %s" % |
7324 | 2bb5c911 | Michael Hanselmann | (vgname, node)) |
7325 | 2bb5c911 | Michael Hanselmann | |
7326 | 2bb5c911 | Michael Hanselmann | def _CheckDisksExistence(self, nodes): |
7327 | 2bb5c911 | Michael Hanselmann | # Check disk existence
|
7328 | 2bb5c911 | Michael Hanselmann | for idx, dev in enumerate(self.instance.disks): |
7329 | 2bb5c911 | Michael Hanselmann | if idx not in self.disks: |
7330 | cff90b79 | Iustin Pop | continue
|
7331 | 2bb5c911 | Michael Hanselmann | |
7332 | 2bb5c911 | Michael Hanselmann | for node in nodes: |
7333 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Checking disk/%d on %s" % (idx, node)) |
7334 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(dev, node)
|
7335 | 2bb5c911 | Michael Hanselmann | |
7336 | 23829f6f | Iustin Pop | result = self.rpc.call_blockdev_find(node, dev)
|
7337 | 2bb5c911 | Michael Hanselmann | |
7338 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
7339 | 2bb5c911 | Michael Hanselmann | if msg or not result.payload: |
7340 | 2bb5c911 | Michael Hanselmann | if not msg: |
7341 | 2bb5c911 | Michael Hanselmann | msg = "disk not found"
|
7342 | 23829f6f | Iustin Pop | raise errors.OpExecError("Can't find disk/%d on node %s: %s" % |
7343 | 23829f6f | Iustin Pop | (idx, node, msg)) |
7344 | cff90b79 | Iustin Pop | |
7345 | 2bb5c911 | Michael Hanselmann | def _CheckDisksConsistency(self, node_name, on_primary, ldisk): |
7346 | 2bb5c911 | Michael Hanselmann | for idx, dev in enumerate(self.instance.disks): |
7347 | 2bb5c911 | Michael Hanselmann | if idx not in self.disks: |
7348 | cff90b79 | Iustin Pop | continue
|
7349 | cff90b79 | Iustin Pop | |
7350 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Checking disk/%d consistency on node %s" % |
7351 | 2bb5c911 | Michael Hanselmann | (idx, node_name)) |
7352 | 2bb5c911 | Michael Hanselmann | |
7353 | 2bb5c911 | Michael Hanselmann | if not _CheckDiskConsistency(self.lu, dev, node_name, on_primary, |
7354 | 2bb5c911 | Michael Hanselmann | ldisk=ldisk): |
7355 | 2bb5c911 | Michael Hanselmann | raise errors.OpExecError("Node %s has degraded storage, unsafe to" |
7356 | 2bb5c911 | Michael Hanselmann | " replace disks for instance %s" %
|
7357 | 2bb5c911 | Michael Hanselmann | (node_name, self.instance.name))
|
7358 | 2bb5c911 | Michael Hanselmann | |
7359 | 2bb5c911 | Michael Hanselmann | def _CreateNewStorage(self, node_name): |
7360 | 2bb5c911 | Michael Hanselmann | vgname = self.cfg.GetVGName()
|
7361 | 2bb5c911 | Michael Hanselmann | iv_names = {} |
7362 | 2bb5c911 | Michael Hanselmann | |
7363 | 2bb5c911 | Michael Hanselmann | for idx, dev in enumerate(self.instance.disks): |
7364 | 2bb5c911 | Michael Hanselmann | if idx not in self.disks: |
7365 | a9e0c397 | Iustin Pop | continue
|
7366 | 2bb5c911 | Michael Hanselmann | |
7367 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Adding storage on %s for disk/%d" % (node_name, idx)) |
7368 | 2bb5c911 | Michael Hanselmann | |
7369 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(dev, node_name)
|
7370 | 2bb5c911 | Michael Hanselmann | |
7371 | 2bb5c911 | Michael Hanselmann | lv_names = [".disk%d_%s" % (idx, suffix) for suffix in ["data", "meta"]] |
7372 | 2bb5c911 | Michael Hanselmann | names = _GenerateUniqueNames(self.lu, lv_names)
|
7373 | 2bb5c911 | Michael Hanselmann | |
7374 | 2bb5c911 | Michael Hanselmann | lv_data = objects.Disk(dev_type=constants.LD_LV, size=dev.size, |
7375 | a9e0c397 | Iustin Pop | logical_id=(vgname, names[0]))
|
7376 | a9e0c397 | Iustin Pop | lv_meta = objects.Disk(dev_type=constants.LD_LV, size=128,
|
7377 | a9e0c397 | Iustin Pop | logical_id=(vgname, names[1]))
|
7378 | 2bb5c911 | Michael Hanselmann | |
7379 | a9e0c397 | Iustin Pop | new_lvs = [lv_data, lv_meta] |
7380 | a9e0c397 | Iustin Pop | old_lvs = dev.children |
7381 | a9e0c397 | Iustin Pop | iv_names[dev.iv_name] = (dev, old_lvs, new_lvs) |
7382 | 2bb5c911 | Michael Hanselmann | |
7383 | 428958aa | Iustin Pop | # we pass force_create=True to force the LVM creation
|
7384 | a9e0c397 | Iustin Pop | for new_lv in new_lvs: |
7385 | 2bb5c911 | Michael Hanselmann | _CreateBlockDev(self.lu, node_name, self.instance, new_lv, True, |
7386 | 2bb5c911 | Michael Hanselmann | _GetInstanceInfoText(self.instance), False) |
7387 | 2bb5c911 | Michael Hanselmann | |
7388 | 2bb5c911 | Michael Hanselmann | return iv_names
|
7389 | 2bb5c911 | Michael Hanselmann | |
7390 | 2bb5c911 | Michael Hanselmann | def _CheckDevices(self, node_name, iv_names): |
7391 | 1122eb25 | Iustin Pop | for name, (dev, _, _) in iv_names.iteritems(): |
7392 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(dev, node_name)
|
7393 | 2bb5c911 | Michael Hanselmann | |
7394 | 2bb5c911 | Michael Hanselmann | result = self.rpc.call_blockdev_find(node_name, dev)
|
7395 | 2bb5c911 | Michael Hanselmann | |
7396 | 2bb5c911 | Michael Hanselmann | msg = result.fail_msg |
7397 | 2bb5c911 | Michael Hanselmann | if msg or not result.payload: |
7398 | 2bb5c911 | Michael Hanselmann | if not msg: |
7399 | 2bb5c911 | Michael Hanselmann | msg = "disk not found"
|
7400 | 2bb5c911 | Michael Hanselmann | raise errors.OpExecError("Can't find DRBD device %s: %s" % |
7401 | 2bb5c911 | Michael Hanselmann | (name, msg)) |
7402 | 2bb5c911 | Michael Hanselmann | |
7403 | 96acbc09 | Michael Hanselmann | if result.payload.is_degraded:
|
7404 | 2bb5c911 | Michael Hanselmann | raise errors.OpExecError("DRBD device %s is degraded!" % name) |
7405 | 2bb5c911 | Michael Hanselmann | |
7406 | 2bb5c911 | Michael Hanselmann | def _RemoveOldStorage(self, node_name, iv_names): |
7407 | 1122eb25 | Iustin Pop | for name, (_, old_lvs, _) in iv_names.iteritems(): |
7408 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Remove logical volumes for %s" % name) |
7409 | 2bb5c911 | Michael Hanselmann | |
7410 | 2bb5c911 | Michael Hanselmann | for lv in old_lvs: |
7411 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(lv, node_name)
|
7412 | 2bb5c911 | Michael Hanselmann | |
7413 | 2bb5c911 | Michael Hanselmann | msg = self.rpc.call_blockdev_remove(node_name, lv).fail_msg
|
7414 | 2bb5c911 | Michael Hanselmann | if msg:
|
7415 | 2bb5c911 | Michael Hanselmann | self.lu.LogWarning("Can't remove old LV: %s" % msg, |
7416 | 2bb5c911 | Michael Hanselmann | hint="remove unused LVs manually")
|
7417 | 2bb5c911 | Michael Hanselmann | |
7418 | 7ea7bcf6 | Iustin Pop | def _ReleaseNodeLock(self, node_name): |
7419 | 7ea7bcf6 | Iustin Pop | """Releases the lock for a given node."""
|
7420 | 7ea7bcf6 | Iustin Pop | self.lu.context.glm.release(locking.LEVEL_NODE, node_name)
|
7421 | 7ea7bcf6 | Iustin Pop | |
7422 | a4eae71f | Michael Hanselmann | def _ExecDrbd8DiskOnly(self, feedback_fn): |
7423 | 2bb5c911 | Michael Hanselmann | """Replace a disk on the primary or secondary for DRBD 8.
|
7424 | 2bb5c911 | Michael Hanselmann |
|
7425 | 2bb5c911 | Michael Hanselmann | The algorithm for replace is quite complicated:
|
7426 | 2bb5c911 | Michael Hanselmann |
|
7427 | 2bb5c911 | Michael Hanselmann | 1. for each disk to be replaced:
|
7428 | 2bb5c911 | Michael Hanselmann |
|
7429 | 2bb5c911 | Michael Hanselmann | 1. create new LVs on the target node with unique names
|
7430 | 2bb5c911 | Michael Hanselmann | 1. detach old LVs from the drbd device
|
7431 | 2bb5c911 | Michael Hanselmann | 1. rename old LVs to name_replaced.<time_t>
|
7432 | 2bb5c911 | Michael Hanselmann | 1. rename new LVs to old LVs
|
7433 | 2bb5c911 | Michael Hanselmann | 1. attach the new LVs (with the old names now) to the drbd device
|
7434 | 2bb5c911 | Michael Hanselmann |
|
7435 | 2bb5c911 | Michael Hanselmann | 1. wait for sync across all devices
|
7436 | 2bb5c911 | Michael Hanselmann |
|
7437 | 2bb5c911 | Michael Hanselmann | 1. for each modified disk:
|
7438 | 2bb5c911 | Michael Hanselmann |
|
7439 | 2bb5c911 | Michael Hanselmann | 1. remove old LVs (which have the name name_replaces.<time_t>)
|
7440 | 2bb5c911 | Michael Hanselmann |
|
7441 | 2bb5c911 | Michael Hanselmann | Failures are not very well handled.
|
7442 | 2bb5c911 | Michael Hanselmann |
|
7443 | 2bb5c911 | Michael Hanselmann | """
|
7444 | 2bb5c911 | Michael Hanselmann | steps_total = 6
|
7445 | 2bb5c911 | Michael Hanselmann | |
7446 | 2bb5c911 | Michael Hanselmann | # Step: check device activation
|
7447 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(1, steps_total, "Check device existence") |
7448 | 2bb5c911 | Michael Hanselmann | self._CheckDisksExistence([self.other_node, self.target_node]) |
7449 | 2bb5c911 | Michael Hanselmann | self._CheckVolumeGroup([self.target_node, self.other_node]) |
7450 | 2bb5c911 | Michael Hanselmann | |
7451 | 2bb5c911 | Michael Hanselmann | # Step: check other node consistency
|
7452 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(2, steps_total, "Check peer consistency") |
7453 | 2bb5c911 | Michael Hanselmann | self._CheckDisksConsistency(self.other_node, |
7454 | 2bb5c911 | Michael Hanselmann | self.other_node == self.instance.primary_node, |
7455 | 2bb5c911 | Michael Hanselmann | False)
|
7456 | 2bb5c911 | Michael Hanselmann | |
7457 | 2bb5c911 | Michael Hanselmann | # Step: create new storage
|
7458 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(3, steps_total, "Allocate new storage") |
7459 | 2bb5c911 | Michael Hanselmann | iv_names = self._CreateNewStorage(self.target_node) |
7460 | a9e0c397 | Iustin Pop | |
7461 | cff90b79 | Iustin Pop | # Step: for each lv, detach+rename*2+attach
|
7462 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(4, steps_total, "Changing drbd configuration") |
7463 | cff90b79 | Iustin Pop | for dev, old_lvs, new_lvs in iv_names.itervalues(): |
7464 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Detaching %s drbd from local storage" % dev.iv_name) |
7465 | 2bb5c911 | Michael Hanselmann | |
7466 | 4d4a651d | Michael Hanselmann | result = self.rpc.call_blockdev_removechildren(self.target_node, dev, |
7467 | 4d4a651d | Michael Hanselmann | old_lvs) |
7468 | 4c4e4e1e | Iustin Pop | result.Raise("Can't detach drbd from local storage on node"
|
7469 | 2bb5c911 | Michael Hanselmann | " %s for device %s" % (self.target_node, dev.iv_name)) |
7470 | cff90b79 | Iustin Pop | #dev.children = []
|
7471 | cff90b79 | Iustin Pop | #cfg.Update(instance)
|
7472 | a9e0c397 | Iustin Pop | |
7473 | a9e0c397 | Iustin Pop | # ok, we created the new LVs, so now we know we have the needed
|
7474 | a9e0c397 | Iustin Pop | # storage; as such, we proceed on the target node to rename
|
7475 | a9e0c397 | Iustin Pop | # old_lv to _old, and new_lv to old_lv; note that we rename LVs
|
7476 | c99a3cc0 | Manuel Franceschini | # using the assumption that logical_id == physical_id (which in
|
7477 | a9e0c397 | Iustin Pop | # turn is the unique_id on that node)
|
7478 | cff90b79 | Iustin Pop | |
7479 | cff90b79 | Iustin Pop | # FIXME(iustin): use a better name for the replaced LVs
|
7480 | a9e0c397 | Iustin Pop | temp_suffix = int(time.time())
|
7481 | a9e0c397 | Iustin Pop | ren_fn = lambda d, suff: (d.physical_id[0], |
7482 | a9e0c397 | Iustin Pop | d.physical_id[1] + "_replaced-%s" % suff) |
7483 | 2bb5c911 | Michael Hanselmann | |
7484 | 2bb5c911 | Michael Hanselmann | # Build the rename list based on what LVs exist on the node
|
7485 | 2bb5c911 | Michael Hanselmann | rename_old_to_new = [] |
7486 | cff90b79 | Iustin Pop | for to_ren in old_lvs: |
7487 | 2bb5c911 | Michael Hanselmann | result = self.rpc.call_blockdev_find(self.target_node, to_ren) |
7488 | 4c4e4e1e | Iustin Pop | if not result.fail_msg and result.payload: |
7489 | 23829f6f | Iustin Pop | # device exists
|
7490 | 2bb5c911 | Michael Hanselmann | rename_old_to_new.append((to_ren, ren_fn(to_ren, temp_suffix))) |
7491 | cff90b79 | Iustin Pop | |
7492 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Renaming the old LVs on the target node") |
7493 | 4d4a651d | Michael Hanselmann | result = self.rpc.call_blockdev_rename(self.target_node, |
7494 | 4d4a651d | Michael Hanselmann | rename_old_to_new) |
7495 | 2bb5c911 | Michael Hanselmann | result.Raise("Can't rename old LVs on node %s" % self.target_node) |
7496 | 2bb5c911 | Michael Hanselmann | |
7497 | 2bb5c911 | Michael Hanselmann | # Now we rename the new LVs to the old LVs
|
7498 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Renaming the new LVs on the target node") |
7499 | 2bb5c911 | Michael Hanselmann | rename_new_to_old = [(new, old.physical_id) |
7500 | 2bb5c911 | Michael Hanselmann | for old, new in zip(old_lvs, new_lvs)] |
7501 | 4d4a651d | Michael Hanselmann | result = self.rpc.call_blockdev_rename(self.target_node, |
7502 | 4d4a651d | Michael Hanselmann | rename_new_to_old) |
7503 | 2bb5c911 | Michael Hanselmann | result.Raise("Can't rename new LVs on node %s" % self.target_node) |
7504 | cff90b79 | Iustin Pop | |
7505 | cff90b79 | Iustin Pop | for old, new in zip(old_lvs, new_lvs): |
7506 | cff90b79 | Iustin Pop | new.logical_id = old.logical_id |
7507 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(new, self.target_node) |
7508 | a9e0c397 | Iustin Pop | |
7509 | cff90b79 | Iustin Pop | for disk in old_lvs: |
7510 | cff90b79 | Iustin Pop | disk.logical_id = ren_fn(disk, temp_suffix) |
7511 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(disk, self.target_node) |
7512 | a9e0c397 | Iustin Pop | |
7513 | 2bb5c911 | Michael Hanselmann | # Now that the new lvs have the old name, we can add them to the device
|
7514 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Adding new mirror component on %s" % self.target_node) |
7515 | 4d4a651d | Michael Hanselmann | result = self.rpc.call_blockdev_addchildren(self.target_node, dev, |
7516 | 4d4a651d | Michael Hanselmann | new_lvs) |
7517 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
7518 | 2cc1da8b | Iustin Pop | if msg:
|
7519 | a9e0c397 | Iustin Pop | for new_lv in new_lvs: |
7520 | 4d4a651d | Michael Hanselmann | msg2 = self.rpc.call_blockdev_remove(self.target_node, |
7521 | 4d4a651d | Michael Hanselmann | new_lv).fail_msg |
7522 | 4c4e4e1e | Iustin Pop | if msg2:
|
7523 | 2bb5c911 | Michael Hanselmann | self.lu.LogWarning("Can't rollback device %s: %s", dev, msg2, |
7524 | 2bb5c911 | Michael Hanselmann | hint=("cleanup manually the unused logical"
|
7525 | 2bb5c911 | Michael Hanselmann | "volumes"))
|
7526 | 2cc1da8b | Iustin Pop | raise errors.OpExecError("Can't add local storage to drbd: %s" % msg) |
7527 | a9e0c397 | Iustin Pop | |
7528 | a9e0c397 | Iustin Pop | dev.children = new_lvs |
7529 | a9e0c397 | Iustin Pop | |
7530 | a4eae71f | Michael Hanselmann | self.cfg.Update(self.instance, feedback_fn) |
7531 | a9e0c397 | Iustin Pop | |
7532 | 7ea7bcf6 | Iustin Pop | cstep = 5
|
7533 | 7ea7bcf6 | Iustin Pop | if self.early_release: |
7534 | 7ea7bcf6 | Iustin Pop | self.lu.LogStep(cstep, steps_total, "Removing old storage") |
7535 | 7ea7bcf6 | Iustin Pop | cstep += 1
|
7536 | 7ea7bcf6 | Iustin Pop | self._RemoveOldStorage(self.target_node, iv_names) |
7537 | d5cd389c | Iustin Pop | # WARNING: we release both node locks here, do not do other RPCs
|
7538 | d5cd389c | Iustin Pop | # than WaitForSync to the primary node
|
7539 | d5cd389c | Iustin Pop | self._ReleaseNodeLock([self.target_node, self.other_node]) |
7540 | 7ea7bcf6 | Iustin Pop | |
7541 | 2bb5c911 | Michael Hanselmann | # Wait for sync
|
7542 | 2bb5c911 | Michael Hanselmann | # This can fail as the old devices are degraded and _WaitForSync
|
7543 | 2bb5c911 | Michael Hanselmann | # does a combined result over all disks, so we don't check its return value
|
7544 | 7ea7bcf6 | Iustin Pop | self.lu.LogStep(cstep, steps_total, "Sync devices") |
7545 | 7ea7bcf6 | Iustin Pop | cstep += 1
|
7546 | b6c07b79 | Michael Hanselmann | _WaitForSync(self.lu, self.instance) |
7547 | a9e0c397 | Iustin Pop | |
7548 | 2bb5c911 | Michael Hanselmann | # Check all devices manually
|
7549 | 2bb5c911 | Michael Hanselmann | self._CheckDevices(self.instance.primary_node, iv_names) |
7550 | a9e0c397 | Iustin Pop | |
7551 | cff90b79 | Iustin Pop | # Step: remove old storage
|
7552 | 7ea7bcf6 | Iustin Pop | if not self.early_release: |
7553 | 7ea7bcf6 | Iustin Pop | self.lu.LogStep(cstep, steps_total, "Removing old storage") |
7554 | 7ea7bcf6 | Iustin Pop | cstep += 1
|
7555 | 7ea7bcf6 | Iustin Pop | self._RemoveOldStorage(self.target_node, iv_names) |
7556 | a9e0c397 | Iustin Pop | |
7557 | a4eae71f | Michael Hanselmann | def _ExecDrbd8Secondary(self, feedback_fn): |
7558 | 2bb5c911 | Michael Hanselmann | """Replace the secondary node for DRBD 8.
|
7559 | a9e0c397 | Iustin Pop |
|
7560 | a9e0c397 | Iustin Pop | The algorithm for replace is quite complicated:
|
7561 | a9e0c397 | Iustin Pop | - for all disks of the instance:
|
7562 | a9e0c397 | Iustin Pop | - create new LVs on the new node with same names
|
7563 | a9e0c397 | Iustin Pop | - shutdown the drbd device on the old secondary
|
7564 | a9e0c397 | Iustin Pop | - disconnect the drbd network on the primary
|
7565 | a9e0c397 | Iustin Pop | - create the drbd device on the new secondary
|
7566 | a9e0c397 | Iustin Pop | - network attach the drbd on the primary, using an artifice:
|
7567 | a9e0c397 | Iustin Pop | the drbd code for Attach() will connect to the network if it
|
7568 | a9e0c397 | Iustin Pop | finds a device which is connected to the good local disks but
|
7569 | a9e0c397 | Iustin Pop | not network enabled
|
7570 | a9e0c397 | Iustin Pop | - wait for sync across all devices
|
7571 | a9e0c397 | Iustin Pop | - remove all disks from the old secondary
|
7572 | a9e0c397 | Iustin Pop |
|
7573 | a9e0c397 | Iustin Pop | Failures are not very well handled.
|
7574 | 0834c866 | Iustin Pop |
|
7575 | a9e0c397 | Iustin Pop | """
|
7576 | 0834c866 | Iustin Pop | steps_total = 6
|
7577 | 0834c866 | Iustin Pop | |
7578 | 0834c866 | Iustin Pop | # Step: check device activation
|
7579 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(1, steps_total, "Check device existence") |
7580 | 2bb5c911 | Michael Hanselmann | self._CheckDisksExistence([self.instance.primary_node]) |
7581 | 2bb5c911 | Michael Hanselmann | self._CheckVolumeGroup([self.instance.primary_node]) |
7582 | 0834c866 | Iustin Pop | |
7583 | 0834c866 | Iustin Pop | # Step: check other node consistency
|
7584 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(2, steps_total, "Check peer consistency") |
7585 | 2bb5c911 | Michael Hanselmann | self._CheckDisksConsistency(self.instance.primary_node, True, True) |
7586 | 0834c866 | Iustin Pop | |
7587 | 0834c866 | Iustin Pop | # Step: create new storage
|
7588 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(3, steps_total, "Allocate new storage") |
7589 | 2bb5c911 | Michael Hanselmann | for idx, dev in enumerate(self.instance.disks): |
7590 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Adding new local storage on %s for disk/%d" % |
7591 | 2bb5c911 | Michael Hanselmann | (self.new_node, idx))
|
7592 | 428958aa | Iustin Pop | # we pass force_create=True to force LVM creation
|
7593 | a9e0c397 | Iustin Pop | for new_lv in dev.children: |
7594 | 2bb5c911 | Michael Hanselmann | _CreateBlockDev(self.lu, self.new_node, self.instance, new_lv, True, |
7595 | 2bb5c911 | Michael Hanselmann | _GetInstanceInfoText(self.instance), False) |
7596 | a9e0c397 | Iustin Pop | |
7597 | 468b46f9 | Iustin Pop | # Step 4: dbrd minors and drbd setups changes
|
7598 | a1578d63 | Iustin Pop | # after this, we must manually remove the drbd minors on both the
|
7599 | a1578d63 | Iustin Pop | # error and the success paths
|
7600 | 2bb5c911 | Michael Hanselmann | self.lu.LogStep(4, steps_total, "Changing drbd configuration") |
7601 | 4d4a651d | Michael Hanselmann | minors = self.cfg.AllocateDRBDMinor([self.new_node |
7602 | 4d4a651d | Michael Hanselmann | for dev in self.instance.disks], |
7603 | 2bb5c911 | Michael Hanselmann | self.instance.name)
|
7604 | 099c52ad | Iustin Pop | logging.debug("Allocated minors %r", minors)
|
7605 | 2bb5c911 | Michael Hanselmann | |
7606 | 2bb5c911 | Michael Hanselmann | iv_names = {} |
7607 | 2bb5c911 | Michael Hanselmann | for idx, (dev, new_minor) in enumerate(zip(self.instance.disks, minors)): |
7608 | 4d4a651d | Michael Hanselmann | self.lu.LogInfo("activating a new drbd on %s for disk/%d" % |
7609 | 4d4a651d | Michael Hanselmann | (self.new_node, idx))
|
7610 | a2d59d8b | Iustin Pop | # create new devices on new_node; note that we create two IDs:
|
7611 | a2d59d8b | Iustin Pop | # one without port, so the drbd will be activated without
|
7612 | a2d59d8b | Iustin Pop | # networking information on the new node at this stage, and one
|
7613 | a2d59d8b | Iustin Pop | # with network, for the latter activation in step 4
|
7614 | a2d59d8b | Iustin Pop | (o_node1, o_node2, o_port, o_minor1, o_minor2, o_secret) = dev.logical_id |
7615 | 2bb5c911 | Michael Hanselmann | if self.instance.primary_node == o_node1: |
7616 | a2d59d8b | Iustin Pop | p_minor = o_minor1 |
7617 | ffa1c0dc | Iustin Pop | else:
|
7618 | 1122eb25 | Iustin Pop | assert self.instance.primary_node == o_node2, "Three-node instance?" |
7619 | a2d59d8b | Iustin Pop | p_minor = o_minor2 |
7620 | a2d59d8b | Iustin Pop | |
7621 | 4d4a651d | Michael Hanselmann | new_alone_id = (self.instance.primary_node, self.new_node, None, |
7622 | 4d4a651d | Michael Hanselmann | p_minor, new_minor, o_secret) |
7623 | 4d4a651d | Michael Hanselmann | new_net_id = (self.instance.primary_node, self.new_node, o_port, |
7624 | 4d4a651d | Michael Hanselmann | p_minor, new_minor, o_secret) |
7625 | a2d59d8b | Iustin Pop | |
7626 | a2d59d8b | Iustin Pop | iv_names[idx] = (dev, dev.children, new_net_id) |
7627 | a1578d63 | Iustin Pop | logging.debug("Allocated new_minor: %s, new_logical_id: %s", new_minor,
|
7628 | a2d59d8b | Iustin Pop | new_net_id) |
7629 | a9e0c397 | Iustin Pop | new_drbd = objects.Disk(dev_type=constants.LD_DRBD8, |
7630 | a2d59d8b | Iustin Pop | logical_id=new_alone_id, |
7631 | 8a6c7011 | Iustin Pop | children=dev.children, |
7632 | 8a6c7011 | Iustin Pop | size=dev.size) |
7633 | 796cab27 | Iustin Pop | try:
|
7634 | 2bb5c911 | Michael Hanselmann | _CreateSingleBlockDev(self.lu, self.new_node, self.instance, new_drbd, |
7635 | 2bb5c911 | Michael Hanselmann | _GetInstanceInfoText(self.instance), False) |
7636 | 82759cb1 | Iustin Pop | except errors.GenericError:
|
7637 | 2bb5c911 | Michael Hanselmann | self.cfg.ReleaseDRBDMinors(self.instance.name) |
7638 | 796cab27 | Iustin Pop | raise
|
7639 | a9e0c397 | Iustin Pop | |
7640 | 2bb5c911 | Michael Hanselmann | # We have new devices, shutdown the drbd on the old secondary
|
7641 | 2bb5c911 | Michael Hanselmann | for idx, dev in enumerate(self.instance.disks): |
7642 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Shutting down drbd for disk/%d on old node" % idx) |
7643 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(dev, self.target_node) |
7644 | 2bb5c911 | Michael Hanselmann | msg = self.rpc.call_blockdev_shutdown(self.target_node, dev).fail_msg |
7645 | cacfd1fd | Iustin Pop | if msg:
|
7646 | 2bb5c911 | Michael Hanselmann | self.lu.LogWarning("Failed to shutdown drbd for disk/%d on old" |
7647 | 2bb5c911 | Michael Hanselmann | "node: %s" % (idx, msg),
|
7648 | 2bb5c911 | Michael Hanselmann | hint=("Please cleanup this device manually as"
|
7649 | 2bb5c911 | Michael Hanselmann | " soon as possible"))
|
7650 | a9e0c397 | Iustin Pop | |
7651 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Detaching primary drbds from the network (=> standalone)") |
7652 | 4d4a651d | Michael Hanselmann | result = self.rpc.call_drbd_disconnect_net([self.instance.primary_node], |
7653 | 4d4a651d | Michael Hanselmann | self.node_secondary_ip,
|
7654 | 4d4a651d | Michael Hanselmann | self.instance.disks)\
|
7655 | 4d4a651d | Michael Hanselmann | [self.instance.primary_node]
|
7656 | 642445d9 | Iustin Pop | |
7657 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
7658 | a2d59d8b | Iustin Pop | if msg:
|
7659 | a2d59d8b | Iustin Pop | # detaches didn't succeed (unlikely)
|
7660 | 2bb5c911 | Michael Hanselmann | self.cfg.ReleaseDRBDMinors(self.instance.name) |
7661 | a2d59d8b | Iustin Pop | raise errors.OpExecError("Can't detach the disks from the network on" |
7662 | a2d59d8b | Iustin Pop | " old node: %s" % (msg,))
|
7663 | 642445d9 | Iustin Pop | |
7664 | 642445d9 | Iustin Pop | # if we managed to detach at least one, we update all the disks of
|
7665 | 642445d9 | Iustin Pop | # the instance to point to the new secondary
|
7666 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Updating instance configuration") |
7667 | 468b46f9 | Iustin Pop | for dev, _, new_logical_id in iv_names.itervalues(): |
7668 | 468b46f9 | Iustin Pop | dev.logical_id = new_logical_id |
7669 | 2bb5c911 | Michael Hanselmann | self.cfg.SetDiskID(dev, self.instance.primary_node) |
7670 | 2bb5c911 | Michael Hanselmann | |
7671 | a4eae71f | Michael Hanselmann | self.cfg.Update(self.instance, feedback_fn) |
7672 | a9e0c397 | Iustin Pop | |
7673 | 642445d9 | Iustin Pop | # and now perform the drbd attach
|
7674 | 2bb5c911 | Michael Hanselmann | self.lu.LogInfo("Attaching primary drbds to new secondary" |
7675 | 2bb5c911 | Michael Hanselmann | " (standalone => connected)")
|
7676 | 4d4a651d | Michael Hanselmann | result = self.rpc.call_drbd_attach_net([self.instance.primary_node, |
7677 | 4d4a651d | Michael Hanselmann | self.new_node],
|
7678 | 4d4a651d | Michael Hanselmann | self.node_secondary_ip,
|
7679 | 4d4a651d | Michael Hanselmann | self.instance.disks,
|
7680 | 4d4a651d | Michael Hanselmann | self.instance.name,
|
7681 | a2d59d8b | Iustin Pop | False)
|
7682 | a2d59d8b | Iustin Pop | for to_node, to_result in result.items(): |
7683 | 4c4e4e1e | Iustin Pop | msg = to_result.fail_msg |
7684 | a2d59d8b | Iustin Pop | if msg:
|
7685 | 4d4a651d | Michael Hanselmann | self.lu.LogWarning("Can't attach drbd disks on node %s: %s", |
7686 | 4d4a651d | Michael Hanselmann | to_node, msg, |
7687 | 2bb5c911 | Michael Hanselmann | hint=("please do a gnt-instance info to see the"
|
7688 | 2bb5c911 | Michael Hanselmann | " status of disks"))
|
7689 | 7ea7bcf6 | Iustin Pop | cstep = 5
|
7690 | 7ea7bcf6 | Iustin Pop | if self.early_release: |
7691 | 7ea7bcf6 | Iustin Pop | self.lu.LogStep(cstep, steps_total, "Removing old storage") |
7692 | 7ea7bcf6 | Iustin Pop | cstep += 1
|
7693 | 7ea7bcf6 | Iustin Pop | self._RemoveOldStorage(self.target_node, iv_names) |
7694 | d5cd389c | Iustin Pop | # WARNING: we release all node locks here, do not do other RPCs
|
7695 | d5cd389c | Iustin Pop | # than WaitForSync to the primary node
|
7696 | d5cd389c | Iustin Pop | self._ReleaseNodeLock([self.instance.primary_node, |
7697 | d5cd389c | Iustin Pop | self.target_node,
|
7698 | d5cd389c | Iustin Pop | self.new_node])
|
7699 | a9e0c397 | Iustin Pop | |
7700 | 2bb5c911 | Michael Hanselmann | # Wait for sync
|
7701 | 2bb5c911 | Michael Hanselmann | # This can fail as the old devices are degraded and _WaitForSync
|
7702 | 2bb5c911 | Michael Hanselmann | # does a combined result over all disks, so we don't check its return value
|
7703 | 7ea7bcf6 | Iustin Pop | self.lu.LogStep(cstep, steps_total, "Sync devices") |
7704 | 7ea7bcf6 | Iustin Pop | cstep += 1
|
7705 | b6c07b79 | Michael Hanselmann | _WaitForSync(self.lu, self.instance) |
7706 | a9e0c397 | Iustin Pop | |
7707 | 2bb5c911 | Michael Hanselmann | # Check all devices manually
|
7708 | 2bb5c911 | Michael Hanselmann | self._CheckDevices(self.instance.primary_node, iv_names) |
7709 | 22985314 | Guido Trotter | |
7710 | 2bb5c911 | Michael Hanselmann | # Step: remove old storage
|
7711 | 7ea7bcf6 | Iustin Pop | if not self.early_release: |
7712 | 7ea7bcf6 | Iustin Pop | self.lu.LogStep(cstep, steps_total, "Removing old storage") |
7713 | 7ea7bcf6 | Iustin Pop | self._RemoveOldStorage(self.target_node, iv_names) |
7714 | a9e0c397 | Iustin Pop | |
7715 | a8083063 | Iustin Pop | |
7716 | 76aef8fc | Michael Hanselmann | class LURepairNodeStorage(NoHooksLU): |
7717 | 76aef8fc | Michael Hanselmann | """Repairs the volume group on a node.
|
7718 | 76aef8fc | Michael Hanselmann |
|
7719 | 76aef8fc | Michael Hanselmann | """
|
7720 | 76aef8fc | Michael Hanselmann | _OP_REQP = ["node_name"]
|
7721 | 76aef8fc | Michael Hanselmann | REQ_BGL = False
|
7722 | 76aef8fc | Michael Hanselmann | |
7723 | 76aef8fc | Michael Hanselmann | def CheckArguments(self): |
7724 | cf26a87a | Iustin Pop | self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name) |
7725 | 76aef8fc | Michael Hanselmann | |
7726 | 0e3baaf3 | Iustin Pop | _CheckStorageType(self.op.storage_type)
|
7727 | 0e3baaf3 | Iustin Pop | |
7728 | 76aef8fc | Michael Hanselmann | def ExpandNames(self): |
7729 | 76aef8fc | Michael Hanselmann | self.needed_locks = {
|
7730 | 76aef8fc | Michael Hanselmann | locking.LEVEL_NODE: [self.op.node_name],
|
7731 | 76aef8fc | Michael Hanselmann | } |
7732 | 76aef8fc | Michael Hanselmann | |
7733 | 76aef8fc | Michael Hanselmann | def _CheckFaultyDisks(self, instance, node_name): |
7734 | 7e9c6a78 | Iustin Pop | """Ensure faulty disks abort the opcode or at least warn."""
|
7735 | 7e9c6a78 | Iustin Pop | try:
|
7736 | 7e9c6a78 | Iustin Pop | if _FindFaultyInstanceDisks(self.cfg, self.rpc, instance, |
7737 | 7e9c6a78 | Iustin Pop | node_name, True):
|
7738 | 7e9c6a78 | Iustin Pop | raise errors.OpPrereqError("Instance '%s' has faulty disks on" |
7739 | 7e9c6a78 | Iustin Pop | " node '%s'" % (instance.name, node_name),
|
7740 | 7e9c6a78 | Iustin Pop | errors.ECODE_STATE) |
7741 | 7e9c6a78 | Iustin Pop | except errors.OpPrereqError, err:
|
7742 | 7e9c6a78 | Iustin Pop | if self.op.ignore_consistency: |
7743 | 7e9c6a78 | Iustin Pop | self.proc.LogWarning(str(err.args[0])) |
7744 | 7e9c6a78 | Iustin Pop | else:
|
7745 | 7e9c6a78 | Iustin Pop | raise
|
7746 | 76aef8fc | Michael Hanselmann | |
7747 | 76aef8fc | Michael Hanselmann | def CheckPrereq(self): |
7748 | 76aef8fc | Michael Hanselmann | """Check prerequisites.
|
7749 | 76aef8fc | Michael Hanselmann |
|
7750 | 76aef8fc | Michael Hanselmann | """
|
7751 | 76aef8fc | Michael Hanselmann | storage_type = self.op.storage_type
|
7752 | 76aef8fc | Michael Hanselmann | |
7753 | 76aef8fc | Michael Hanselmann | if (constants.SO_FIX_CONSISTENCY not in |
7754 | 76aef8fc | Michael Hanselmann | constants.VALID_STORAGE_OPERATIONS.get(storage_type, [])): |
7755 | 76aef8fc | Michael Hanselmann | raise errors.OpPrereqError("Storage units of type '%s' can not be" |
7756 | 5c983ee5 | Iustin Pop | " repaired" % storage_type,
|
7757 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
7758 | 76aef8fc | Michael Hanselmann | |
7759 | 76aef8fc | Michael Hanselmann | # Check whether any instance on this node has faulty disks
|
7760 | 76aef8fc | Michael Hanselmann | for inst in _GetNodeInstances(self.cfg, self.op.node_name): |
7761 | 7e9c6a78 | Iustin Pop | if not inst.admin_up: |
7762 | 7e9c6a78 | Iustin Pop | continue
|
7763 | 76aef8fc | Michael Hanselmann | check_nodes = set(inst.all_nodes)
|
7764 | 76aef8fc | Michael Hanselmann | check_nodes.discard(self.op.node_name)
|
7765 | 76aef8fc | Michael Hanselmann | for inst_node_name in check_nodes: |
7766 | 76aef8fc | Michael Hanselmann | self._CheckFaultyDisks(inst, inst_node_name)
|
7767 | 76aef8fc | Michael Hanselmann | |
7768 | 76aef8fc | Michael Hanselmann | def Exec(self, feedback_fn): |
7769 | 76aef8fc | Michael Hanselmann | feedback_fn("Repairing storage unit '%s' on %s ..." %
|
7770 | 76aef8fc | Michael Hanselmann | (self.op.name, self.op.node_name)) |
7771 | 76aef8fc | Michael Hanselmann | |
7772 | 76aef8fc | Michael Hanselmann | st_args = _GetStorageTypeArgs(self.cfg, self.op.storage_type) |
7773 | 76aef8fc | Michael Hanselmann | result = self.rpc.call_storage_execute(self.op.node_name, |
7774 | 76aef8fc | Michael Hanselmann | self.op.storage_type, st_args,
|
7775 | 76aef8fc | Michael Hanselmann | self.op.name,
|
7776 | 76aef8fc | Michael Hanselmann | constants.SO_FIX_CONSISTENCY) |
7777 | 76aef8fc | Michael Hanselmann | result.Raise("Failed to repair storage unit '%s' on %s" %
|
7778 | 76aef8fc | Michael Hanselmann | (self.op.name, self.op.node_name)) |
7779 | 76aef8fc | Michael Hanselmann | |
7780 | 76aef8fc | Michael Hanselmann | |
7781 | f7e7689f | Iustin Pop | class LUNodeEvacuationStrategy(NoHooksLU): |
7782 | f7e7689f | Iustin Pop | """Computes the node evacuation strategy.
|
7783 | f7e7689f | Iustin Pop |
|
7784 | f7e7689f | Iustin Pop | """
|
7785 | f7e7689f | Iustin Pop | _OP_REQP = ["nodes"]
|
7786 | f7e7689f | Iustin Pop | REQ_BGL = False
|
7787 | f7e7689f | Iustin Pop | |
7788 | f7e7689f | Iustin Pop | def CheckArguments(self): |
7789 | f7e7689f | Iustin Pop | if not hasattr(self.op, "remote_node"): |
7790 | f7e7689f | Iustin Pop | self.op.remote_node = None |
7791 | f7e7689f | Iustin Pop | if not hasattr(self.op, "iallocator"): |
7792 | f7e7689f | Iustin Pop | self.op.iallocator = None |
7793 | f7e7689f | Iustin Pop | if self.op.remote_node is not None and self.op.iallocator is not None: |
7794 | f7e7689f | Iustin Pop | raise errors.OpPrereqError("Give either the iallocator or the new" |
7795 | f7e7689f | Iustin Pop | " secondary, not both", errors.ECODE_INVAL)
|
7796 | f7e7689f | Iustin Pop | |
7797 | f7e7689f | Iustin Pop | def ExpandNames(self): |
7798 | f7e7689f | Iustin Pop | self.op.nodes = _GetWantedNodes(self, self.op.nodes) |
7799 | f7e7689f | Iustin Pop | self.needed_locks = locks = {}
|
7800 | f7e7689f | Iustin Pop | if self.op.remote_node is None: |
7801 | f7e7689f | Iustin Pop | locks[locking.LEVEL_NODE] = locking.ALL_SET |
7802 | f7e7689f | Iustin Pop | else:
|
7803 | f7e7689f | Iustin Pop | self.op.remote_node = _ExpandNodeName(self.cfg, self.op.remote_node) |
7804 | f7e7689f | Iustin Pop | locks[locking.LEVEL_NODE] = self.op.nodes + [self.op.remote_node] |
7805 | f7e7689f | Iustin Pop | |
7806 | f7e7689f | Iustin Pop | def CheckPrereq(self): |
7807 | f7e7689f | Iustin Pop | pass
|
7808 | f7e7689f | Iustin Pop | |
7809 | f7e7689f | Iustin Pop | def Exec(self, feedback_fn): |
7810 | f7e7689f | Iustin Pop | if self.op.remote_node is not None: |
7811 | f7e7689f | Iustin Pop | instances = [] |
7812 | f7e7689f | Iustin Pop | for node in self.op.nodes: |
7813 | f7e7689f | Iustin Pop | instances.extend(_GetNodeSecondaryInstances(self.cfg, node))
|
7814 | f7e7689f | Iustin Pop | result = [] |
7815 | f7e7689f | Iustin Pop | for i in instances: |
7816 | f7e7689f | Iustin Pop | if i.primary_node == self.op.remote_node: |
7817 | f7e7689f | Iustin Pop | raise errors.OpPrereqError("Node %s is the primary node of" |
7818 | f7e7689f | Iustin Pop | " instance %s, cannot use it as"
|
7819 | f7e7689f | Iustin Pop | " secondary" %
|
7820 | f7e7689f | Iustin Pop | (self.op.remote_node, i.name),
|
7821 | f7e7689f | Iustin Pop | errors.ECODE_INVAL) |
7822 | f7e7689f | Iustin Pop | result.append([i.name, self.op.remote_node])
|
7823 | f7e7689f | Iustin Pop | else:
|
7824 | f7e7689f | Iustin Pop | ial = IAllocator(self.cfg, self.rpc, |
7825 | f7e7689f | Iustin Pop | mode=constants.IALLOCATOR_MODE_MEVAC, |
7826 | f7e7689f | Iustin Pop | evac_nodes=self.op.nodes)
|
7827 | f7e7689f | Iustin Pop | ial.Run(self.op.iallocator, validate=True) |
7828 | f7e7689f | Iustin Pop | if not ial.success: |
7829 | f7e7689f | Iustin Pop | raise errors.OpExecError("No valid evacuation solution: %s" % ial.info, |
7830 | f7e7689f | Iustin Pop | errors.ECODE_NORES) |
7831 | f7e7689f | Iustin Pop | result = ial.result |
7832 | f7e7689f | Iustin Pop | return result
|
7833 | f7e7689f | Iustin Pop | |
7834 | f7e7689f | Iustin Pop | |
7835 | 8729e0d7 | Iustin Pop | class LUGrowDisk(LogicalUnit): |
7836 | 8729e0d7 | Iustin Pop | """Grow a disk of an instance.
|
7837 | 8729e0d7 | Iustin Pop |
|
7838 | 8729e0d7 | Iustin Pop | """
|
7839 | 8729e0d7 | Iustin Pop | HPATH = "disk-grow"
|
7840 | 8729e0d7 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
7841 | 6605411d | Iustin Pop | _OP_REQP = ["instance_name", "disk", "amount", "wait_for_sync"] |
7842 | 31e63dbf | Guido Trotter | REQ_BGL = False
|
7843 | 31e63dbf | Guido Trotter | |
7844 | 31e63dbf | Guido Trotter | def ExpandNames(self): |
7845 | 31e63dbf | Guido Trotter | self._ExpandAndLockInstance()
|
7846 | 31e63dbf | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
7847 | f6d9a522 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
7848 | 31e63dbf | Guido Trotter | |
7849 | 31e63dbf | Guido Trotter | def DeclareLocks(self, level): |
7850 | 31e63dbf | Guido Trotter | if level == locking.LEVEL_NODE:
|
7851 | 31e63dbf | Guido Trotter | self._LockInstancesNodes()
|
7852 | 8729e0d7 | Iustin Pop | |
7853 | 8729e0d7 | Iustin Pop | def BuildHooksEnv(self): |
7854 | 8729e0d7 | Iustin Pop | """Build hooks env.
|
7855 | 8729e0d7 | Iustin Pop |
|
7856 | 8729e0d7 | Iustin Pop | This runs on the master, the primary and all the secondaries.
|
7857 | 8729e0d7 | Iustin Pop |
|
7858 | 8729e0d7 | Iustin Pop | """
|
7859 | 8729e0d7 | Iustin Pop | env = { |
7860 | 8729e0d7 | Iustin Pop | "DISK": self.op.disk, |
7861 | 8729e0d7 | Iustin Pop | "AMOUNT": self.op.amount, |
7862 | 8729e0d7 | Iustin Pop | } |
7863 | 338e51e8 | Iustin Pop | env.update(_BuildInstanceHookEnvByObject(self, self.instance)) |
7864 | abd8e836 | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
7865 | 8729e0d7 | Iustin Pop | return env, nl, nl
|
7866 | 8729e0d7 | Iustin Pop | |
7867 | 8729e0d7 | Iustin Pop | def CheckPrereq(self): |
7868 | 8729e0d7 | Iustin Pop | """Check prerequisites.
|
7869 | 8729e0d7 | Iustin Pop |
|
7870 | 8729e0d7 | Iustin Pop | This checks that the instance is in the cluster.
|
7871 | 8729e0d7 | Iustin Pop |
|
7872 | 8729e0d7 | Iustin Pop | """
|
7873 | 31e63dbf | Guido Trotter | instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
7874 | 31e63dbf | Guido Trotter | assert instance is not None, \ |
7875 | 31e63dbf | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
7876 | 6b12959c | Iustin Pop | nodenames = list(instance.all_nodes)
|
7877 | 6b12959c | Iustin Pop | for node in nodenames: |
7878 | 7527a8a4 | Iustin Pop | _CheckNodeOnline(self, node)
|
7879 | 7527a8a4 | Iustin Pop | |
7880 | 31e63dbf | Guido Trotter | |
7881 | 8729e0d7 | Iustin Pop | self.instance = instance
|
7882 | 8729e0d7 | Iustin Pop | |
7883 | 728489a3 | Guido Trotter | if instance.disk_template not in constants.DTS_GROWABLE: |
7884 | 8729e0d7 | Iustin Pop | raise errors.OpPrereqError("Instance's disk layout does not support" |
7885 | 5c983ee5 | Iustin Pop | " growing.", errors.ECODE_INVAL)
|
7886 | 8729e0d7 | Iustin Pop | |
7887 | ad24e046 | Iustin Pop | self.disk = instance.FindDisk(self.op.disk) |
7888 | 8729e0d7 | Iustin Pop | |
7889 | 2c42c5df | Guido Trotter | if instance.disk_template != constants.DT_FILE:
|
7890 | 2c42c5df | Guido Trotter | # TODO: check the free disk space for file, when that feature will be
|
7891 | 2c42c5df | Guido Trotter | # supported
|
7892 | 2c42c5df | Guido Trotter | _CheckNodesFreeDisk(self, nodenames, self.op.amount) |
7893 | 8729e0d7 | Iustin Pop | |
7894 | 8729e0d7 | Iustin Pop | def Exec(self, feedback_fn): |
7895 | 8729e0d7 | Iustin Pop | """Execute disk grow.
|
7896 | 8729e0d7 | Iustin Pop |
|
7897 | 8729e0d7 | Iustin Pop | """
|
7898 | 8729e0d7 | Iustin Pop | instance = self.instance
|
7899 | ad24e046 | Iustin Pop | disk = self.disk
|
7900 | 6b12959c | Iustin Pop | for node in instance.all_nodes: |
7901 | 8729e0d7 | Iustin Pop | self.cfg.SetDiskID(disk, node)
|
7902 | 72737a7f | Iustin Pop | result = self.rpc.call_blockdev_grow(node, disk, self.op.amount) |
7903 | 4c4e4e1e | Iustin Pop | result.Raise("Grow request failed to node %s" % node)
|
7904 | 5bc556dd | Michael Hanselmann | |
7905 | 5bc556dd | Michael Hanselmann | # TODO: Rewrite code to work properly
|
7906 | 5bc556dd | Michael Hanselmann | # DRBD goes into sync mode for a short amount of time after executing the
|
7907 | 5bc556dd | Michael Hanselmann | # "resize" command. DRBD 8.x below version 8.0.13 contains a bug whereby
|
7908 | 5bc556dd | Michael Hanselmann | # calling "resize" in sync mode fails. Sleeping for a short amount of
|
7909 | 5bc556dd | Michael Hanselmann | # time is a work-around.
|
7910 | 5bc556dd | Michael Hanselmann | time.sleep(5)
|
7911 | 5bc556dd | Michael Hanselmann | |
7912 | 8729e0d7 | Iustin Pop | disk.RecordGrow(self.op.amount)
|
7913 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, feedback_fn)
|
7914 | 6605411d | Iustin Pop | if self.op.wait_for_sync: |
7915 | cd4d138f | Guido Trotter | disk_abort = not _WaitForSync(self, instance) |
7916 | 6605411d | Iustin Pop | if disk_abort:
|
7917 | 86d9d3bb | Iustin Pop | self.proc.LogWarning("Warning: disk sync-ing has not returned a good" |
7918 | 86d9d3bb | Iustin Pop | " status.\nPlease check the instance.")
|
7919 | 8729e0d7 | Iustin Pop | |
7920 | 8729e0d7 | Iustin Pop | |
7921 | a8083063 | Iustin Pop | class LUQueryInstanceData(NoHooksLU): |
7922 | a8083063 | Iustin Pop | """Query runtime instance data.
|
7923 | a8083063 | Iustin Pop |
|
7924 | a8083063 | Iustin Pop | """
|
7925 | 57821cac | Iustin Pop | _OP_REQP = ["instances", "static"] |
7926 | a987fa48 | Guido Trotter | REQ_BGL = False
|
7927 | ae5849b5 | Michael Hanselmann | |
7928 | a987fa48 | Guido Trotter | def ExpandNames(self): |
7929 | a987fa48 | Guido Trotter | self.needed_locks = {}
|
7930 | c772d142 | Michael Hanselmann | self.share_locks = dict.fromkeys(locking.LEVELS, 1) |
7931 | a987fa48 | Guido Trotter | |
7932 | a987fa48 | Guido Trotter | if not isinstance(self.op.instances, list): |
7933 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid argument type 'instances'", |
7934 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
7935 | a987fa48 | Guido Trotter | |
7936 | a987fa48 | Guido Trotter | if self.op.instances: |
7937 | a987fa48 | Guido Trotter | self.wanted_names = []
|
7938 | a987fa48 | Guido Trotter | for name in self.op.instances: |
7939 | cf26a87a | Iustin Pop | full_name = _ExpandInstanceName(self.cfg, name)
|
7940 | a987fa48 | Guido Trotter | self.wanted_names.append(full_name)
|
7941 | a987fa48 | Guido Trotter | self.needed_locks[locking.LEVEL_INSTANCE] = self.wanted_names |
7942 | a987fa48 | Guido Trotter | else:
|
7943 | a987fa48 | Guido Trotter | self.wanted_names = None |
7944 | a987fa48 | Guido Trotter | self.needed_locks[locking.LEVEL_INSTANCE] = locking.ALL_SET
|
7945 | a987fa48 | Guido Trotter | |
7946 | a987fa48 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
7947 | a987fa48 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
7948 | a987fa48 | Guido Trotter | |
7949 | a987fa48 | Guido Trotter | def DeclareLocks(self, level): |
7950 | a987fa48 | Guido Trotter | if level == locking.LEVEL_NODE:
|
7951 | a987fa48 | Guido Trotter | self._LockInstancesNodes()
|
7952 | a8083063 | Iustin Pop | |
7953 | a8083063 | Iustin Pop | def CheckPrereq(self): |
7954 | a8083063 | Iustin Pop | """Check prerequisites.
|
7955 | a8083063 | Iustin Pop |
|
7956 | a8083063 | Iustin Pop | This only checks the optional instance list against the existing names.
|
7957 | a8083063 | Iustin Pop |
|
7958 | a8083063 | Iustin Pop | """
|
7959 | a987fa48 | Guido Trotter | if self.wanted_names is None: |
7960 | a987fa48 | Guido Trotter | self.wanted_names = self.acquired_locks[locking.LEVEL_INSTANCE] |
7961 | a8083063 | Iustin Pop | |
7962 | a987fa48 | Guido Trotter | self.wanted_instances = [self.cfg.GetInstanceInfo(name) for name |
7963 | a987fa48 | Guido Trotter | in self.wanted_names] |
7964 | a987fa48 | Guido Trotter | return
|
7965 | a8083063 | Iustin Pop | |
7966 | 98825740 | Michael Hanselmann | def _ComputeBlockdevStatus(self, node, instance_name, dev): |
7967 | 98825740 | Michael Hanselmann | """Returns the status of a block device
|
7968 | 98825740 | Michael Hanselmann |
|
7969 | 98825740 | Michael Hanselmann | """
|
7970 | 4dce1a83 | Michael Hanselmann | if self.op.static or not node: |
7971 | 98825740 | Michael Hanselmann | return None |
7972 | 98825740 | Michael Hanselmann | |
7973 | 98825740 | Michael Hanselmann | self.cfg.SetDiskID(dev, node)
|
7974 | 98825740 | Michael Hanselmann | |
7975 | 98825740 | Michael Hanselmann | result = self.rpc.call_blockdev_find(node, dev)
|
7976 | 98825740 | Michael Hanselmann | if result.offline:
|
7977 | 98825740 | Michael Hanselmann | return None |
7978 | 98825740 | Michael Hanselmann | |
7979 | 98825740 | Michael Hanselmann | result.Raise("Can't compute disk status for %s" % instance_name)
|
7980 | 98825740 | Michael Hanselmann | |
7981 | 98825740 | Michael Hanselmann | status = result.payload |
7982 | ddfe2228 | Michael Hanselmann | if status is None: |
7983 | ddfe2228 | Michael Hanselmann | return None |
7984 | 98825740 | Michael Hanselmann | |
7985 | 98825740 | Michael Hanselmann | return (status.dev_path, status.major, status.minor,
|
7986 | 98825740 | Michael Hanselmann | status.sync_percent, status.estimated_time, |
7987 | f208978a | Michael Hanselmann | status.is_degraded, status.ldisk_status) |
7988 | 98825740 | Michael Hanselmann | |
7989 | a8083063 | Iustin Pop | def _ComputeDiskStatus(self, instance, snode, dev): |
7990 | a8083063 | Iustin Pop | """Compute block device status.
|
7991 | a8083063 | Iustin Pop |
|
7992 | a8083063 | Iustin Pop | """
|
7993 | a1f445d3 | Iustin Pop | if dev.dev_type in constants.LDS_DRBD: |
7994 | a8083063 | Iustin Pop | # we change the snode then (otherwise we use the one passed in)
|
7995 | a8083063 | Iustin Pop | if dev.logical_id[0] == instance.primary_node: |
7996 | a8083063 | Iustin Pop | snode = dev.logical_id[1]
|
7997 | a8083063 | Iustin Pop | else:
|
7998 | a8083063 | Iustin Pop | snode = dev.logical_id[0]
|
7999 | a8083063 | Iustin Pop | |
8000 | 98825740 | Michael Hanselmann | dev_pstatus = self._ComputeBlockdevStatus(instance.primary_node,
|
8001 | 98825740 | Michael Hanselmann | instance.name, dev) |
8002 | 98825740 | Michael Hanselmann | dev_sstatus = self._ComputeBlockdevStatus(snode, instance.name, dev)
|
8003 | a8083063 | Iustin Pop | |
8004 | a8083063 | Iustin Pop | if dev.children:
|
8005 | a8083063 | Iustin Pop | dev_children = [self._ComputeDiskStatus(instance, snode, child)
|
8006 | a8083063 | Iustin Pop | for child in dev.children] |
8007 | a8083063 | Iustin Pop | else:
|
8008 | a8083063 | Iustin Pop | dev_children = [] |
8009 | a8083063 | Iustin Pop | |
8010 | a8083063 | Iustin Pop | data = { |
8011 | a8083063 | Iustin Pop | "iv_name": dev.iv_name,
|
8012 | a8083063 | Iustin Pop | "dev_type": dev.dev_type,
|
8013 | a8083063 | Iustin Pop | "logical_id": dev.logical_id,
|
8014 | a8083063 | Iustin Pop | "physical_id": dev.physical_id,
|
8015 | a8083063 | Iustin Pop | "pstatus": dev_pstatus,
|
8016 | a8083063 | Iustin Pop | "sstatus": dev_sstatus,
|
8017 | a8083063 | Iustin Pop | "children": dev_children,
|
8018 | b6fdf8b8 | Iustin Pop | "mode": dev.mode,
|
8019 | c98162a7 | Iustin Pop | "size": dev.size,
|
8020 | a8083063 | Iustin Pop | } |
8021 | a8083063 | Iustin Pop | |
8022 | a8083063 | Iustin Pop | return data
|
8023 | a8083063 | Iustin Pop | |
8024 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
8025 | a8083063 | Iustin Pop | """Gather and return data"""
|
8026 | a8083063 | Iustin Pop | result = {} |
8027 | 338e51e8 | Iustin Pop | |
8028 | 338e51e8 | Iustin Pop | cluster = self.cfg.GetClusterInfo()
|
8029 | 338e51e8 | Iustin Pop | |
8030 | a8083063 | Iustin Pop | for instance in self.wanted_instances: |
8031 | 57821cac | Iustin Pop | if not self.op.static: |
8032 | 57821cac | Iustin Pop | remote_info = self.rpc.call_instance_info(instance.primary_node,
|
8033 | 57821cac | Iustin Pop | instance.name, |
8034 | 57821cac | Iustin Pop | instance.hypervisor) |
8035 | 4c4e4e1e | Iustin Pop | remote_info.Raise("Error checking node %s" % instance.primary_node)
|
8036 | 7ad1af4a | Iustin Pop | remote_info = remote_info.payload |
8037 | 57821cac | Iustin Pop | if remote_info and "state" in remote_info: |
8038 | 57821cac | Iustin Pop | remote_state = "up"
|
8039 | 57821cac | Iustin Pop | else:
|
8040 | 57821cac | Iustin Pop | remote_state = "down"
|
8041 | a8083063 | Iustin Pop | else:
|
8042 | 57821cac | Iustin Pop | remote_state = None
|
8043 | 0d68c45d | Iustin Pop | if instance.admin_up:
|
8044 | a8083063 | Iustin Pop | config_state = "up"
|
8045 | 0d68c45d | Iustin Pop | else:
|
8046 | 0d68c45d | Iustin Pop | config_state = "down"
|
8047 | a8083063 | Iustin Pop | |
8048 | a8083063 | Iustin Pop | disks = [self._ComputeDiskStatus(instance, None, device) |
8049 | a8083063 | Iustin Pop | for device in instance.disks] |
8050 | a8083063 | Iustin Pop | |
8051 | a8083063 | Iustin Pop | idict = { |
8052 | a8083063 | Iustin Pop | "name": instance.name,
|
8053 | a8083063 | Iustin Pop | "config_state": config_state,
|
8054 | a8083063 | Iustin Pop | "run_state": remote_state,
|
8055 | a8083063 | Iustin Pop | "pnode": instance.primary_node,
|
8056 | a8083063 | Iustin Pop | "snodes": instance.secondary_nodes,
|
8057 | a8083063 | Iustin Pop | "os": instance.os,
|
8058 | 0b13832c | Guido Trotter | # this happens to be the same format used for hooks
|
8059 | 0b13832c | Guido Trotter | "nics": _NICListToTuple(self, instance.nics), |
8060 | a8083063 | Iustin Pop | "disks": disks,
|
8061 | e69d05fd | Iustin Pop | "hypervisor": instance.hypervisor,
|
8062 | 24838135 | Iustin Pop | "network_port": instance.network_port,
|
8063 | 24838135 | Iustin Pop | "hv_instance": instance.hvparams,
|
8064 | 7736a5f2 | Iustin Pop | "hv_actual": cluster.FillHV(instance, skip_globals=True), |
8065 | 338e51e8 | Iustin Pop | "be_instance": instance.beparams,
|
8066 | 338e51e8 | Iustin Pop | "be_actual": cluster.FillBE(instance),
|
8067 | 90f72445 | Iustin Pop | "serial_no": instance.serial_no,
|
8068 | 90f72445 | Iustin Pop | "mtime": instance.mtime,
|
8069 | 90f72445 | Iustin Pop | "ctime": instance.ctime,
|
8070 | 033d58b0 | Iustin Pop | "uuid": instance.uuid,
|
8071 | a8083063 | Iustin Pop | } |
8072 | a8083063 | Iustin Pop | |
8073 | a8083063 | Iustin Pop | result[instance.name] = idict |
8074 | a8083063 | Iustin Pop | |
8075 | a8083063 | Iustin Pop | return result
|
8076 | a8083063 | Iustin Pop | |
8077 | a8083063 | Iustin Pop | |
8078 | 7767bbf5 | Manuel Franceschini | class LUSetInstanceParams(LogicalUnit): |
8079 | a8083063 | Iustin Pop | """Modifies an instances's parameters.
|
8080 | a8083063 | Iustin Pop |
|
8081 | a8083063 | Iustin Pop | """
|
8082 | a8083063 | Iustin Pop | HPATH = "instance-modify"
|
8083 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
8084 | 24991749 | Iustin Pop | _OP_REQP = ["instance_name"]
|
8085 | 1a5c7281 | Guido Trotter | REQ_BGL = False
|
8086 | 1a5c7281 | Guido Trotter | |
8087 | 24991749 | Iustin Pop | def CheckArguments(self): |
8088 | 24991749 | Iustin Pop | if not hasattr(self.op, 'nics'): |
8089 | 24991749 | Iustin Pop | self.op.nics = []
|
8090 | 24991749 | Iustin Pop | if not hasattr(self.op, 'disks'): |
8091 | 24991749 | Iustin Pop | self.op.disks = []
|
8092 | 24991749 | Iustin Pop | if not hasattr(self.op, 'beparams'): |
8093 | 24991749 | Iustin Pop | self.op.beparams = {}
|
8094 | 24991749 | Iustin Pop | if not hasattr(self.op, 'hvparams'): |
8095 | 24991749 | Iustin Pop | self.op.hvparams = {}
|
8096 | e29e9550 | Iustin Pop | if not hasattr(self.op, "disk_template"): |
8097 | e29e9550 | Iustin Pop | self.op.disk_template = None |
8098 | e29e9550 | Iustin Pop | if not hasattr(self.op, "remote_node"): |
8099 | e29e9550 | Iustin Pop | self.op.remote_node = None |
8100 | 96b39bcc | Iustin Pop | if not hasattr(self.op, "os_name"): |
8101 | 96b39bcc | Iustin Pop | self.op.os_name = None |
8102 | 96b39bcc | Iustin Pop | if not hasattr(self.op, "force_variant"): |
8103 | 96b39bcc | Iustin Pop | self.op.force_variant = False |
8104 | 24991749 | Iustin Pop | self.op.force = getattr(self.op, "force", False) |
8105 | e29e9550 | Iustin Pop | if not (self.op.nics or self.op.disks or self.op.disk_template or |
8106 | 96b39bcc | Iustin Pop | self.op.hvparams or self.op.beparams or self.op.os_name): |
8107 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL) |
8108 | 24991749 | Iustin Pop | |
8109 | 7736a5f2 | Iustin Pop | if self.op.hvparams: |
8110 | 7736a5f2 | Iustin Pop | _CheckGlobalHvParams(self.op.hvparams)
|
8111 | 7736a5f2 | Iustin Pop | |
8112 | 24991749 | Iustin Pop | # Disk validation
|
8113 | 24991749 | Iustin Pop | disk_addremove = 0
|
8114 | 24991749 | Iustin Pop | for disk_op, disk_dict in self.op.disks: |
8115 | 24991749 | Iustin Pop | if disk_op == constants.DDM_REMOVE:
|
8116 | 24991749 | Iustin Pop | disk_addremove += 1
|
8117 | 24991749 | Iustin Pop | continue
|
8118 | 24991749 | Iustin Pop | elif disk_op == constants.DDM_ADD:
|
8119 | 24991749 | Iustin Pop | disk_addremove += 1
|
8120 | 24991749 | Iustin Pop | else:
|
8121 | 24991749 | Iustin Pop | if not isinstance(disk_op, int): |
8122 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid disk index", errors.ECODE_INVAL) |
8123 | 8b46606c | Guido Trotter | if not isinstance(disk_dict, dict): |
8124 | 8b46606c | Guido Trotter | msg = "Invalid disk value: expected dict, got '%s'" % disk_dict
|
8125 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
8126 | 8b46606c | Guido Trotter | |
8127 | 24991749 | Iustin Pop | if disk_op == constants.DDM_ADD:
|
8128 | 24991749 | Iustin Pop | mode = disk_dict.setdefault('mode', constants.DISK_RDWR)
|
8129 | 6ec66eae | Iustin Pop | if mode not in constants.DISK_ACCESS_SET: |
8130 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid disk access mode '%s'" % mode, |
8131 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8132 | 24991749 | Iustin Pop | size = disk_dict.get('size', None) |
8133 | 24991749 | Iustin Pop | if size is None: |
8134 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Required disk parameter size missing", |
8135 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8136 | 24991749 | Iustin Pop | try:
|
8137 | 24991749 | Iustin Pop | size = int(size)
|
8138 | 691744c4 | Iustin Pop | except (TypeError, ValueError), err: |
8139 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Invalid disk size parameter: %s" % |
8140 | 5c983ee5 | Iustin Pop | str(err), errors.ECODE_INVAL)
|
8141 | 24991749 | Iustin Pop | disk_dict['size'] = size
|
8142 | 24991749 | Iustin Pop | else:
|
8143 | 24991749 | Iustin Pop | # modification of disk
|
8144 | 24991749 | Iustin Pop | if 'size' in disk_dict: |
8145 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Disk size change not possible, use" |
8146 | 5c983ee5 | Iustin Pop | " grow-disk", errors.ECODE_INVAL)
|
8147 | 24991749 | Iustin Pop | |
8148 | 24991749 | Iustin Pop | if disk_addremove > 1: |
8149 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Only one disk add or remove operation" |
8150 | 5c983ee5 | Iustin Pop | " supported at a time", errors.ECODE_INVAL)
|
8151 | 24991749 | Iustin Pop | |
8152 | e29e9550 | Iustin Pop | if self.op.disks and self.op.disk_template is not None: |
8153 | e29e9550 | Iustin Pop | raise errors.OpPrereqError("Disk template conversion and other disk" |
8154 | e29e9550 | Iustin Pop | " changes not supported at the same time",
|
8155 | e29e9550 | Iustin Pop | errors.ECODE_INVAL) |
8156 | e29e9550 | Iustin Pop | |
8157 | e29e9550 | Iustin Pop | if self.op.disk_template: |
8158 | e29e9550 | Iustin Pop | _CheckDiskTemplate(self.op.disk_template)
|
8159 | e29e9550 | Iustin Pop | if (self.op.disk_template in constants.DTS_NET_MIRROR and |
8160 | e29e9550 | Iustin Pop | self.op.remote_node is None): |
8161 | e29e9550 | Iustin Pop | raise errors.OpPrereqError("Changing the disk template to a mirrored" |
8162 | e29e9550 | Iustin Pop | " one requires specifying a secondary node",
|
8163 | e29e9550 | Iustin Pop | errors.ECODE_INVAL) |
8164 | e29e9550 | Iustin Pop | |
8165 | 24991749 | Iustin Pop | # NIC validation
|
8166 | 24991749 | Iustin Pop | nic_addremove = 0
|
8167 | 24991749 | Iustin Pop | for nic_op, nic_dict in self.op.nics: |
8168 | 24991749 | Iustin Pop | if nic_op == constants.DDM_REMOVE:
|
8169 | 24991749 | Iustin Pop | nic_addremove += 1
|
8170 | 24991749 | Iustin Pop | continue
|
8171 | 24991749 | Iustin Pop | elif nic_op == constants.DDM_ADD:
|
8172 | 24991749 | Iustin Pop | nic_addremove += 1
|
8173 | 24991749 | Iustin Pop | else:
|
8174 | 24991749 | Iustin Pop | if not isinstance(nic_op, int): |
8175 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid nic index", errors.ECODE_INVAL) |
8176 | 8b46606c | Guido Trotter | if not isinstance(nic_dict, dict): |
8177 | 8b46606c | Guido Trotter | msg = "Invalid nic value: expected dict, got '%s'" % nic_dict
|
8178 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
8179 | 24991749 | Iustin Pop | |
8180 | 24991749 | Iustin Pop | # nic_dict should be a dict
|
8181 | 24991749 | Iustin Pop | nic_ip = nic_dict.get('ip', None) |
8182 | 24991749 | Iustin Pop | if nic_ip is not None: |
8183 | 5c44da6a | Guido Trotter | if nic_ip.lower() == constants.VALUE_NONE:
|
8184 | 24991749 | Iustin Pop | nic_dict['ip'] = None |
8185 | 24991749 | Iustin Pop | else:
|
8186 | 24991749 | Iustin Pop | if not utils.IsValidIP(nic_ip): |
8187 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid IP address '%s'" % nic_ip, |
8188 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8189 | 5c44da6a | Guido Trotter | |
8190 | cd098c41 | Guido Trotter | nic_bridge = nic_dict.get('bridge', None) |
8191 | cd098c41 | Guido Trotter | nic_link = nic_dict.get('link', None) |
8192 | cd098c41 | Guido Trotter | if nic_bridge and nic_link: |
8193 | 29921401 | Iustin Pop | raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'" |
8194 | 5c983ee5 | Iustin Pop | " at the same time", errors.ECODE_INVAL)
|
8195 | cd098c41 | Guido Trotter | elif nic_bridge and nic_bridge.lower() == constants.VALUE_NONE: |
8196 | cd098c41 | Guido Trotter | nic_dict['bridge'] = None |
8197 | cd098c41 | Guido Trotter | elif nic_link and nic_link.lower() == constants.VALUE_NONE: |
8198 | cd098c41 | Guido Trotter | nic_dict['link'] = None |
8199 | cd098c41 | Guido Trotter | |
8200 | 5c44da6a | Guido Trotter | if nic_op == constants.DDM_ADD:
|
8201 | 5c44da6a | Guido Trotter | nic_mac = nic_dict.get('mac', None) |
8202 | 5c44da6a | Guido Trotter | if nic_mac is None: |
8203 | 5c44da6a | Guido Trotter | nic_dict['mac'] = constants.VALUE_AUTO
|
8204 | 5c44da6a | Guido Trotter | |
8205 | 5c44da6a | Guido Trotter | if 'mac' in nic_dict: |
8206 | 5c44da6a | Guido Trotter | nic_mac = nic_dict['mac']
|
8207 | 24991749 | Iustin Pop | if nic_mac not in (constants.VALUE_AUTO, constants.VALUE_GENERATE): |
8208 | 82187135 | René Nussbaumer | nic_mac = utils.NormalizeAndValidateMac(nic_mac) |
8209 | 82187135 | René Nussbaumer | |
8210 | 5c44da6a | Guido Trotter | if nic_op != constants.DDM_ADD and nic_mac == constants.VALUE_AUTO: |
8211 | 5c44da6a | Guido Trotter | raise errors.OpPrereqError("'auto' is not a valid MAC address when" |
8212 | 5c983ee5 | Iustin Pop | " modifying an existing nic",
|
8213 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8214 | 5c44da6a | Guido Trotter | |
8215 | 24991749 | Iustin Pop | if nic_addremove > 1: |
8216 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Only one NIC add or remove operation" |
8217 | 5c983ee5 | Iustin Pop | " supported at a time", errors.ECODE_INVAL)
|
8218 | 24991749 | Iustin Pop | |
8219 | 1a5c7281 | Guido Trotter | def ExpandNames(self): |
8220 | 1a5c7281 | Guido Trotter | self._ExpandAndLockInstance()
|
8221 | 74409b12 | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = []
|
8222 | 74409b12 | Iustin Pop | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
8223 | 74409b12 | Iustin Pop | |
8224 | 74409b12 | Iustin Pop | def DeclareLocks(self, level): |
8225 | 74409b12 | Iustin Pop | if level == locking.LEVEL_NODE:
|
8226 | 74409b12 | Iustin Pop | self._LockInstancesNodes()
|
8227 | e29e9550 | Iustin Pop | if self.op.disk_template and self.op.remote_node: |
8228 | e29e9550 | Iustin Pop | self.op.remote_node = _ExpandNodeName(self.cfg, self.op.remote_node) |
8229 | e29e9550 | Iustin Pop | self.needed_locks[locking.LEVEL_NODE].append(self.op.remote_node) |
8230 | a8083063 | Iustin Pop | |
8231 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
8232 | a8083063 | Iustin Pop | """Build hooks env.
|
8233 | a8083063 | Iustin Pop |
|
8234 | a8083063 | Iustin Pop | This runs on the master, primary and secondaries.
|
8235 | a8083063 | Iustin Pop |
|
8236 | a8083063 | Iustin Pop | """
|
8237 | 396e1b78 | Michael Hanselmann | args = dict()
|
8238 | 338e51e8 | Iustin Pop | if constants.BE_MEMORY in self.be_new: |
8239 | 338e51e8 | Iustin Pop | args['memory'] = self.be_new[constants.BE_MEMORY] |
8240 | 338e51e8 | Iustin Pop | if constants.BE_VCPUS in self.be_new: |
8241 | 61be6ba4 | Iustin Pop | args['vcpus'] = self.be_new[constants.BE_VCPUS] |
8242 | d8dcf3c9 | Guido Trotter | # TODO: export disk changes. Note: _BuildInstanceHookEnv* don't export disk
|
8243 | d8dcf3c9 | Guido Trotter | # information at all.
|
8244 | d8dcf3c9 | Guido Trotter | if self.op.nics: |
8245 | d8dcf3c9 | Guido Trotter | args['nics'] = []
|
8246 | d8dcf3c9 | Guido Trotter | nic_override = dict(self.op.nics) |
8247 | 62f0dd02 | Guido Trotter | c_nicparams = self.cluster.nicparams[constants.PP_DEFAULT]
|
8248 | d8dcf3c9 | Guido Trotter | for idx, nic in enumerate(self.instance.nics): |
8249 | d8dcf3c9 | Guido Trotter | if idx in nic_override: |
8250 | d8dcf3c9 | Guido Trotter | this_nic_override = nic_override[idx] |
8251 | d8dcf3c9 | Guido Trotter | else:
|
8252 | d8dcf3c9 | Guido Trotter | this_nic_override = {} |
8253 | d8dcf3c9 | Guido Trotter | if 'ip' in this_nic_override: |
8254 | d8dcf3c9 | Guido Trotter | ip = this_nic_override['ip']
|
8255 | d8dcf3c9 | Guido Trotter | else:
|
8256 | d8dcf3c9 | Guido Trotter | ip = nic.ip |
8257 | d8dcf3c9 | Guido Trotter | if 'mac' in this_nic_override: |
8258 | d8dcf3c9 | Guido Trotter | mac = this_nic_override['mac']
|
8259 | d8dcf3c9 | Guido Trotter | else:
|
8260 | d8dcf3c9 | Guido Trotter | mac = nic.mac |
8261 | 62f0dd02 | Guido Trotter | if idx in self.nic_pnew: |
8262 | 62f0dd02 | Guido Trotter | nicparams = self.nic_pnew[idx]
|
8263 | 62f0dd02 | Guido Trotter | else:
|
8264 | 62f0dd02 | Guido Trotter | nicparams = objects.FillDict(c_nicparams, nic.nicparams) |
8265 | 62f0dd02 | Guido Trotter | mode = nicparams[constants.NIC_MODE] |
8266 | 62f0dd02 | Guido Trotter | link = nicparams[constants.NIC_LINK] |
8267 | 62f0dd02 | Guido Trotter | args['nics'].append((ip, mac, mode, link))
|
8268 | d8dcf3c9 | Guido Trotter | if constants.DDM_ADD in nic_override: |
8269 | d8dcf3c9 | Guido Trotter | ip = nic_override[constants.DDM_ADD].get('ip', None) |
8270 | d8dcf3c9 | Guido Trotter | mac = nic_override[constants.DDM_ADD]['mac']
|
8271 | 62f0dd02 | Guido Trotter | nicparams = self.nic_pnew[constants.DDM_ADD]
|
8272 | 62f0dd02 | Guido Trotter | mode = nicparams[constants.NIC_MODE] |
8273 | 62f0dd02 | Guido Trotter | link = nicparams[constants.NIC_LINK] |
8274 | 62f0dd02 | Guido Trotter | args['nics'].append((ip, mac, mode, link))
|
8275 | d8dcf3c9 | Guido Trotter | elif constants.DDM_REMOVE in nic_override: |
8276 | d8dcf3c9 | Guido Trotter | del args['nics'][-1] |
8277 | d8dcf3c9 | Guido Trotter | |
8278 | 338e51e8 | Iustin Pop | env = _BuildInstanceHookEnvByObject(self, self.instance, override=args) |
8279 | e29e9550 | Iustin Pop | if self.op.disk_template: |
8280 | e29e9550 | Iustin Pop | env["NEW_DISK_TEMPLATE"] = self.op.disk_template |
8281 | 6b12959c | Iustin Pop | nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
8282 | a8083063 | Iustin Pop | return env, nl, nl
|
8283 | a8083063 | Iustin Pop | |
8284 | 7e950d31 | Iustin Pop | @staticmethod
|
8285 | 7e950d31 | Iustin Pop | def _GetUpdatedParams(old_params, update_dict, |
8286 | 0329617a | Guido Trotter | default_values, parameter_types): |
8287 | 0329617a | Guido Trotter | """Return the new params dict for the given params.
|
8288 | 0329617a | Guido Trotter |
|
8289 | 0329617a | Guido Trotter | @type old_params: dict
|
8290 | f2fd87d7 | Iustin Pop | @param old_params: old parameters
|
8291 | 0329617a | Guido Trotter | @type update_dict: dict
|
8292 | f2fd87d7 | Iustin Pop | @param update_dict: dict containing new parameter values,
|
8293 | f2fd87d7 | Iustin Pop | or constants.VALUE_DEFAULT to reset the
|
8294 | f2fd87d7 | Iustin Pop | parameter to its default value
|
8295 | 0329617a | Guido Trotter | @type default_values: dict
|
8296 | 0329617a | Guido Trotter | @param default_values: default values for the filled parameters
|
8297 | 0329617a | Guido Trotter | @type parameter_types: dict
|
8298 | 0329617a | Guido Trotter | @param parameter_types: dict mapping target dict keys to types
|
8299 | 0329617a | Guido Trotter | in constants.ENFORCEABLE_TYPES
|
8300 | 0329617a | Guido Trotter | @rtype: (dict, dict)
|
8301 | 0329617a | Guido Trotter | @return: (new_parameters, filled_parameters)
|
8302 | 0329617a | Guido Trotter |
|
8303 | 0329617a | Guido Trotter | """
|
8304 | 0329617a | Guido Trotter | params_copy = copy.deepcopy(old_params) |
8305 | 0329617a | Guido Trotter | for key, val in update_dict.iteritems(): |
8306 | 0329617a | Guido Trotter | if val == constants.VALUE_DEFAULT:
|
8307 | 0329617a | Guido Trotter | try:
|
8308 | 0329617a | Guido Trotter | del params_copy[key]
|
8309 | 0329617a | Guido Trotter | except KeyError: |
8310 | 0329617a | Guido Trotter | pass
|
8311 | 0329617a | Guido Trotter | else:
|
8312 | 0329617a | Guido Trotter | params_copy[key] = val |
8313 | 0329617a | Guido Trotter | utils.ForceDictType(params_copy, parameter_types) |
8314 | 0329617a | Guido Trotter | params_filled = objects.FillDict(default_values, params_copy) |
8315 | 0329617a | Guido Trotter | return (params_copy, params_filled)
|
8316 | 0329617a | Guido Trotter | |
8317 | a8083063 | Iustin Pop | def CheckPrereq(self): |
8318 | a8083063 | Iustin Pop | """Check prerequisites.
|
8319 | a8083063 | Iustin Pop |
|
8320 | a8083063 | Iustin Pop | This only checks the instance list against the existing names.
|
8321 | a8083063 | Iustin Pop |
|
8322 | a8083063 | Iustin Pop | """
|
8323 | 7c4d6c7b | Michael Hanselmann | self.force = self.op.force |
8324 | a8083063 | Iustin Pop | |
8325 | 74409b12 | Iustin Pop | # checking the new params on the primary/secondary nodes
|
8326 | 31a853d2 | Iustin Pop | |
8327 | cfefe007 | Guido Trotter | instance = self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
8328 | 2ee88aeb | Guido Trotter | cluster = self.cluster = self.cfg.GetClusterInfo() |
8329 | 1a5c7281 | Guido Trotter | assert self.instance is not None, \ |
8330 | 1a5c7281 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
8331 | 6b12959c | Iustin Pop | pnode = instance.primary_node |
8332 | 6b12959c | Iustin Pop | nodelist = list(instance.all_nodes)
|
8333 | 74409b12 | Iustin Pop | |
8334 | e29e9550 | Iustin Pop | if self.op.disk_template: |
8335 | e29e9550 | Iustin Pop | if instance.disk_template == self.op.disk_template: |
8336 | e29e9550 | Iustin Pop | raise errors.OpPrereqError("Instance already has disk template %s" % |
8337 | e29e9550 | Iustin Pop | instance.disk_template, errors.ECODE_INVAL) |
8338 | e29e9550 | Iustin Pop | |
8339 | e29e9550 | Iustin Pop | if (instance.disk_template,
|
8340 | e29e9550 | Iustin Pop | self.op.disk_template) not in self._DISK_CONVERSIONS: |
8341 | e29e9550 | Iustin Pop | raise errors.OpPrereqError("Unsupported disk template conversion from" |
8342 | e29e9550 | Iustin Pop | " %s to %s" % (instance.disk_template,
|
8343 | e29e9550 | Iustin Pop | self.op.disk_template),
|
8344 | e29e9550 | Iustin Pop | errors.ECODE_INVAL) |
8345 | e29e9550 | Iustin Pop | if self.op.disk_template in constants.DTS_NET_MIRROR: |
8346 | e29e9550 | Iustin Pop | _CheckNodeOnline(self, self.op.remote_node) |
8347 | e29e9550 | Iustin Pop | _CheckNodeNotDrained(self, self.op.remote_node) |
8348 | e29e9550 | Iustin Pop | disks = [{"size": d.size} for d in instance.disks] |
8349 | e29e9550 | Iustin Pop | required = _ComputeDiskSize(self.op.disk_template, disks)
|
8350 | e29e9550 | Iustin Pop | _CheckNodesFreeDisk(self, [self.op.remote_node], required) |
8351 | e29e9550 | Iustin Pop | _CheckInstanceDown(self, instance, "cannot change disk template") |
8352 | e29e9550 | Iustin Pop | |
8353 | 338e51e8 | Iustin Pop | # hvparams processing
|
8354 | 74409b12 | Iustin Pop | if self.op.hvparams: |
8355 | 0329617a | Guido Trotter | i_hvdict, hv_new = self._GetUpdatedParams(
|
8356 | 0329617a | Guido Trotter | instance.hvparams, self.op.hvparams,
|
8357 | 0329617a | Guido Trotter | cluster.hvparams[instance.hypervisor], |
8358 | 0329617a | Guido Trotter | constants.HVS_PARAMETER_TYPES) |
8359 | 74409b12 | Iustin Pop | # local check
|
8360 | 74409b12 | Iustin Pop | hypervisor.GetHypervisor( |
8361 | 74409b12 | Iustin Pop | instance.hypervisor).CheckParameterSyntax(hv_new) |
8362 | 74409b12 | Iustin Pop | _CheckHVParams(self, nodelist, instance.hypervisor, hv_new)
|
8363 | 338e51e8 | Iustin Pop | self.hv_new = hv_new # the new actual values |
8364 | 338e51e8 | Iustin Pop | self.hv_inst = i_hvdict # the new dict (without defaults) |
8365 | 338e51e8 | Iustin Pop | else:
|
8366 | 338e51e8 | Iustin Pop | self.hv_new = self.hv_inst = {} |
8367 | 338e51e8 | Iustin Pop | |
8368 | 338e51e8 | Iustin Pop | # beparams processing
|
8369 | 338e51e8 | Iustin Pop | if self.op.beparams: |
8370 | 0329617a | Guido Trotter | i_bedict, be_new = self._GetUpdatedParams(
|
8371 | 0329617a | Guido Trotter | instance.beparams, self.op.beparams,
|
8372 | 0329617a | Guido Trotter | cluster.beparams[constants.PP_DEFAULT], |
8373 | 0329617a | Guido Trotter | constants.BES_PARAMETER_TYPES) |
8374 | 338e51e8 | Iustin Pop | self.be_new = be_new # the new actual values |
8375 | 338e51e8 | Iustin Pop | self.be_inst = i_bedict # the new dict (without defaults) |
8376 | 338e51e8 | Iustin Pop | else:
|
8377 | b637ae4d | Iustin Pop | self.be_new = self.be_inst = {} |
8378 | 74409b12 | Iustin Pop | |
8379 | cfefe007 | Guido Trotter | self.warn = []
|
8380 | 647a5d80 | Iustin Pop | |
8381 | 338e51e8 | Iustin Pop | if constants.BE_MEMORY in self.op.beparams and not self.force: |
8382 | 647a5d80 | Iustin Pop | mem_check_list = [pnode] |
8383 | c0f2b229 | Iustin Pop | if be_new[constants.BE_AUTO_BALANCE]:
|
8384 | c0f2b229 | Iustin Pop | # either we changed auto_balance to yes or it was from before
|
8385 | 647a5d80 | Iustin Pop | mem_check_list.extend(instance.secondary_nodes) |
8386 | 72737a7f | Iustin Pop | instance_info = self.rpc.call_instance_info(pnode, instance.name,
|
8387 | 72737a7f | Iustin Pop | instance.hypervisor) |
8388 | 647a5d80 | Iustin Pop | nodeinfo = self.rpc.call_node_info(mem_check_list, self.cfg.GetVGName(), |
8389 | 72737a7f | Iustin Pop | instance.hypervisor) |
8390 | 070e998b | Iustin Pop | pninfo = nodeinfo[pnode] |
8391 | 4c4e4e1e | Iustin Pop | msg = pninfo.fail_msg |
8392 | 070e998b | Iustin Pop | if msg:
|
8393 | cfefe007 | Guido Trotter | # Assume the primary node is unreachable and go ahead
|
8394 | 070e998b | Iustin Pop | self.warn.append("Can't get info from primary node %s: %s" % |
8395 | 070e998b | Iustin Pop | (pnode, msg)) |
8396 | 070e998b | Iustin Pop | elif not isinstance(pninfo.payload.get('memory_free', None), int): |
8397 | 070e998b | Iustin Pop | self.warn.append("Node data from primary node %s doesn't contain" |
8398 | 070e998b | Iustin Pop | " free memory information" % pnode)
|
8399 | 4c4e4e1e | Iustin Pop | elif instance_info.fail_msg:
|
8400 | 7ad1af4a | Iustin Pop | self.warn.append("Can't get instance runtime information: %s" % |
8401 | 4c4e4e1e | Iustin Pop | instance_info.fail_msg) |
8402 | cfefe007 | Guido Trotter | else:
|
8403 | 7ad1af4a | Iustin Pop | if instance_info.payload:
|
8404 | 7ad1af4a | Iustin Pop | current_mem = int(instance_info.payload['memory']) |
8405 | cfefe007 | Guido Trotter | else:
|
8406 | cfefe007 | Guido Trotter | # Assume instance not running
|
8407 | cfefe007 | Guido Trotter | # (there is a slight race condition here, but it's not very probable,
|
8408 | cfefe007 | Guido Trotter | # and we have no other way to check)
|
8409 | cfefe007 | Guido Trotter | current_mem = 0
|
8410 | 338e51e8 | Iustin Pop | miss_mem = (be_new[constants.BE_MEMORY] - current_mem - |
8411 | 070e998b | Iustin Pop | pninfo.payload['memory_free'])
|
8412 | cfefe007 | Guido Trotter | if miss_mem > 0: |
8413 | cfefe007 | Guido Trotter | raise errors.OpPrereqError("This change will prevent the instance" |
8414 | cfefe007 | Guido Trotter | " from starting, due to %d MB of memory"
|
8415 | 5c983ee5 | Iustin Pop | " missing on its primary node" % miss_mem,
|
8416 | 5c983ee5 | Iustin Pop | errors.ECODE_NORES) |
8417 | cfefe007 | Guido Trotter | |
8418 | c0f2b229 | Iustin Pop | if be_new[constants.BE_AUTO_BALANCE]:
|
8419 | 070e998b | Iustin Pop | for node, nres in nodeinfo.items(): |
8420 | ea33068f | Iustin Pop | if node not in instance.secondary_nodes: |
8421 | ea33068f | Iustin Pop | continue
|
8422 | 4c4e4e1e | Iustin Pop | msg = nres.fail_msg |
8423 | 070e998b | Iustin Pop | if msg:
|
8424 | 070e998b | Iustin Pop | self.warn.append("Can't get info from secondary node %s: %s" % |
8425 | 070e998b | Iustin Pop | (node, msg)) |
8426 | 070e998b | Iustin Pop | elif not isinstance(nres.payload.get('memory_free', None), int): |
8427 | 070e998b | Iustin Pop | self.warn.append("Secondary node %s didn't return free" |
8428 | 070e998b | Iustin Pop | " memory information" % node)
|
8429 | 070e998b | Iustin Pop | elif be_new[constants.BE_MEMORY] > nres.payload['memory_free']: |
8430 | 647a5d80 | Iustin Pop | self.warn.append("Not enough memory to failover instance to" |
8431 | 647a5d80 | Iustin Pop | " secondary node %s" % node)
|
8432 | 5bc84f33 | Alexander Schreiber | |
8433 | 24991749 | Iustin Pop | # NIC processing
|
8434 | cd098c41 | Guido Trotter | self.nic_pnew = {}
|
8435 | cd098c41 | Guido Trotter | self.nic_pinst = {}
|
8436 | 24991749 | Iustin Pop | for nic_op, nic_dict in self.op.nics: |
8437 | 24991749 | Iustin Pop | if nic_op == constants.DDM_REMOVE:
|
8438 | 24991749 | Iustin Pop | if not instance.nics: |
8439 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Instance has no NICs, cannot remove", |
8440 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8441 | 24991749 | Iustin Pop | continue
|
8442 | 24991749 | Iustin Pop | if nic_op != constants.DDM_ADD:
|
8443 | 24991749 | Iustin Pop | # an existing nic
|
8444 | 21bcb9aa | Michael Hanselmann | if not instance.nics: |
8445 | 21bcb9aa | Michael Hanselmann | raise errors.OpPrereqError("Invalid NIC index %s, instance has" |
8446 | 21bcb9aa | Michael Hanselmann | " no NICs" % nic_op,
|
8447 | 21bcb9aa | Michael Hanselmann | errors.ECODE_INVAL) |
8448 | 24991749 | Iustin Pop | if nic_op < 0 or nic_op >= len(instance.nics): |
8449 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Invalid NIC index %s, valid values" |
8450 | 24991749 | Iustin Pop | " are 0 to %d" %
|
8451 | 21bcb9aa | Michael Hanselmann | (nic_op, len(instance.nics) - 1), |
8452 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8453 | cd098c41 | Guido Trotter | old_nic_params = instance.nics[nic_op].nicparams |
8454 | cd098c41 | Guido Trotter | old_nic_ip = instance.nics[nic_op].ip |
8455 | cd098c41 | Guido Trotter | else:
|
8456 | cd098c41 | Guido Trotter | old_nic_params = {} |
8457 | cd098c41 | Guido Trotter | old_nic_ip = None
|
8458 | cd098c41 | Guido Trotter | |
8459 | cd098c41 | Guido Trotter | update_params_dict = dict([(key, nic_dict[key])
|
8460 | cd098c41 | Guido Trotter | for key in constants.NICS_PARAMETERS |
8461 | cd098c41 | Guido Trotter | if key in nic_dict]) |
8462 | cd098c41 | Guido Trotter | |
8463 | 5c44da6a | Guido Trotter | if 'bridge' in nic_dict: |
8464 | cd098c41 | Guido Trotter | update_params_dict[constants.NIC_LINK] = nic_dict['bridge']
|
8465 | cd098c41 | Guido Trotter | |
8466 | cd098c41 | Guido Trotter | new_nic_params, new_filled_nic_params = \ |
8467 | cd098c41 | Guido Trotter | self._GetUpdatedParams(old_nic_params, update_params_dict,
|
8468 | cd098c41 | Guido Trotter | cluster.nicparams[constants.PP_DEFAULT], |
8469 | cd098c41 | Guido Trotter | constants.NICS_PARAMETER_TYPES) |
8470 | cd098c41 | Guido Trotter | objects.NIC.CheckParameterSyntax(new_filled_nic_params) |
8471 | cd098c41 | Guido Trotter | self.nic_pinst[nic_op] = new_nic_params
|
8472 | cd098c41 | Guido Trotter | self.nic_pnew[nic_op] = new_filled_nic_params
|
8473 | cd098c41 | Guido Trotter | new_nic_mode = new_filled_nic_params[constants.NIC_MODE] |
8474 | cd098c41 | Guido Trotter | |
8475 | cd098c41 | Guido Trotter | if new_nic_mode == constants.NIC_MODE_BRIDGED:
|
8476 | cd098c41 | Guido Trotter | nic_bridge = new_filled_nic_params[constants.NIC_LINK] |
8477 | 4c4e4e1e | Iustin Pop | msg = self.rpc.call_bridges_exist(pnode, [nic_bridge]).fail_msg
|
8478 | 35c0c8da | Iustin Pop | if msg:
|
8479 | 35c0c8da | Iustin Pop | msg = "Error checking bridges on node %s: %s" % (pnode, msg)
|
8480 | 24991749 | Iustin Pop | if self.force: |
8481 | 24991749 | Iustin Pop | self.warn.append(msg)
|
8482 | 24991749 | Iustin Pop | else:
|
8483 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError(msg, errors.ECODE_ENVIRON)
|
8484 | cd098c41 | Guido Trotter | if new_nic_mode == constants.NIC_MODE_ROUTED:
|
8485 | cd098c41 | Guido Trotter | if 'ip' in nic_dict: |
8486 | cd098c41 | Guido Trotter | nic_ip = nic_dict['ip']
|
8487 | cd098c41 | Guido Trotter | else:
|
8488 | cd098c41 | Guido Trotter | nic_ip = old_nic_ip |
8489 | cd098c41 | Guido Trotter | if nic_ip is None: |
8490 | cd098c41 | Guido Trotter | raise errors.OpPrereqError('Cannot set the nic ip to None' |
8491 | 5c983ee5 | Iustin Pop | ' on a routed nic', errors.ECODE_INVAL)
|
8492 | 5c44da6a | Guido Trotter | if 'mac' in nic_dict: |
8493 | 5c44da6a | Guido Trotter | nic_mac = nic_dict['mac']
|
8494 | 5c44da6a | Guido Trotter | if nic_mac is None: |
8495 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError('Cannot set the nic mac to None', |
8496 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8497 | 5c44da6a | Guido Trotter | elif nic_mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE): |
8498 | 5c44da6a | Guido Trotter | # otherwise generate the mac
|
8499 | 36b66e6e | Guido Trotter | nic_dict['mac'] = self.cfg.GenerateMAC(self.proc.GetECId()) |
8500 | 5c44da6a | Guido Trotter | else:
|
8501 | 5c44da6a | Guido Trotter | # or validate/reserve the current one
|
8502 | 36b66e6e | Guido Trotter | try:
|
8503 | 36b66e6e | Guido Trotter | self.cfg.ReserveMAC(nic_mac, self.proc.GetECId()) |
8504 | 36b66e6e | Guido Trotter | except errors.ReservationError:
|
8505 | 5c44da6a | Guido Trotter | raise errors.OpPrereqError("MAC address %s already in use" |
8506 | 5c983ee5 | Iustin Pop | " in cluster" % nic_mac,
|
8507 | 5c983ee5 | Iustin Pop | errors.ECODE_NOTUNIQUE) |
8508 | 24991749 | Iustin Pop | |
8509 | 24991749 | Iustin Pop | # DISK processing
|
8510 | 24991749 | Iustin Pop | if self.op.disks and instance.disk_template == constants.DT_DISKLESS: |
8511 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Disk operations not supported for" |
8512 | 5c983ee5 | Iustin Pop | " diskless instances",
|
8513 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8514 | 1122eb25 | Iustin Pop | for disk_op, _ in self.op.disks: |
8515 | 24991749 | Iustin Pop | if disk_op == constants.DDM_REMOVE:
|
8516 | 24991749 | Iustin Pop | if len(instance.disks) == 1: |
8517 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Cannot remove the last disk of" |
8518 | 31624382 | Iustin Pop | " an instance", errors.ECODE_INVAL)
|
8519 | 31624382 | Iustin Pop | _CheckInstanceDown(self, instance, "cannot remove disks") |
8520 | 24991749 | Iustin Pop | |
8521 | 24991749 | Iustin Pop | if (disk_op == constants.DDM_ADD and |
8522 | 24991749 | Iustin Pop | len(instance.nics) >= constants.MAX_DISKS):
|
8523 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Instance has too many disks (%d), cannot" |
8524 | 5c983ee5 | Iustin Pop | " add more" % constants.MAX_DISKS,
|
8525 | 5c983ee5 | Iustin Pop | errors.ECODE_STATE) |
8526 | 24991749 | Iustin Pop | if disk_op not in (constants.DDM_ADD, constants.DDM_REMOVE): |
8527 | 24991749 | Iustin Pop | # an existing disk
|
8528 | 24991749 | Iustin Pop | if disk_op < 0 or disk_op >= len(instance.disks): |
8529 | 24991749 | Iustin Pop | raise errors.OpPrereqError("Invalid disk index %s, valid values" |
8530 | 24991749 | Iustin Pop | " are 0 to %d" %
|
8531 | 5c983ee5 | Iustin Pop | (disk_op, len(instance.disks)),
|
8532 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
8533 | 24991749 | Iustin Pop | |
8534 | 96b39bcc | Iustin Pop | # OS change
|
8535 | 96b39bcc | Iustin Pop | if self.op.os_name and not self.op.force: |
8536 | 96b39bcc | Iustin Pop | _CheckNodeHasOS(self, instance.primary_node, self.op.os_name, |
8537 | 96b39bcc | Iustin Pop | self.op.force_variant)
|
8538 | 96b39bcc | Iustin Pop | |
8539 | a8083063 | Iustin Pop | return
|
8540 | a8083063 | Iustin Pop | |
8541 | e29e9550 | Iustin Pop | def _ConvertPlainToDrbd(self, feedback_fn): |
8542 | e29e9550 | Iustin Pop | """Converts an instance from plain to drbd.
|
8543 | e29e9550 | Iustin Pop |
|
8544 | e29e9550 | Iustin Pop | """
|
8545 | e29e9550 | Iustin Pop | feedback_fn("Converting template to drbd")
|
8546 | e29e9550 | Iustin Pop | instance = self.instance
|
8547 | e29e9550 | Iustin Pop | pnode = instance.primary_node |
8548 | e29e9550 | Iustin Pop | snode = self.op.remote_node
|
8549 | e29e9550 | Iustin Pop | |
8550 | e29e9550 | Iustin Pop | # create a fake disk info for _GenerateDiskTemplate
|
8551 | e29e9550 | Iustin Pop | disk_info = [{"size": d.size, "mode": d.mode} for d in instance.disks] |
8552 | e29e9550 | Iustin Pop | new_disks = _GenerateDiskTemplate(self, self.op.disk_template, |
8553 | e29e9550 | Iustin Pop | instance.name, pnode, [snode], |
8554 | e29e9550 | Iustin Pop | disk_info, None, None, 0) |
8555 | e29e9550 | Iustin Pop | info = _GetInstanceInfoText(instance) |
8556 | e29e9550 | Iustin Pop | feedback_fn("Creating aditional volumes...")
|
8557 | e29e9550 | Iustin Pop | # first, create the missing data and meta devices
|
8558 | e29e9550 | Iustin Pop | for disk in new_disks: |
8559 | e29e9550 | Iustin Pop | # unfortunately this is... not too nice
|
8560 | e29e9550 | Iustin Pop | _CreateSingleBlockDev(self, pnode, instance, disk.children[1], |
8561 | e29e9550 | Iustin Pop | info, True)
|
8562 | e29e9550 | Iustin Pop | for child in disk.children: |
8563 | e29e9550 | Iustin Pop | _CreateSingleBlockDev(self, snode, instance, child, info, True) |
8564 | e29e9550 | Iustin Pop | # at this stage, all new LVs have been created, we can rename the
|
8565 | e29e9550 | Iustin Pop | # old ones
|
8566 | e29e9550 | Iustin Pop | feedback_fn("Renaming original volumes...")
|
8567 | e29e9550 | Iustin Pop | rename_list = [(o, n.children[0].logical_id)
|
8568 | e29e9550 | Iustin Pop | for (o, n) in zip(instance.disks, new_disks)] |
8569 | e29e9550 | Iustin Pop | result = self.rpc.call_blockdev_rename(pnode, rename_list)
|
8570 | e29e9550 | Iustin Pop | result.Raise("Failed to rename original LVs")
|
8571 | e29e9550 | Iustin Pop | |
8572 | e29e9550 | Iustin Pop | feedback_fn("Initializing DRBD devices...")
|
8573 | e29e9550 | Iustin Pop | # all child devices are in place, we can now create the DRBD devices
|
8574 | e29e9550 | Iustin Pop | for disk in new_disks: |
8575 | e29e9550 | Iustin Pop | for node in [pnode, snode]: |
8576 | e29e9550 | Iustin Pop | f_create = node == pnode |
8577 | e29e9550 | Iustin Pop | _CreateSingleBlockDev(self, node, instance, disk, info, f_create)
|
8578 | e29e9550 | Iustin Pop | |
8579 | e29e9550 | Iustin Pop | # at this point, the instance has been modified
|
8580 | e29e9550 | Iustin Pop | instance.disk_template = constants.DT_DRBD8 |
8581 | e29e9550 | Iustin Pop | instance.disks = new_disks |
8582 | e29e9550 | Iustin Pop | self.cfg.Update(instance, feedback_fn)
|
8583 | e29e9550 | Iustin Pop | |
8584 | e29e9550 | Iustin Pop | # disks are created, waiting for sync
|
8585 | e29e9550 | Iustin Pop | disk_abort = not _WaitForSync(self, instance) |
8586 | e29e9550 | Iustin Pop | if disk_abort:
|
8587 | e29e9550 | Iustin Pop | raise errors.OpExecError("There are some degraded disks for" |
8588 | e29e9550 | Iustin Pop | " this instance, please cleanup manually")
|
8589 | e29e9550 | Iustin Pop | |
8590 | 2f414c48 | Iustin Pop | def _ConvertDrbdToPlain(self, feedback_fn): |
8591 | 2f414c48 | Iustin Pop | """Converts an instance from drbd to plain.
|
8592 | 2f414c48 | Iustin Pop |
|
8593 | 2f414c48 | Iustin Pop | """
|
8594 | 2f414c48 | Iustin Pop | instance = self.instance
|
8595 | 2f414c48 | Iustin Pop | assert len(instance.secondary_nodes) == 1 |
8596 | 2f414c48 | Iustin Pop | pnode = instance.primary_node |
8597 | 2f414c48 | Iustin Pop | snode = instance.secondary_nodes[0]
|
8598 | 2f414c48 | Iustin Pop | feedback_fn("Converting template to plain")
|
8599 | 2f414c48 | Iustin Pop | |
8600 | 2f414c48 | Iustin Pop | old_disks = instance.disks |
8601 | 2f414c48 | Iustin Pop | new_disks = [d.children[0] for d in old_disks] |
8602 | 2f414c48 | Iustin Pop | |
8603 | 2f414c48 | Iustin Pop | # copy over size and mode
|
8604 | 2f414c48 | Iustin Pop | for parent, child in zip(old_disks, new_disks): |
8605 | 2f414c48 | Iustin Pop | child.size = parent.size |
8606 | 2f414c48 | Iustin Pop | child.mode = parent.mode |
8607 | 2f414c48 | Iustin Pop | |
8608 | 2f414c48 | Iustin Pop | # update instance structure
|
8609 | 2f414c48 | Iustin Pop | instance.disks = new_disks |
8610 | 2f414c48 | Iustin Pop | instance.disk_template = constants.DT_PLAIN |
8611 | 2f414c48 | Iustin Pop | self.cfg.Update(instance, feedback_fn)
|
8612 | 2f414c48 | Iustin Pop | |
8613 | 2f414c48 | Iustin Pop | feedback_fn("Removing volumes on the secondary node...")
|
8614 | 2f414c48 | Iustin Pop | for disk in old_disks: |
8615 | 2f414c48 | Iustin Pop | self.cfg.SetDiskID(disk, snode)
|
8616 | 2f414c48 | Iustin Pop | msg = self.rpc.call_blockdev_remove(snode, disk).fail_msg
|
8617 | 2f414c48 | Iustin Pop | if msg:
|
8618 | 2f414c48 | Iustin Pop | self.LogWarning("Could not remove block device %s on node %s," |
8619 | 2f414c48 | Iustin Pop | " continuing anyway: %s", disk.iv_name, snode, msg)
|
8620 | 2f414c48 | Iustin Pop | |
8621 | 2f414c48 | Iustin Pop | feedback_fn("Removing unneeded volumes on the primary node...")
|
8622 | 2f414c48 | Iustin Pop | for idx, disk in enumerate(old_disks): |
8623 | 2f414c48 | Iustin Pop | meta = disk.children[1]
|
8624 | 2f414c48 | Iustin Pop | self.cfg.SetDiskID(meta, pnode)
|
8625 | 2f414c48 | Iustin Pop | msg = self.rpc.call_blockdev_remove(pnode, meta).fail_msg
|
8626 | 2f414c48 | Iustin Pop | if msg:
|
8627 | 2f414c48 | Iustin Pop | self.LogWarning("Could not remove metadata for disk %d on node %s," |
8628 | 2f414c48 | Iustin Pop | " continuing anyway: %s", idx, pnode, msg)
|
8629 | 2f414c48 | Iustin Pop | |
8630 | 2f414c48 | Iustin Pop | |
8631 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
8632 | a8083063 | Iustin Pop | """Modifies an instance.
|
8633 | a8083063 | Iustin Pop |
|
8634 | a8083063 | Iustin Pop | All parameters take effect only at the next restart of the instance.
|
8635 | 24991749 | Iustin Pop |
|
8636 | a8083063 | Iustin Pop | """
|
8637 | cfefe007 | Guido Trotter | # Process here the warnings from CheckPrereq, as we don't have a
|
8638 | cfefe007 | Guido Trotter | # feedback_fn there.
|
8639 | cfefe007 | Guido Trotter | for warn in self.warn: |
8640 | cfefe007 | Guido Trotter | feedback_fn("WARNING: %s" % warn)
|
8641 | cfefe007 | Guido Trotter | |
8642 | a8083063 | Iustin Pop | result = [] |
8643 | a8083063 | Iustin Pop | instance = self.instance
|
8644 | 24991749 | Iustin Pop | # disk changes
|
8645 | 24991749 | Iustin Pop | for disk_op, disk_dict in self.op.disks: |
8646 | 24991749 | Iustin Pop | if disk_op == constants.DDM_REMOVE:
|
8647 | 24991749 | Iustin Pop | # remove the last disk
|
8648 | 24991749 | Iustin Pop | device = instance.disks.pop() |
8649 | 24991749 | Iustin Pop | device_idx = len(instance.disks)
|
8650 | 24991749 | Iustin Pop | for node, disk in device.ComputeNodeTree(instance.primary_node): |
8651 | 24991749 | Iustin Pop | self.cfg.SetDiskID(disk, node)
|
8652 | 4c4e4e1e | Iustin Pop | msg = self.rpc.call_blockdev_remove(node, disk).fail_msg
|
8653 | e1bc0878 | Iustin Pop | if msg:
|
8654 | e1bc0878 | Iustin Pop | self.LogWarning("Could not remove disk/%d on node %s: %s," |
8655 | e1bc0878 | Iustin Pop | " continuing anyway", device_idx, node, msg)
|
8656 | 24991749 | Iustin Pop | result.append(("disk/%d" % device_idx, "remove")) |
8657 | 24991749 | Iustin Pop | elif disk_op == constants.DDM_ADD:
|
8658 | 24991749 | Iustin Pop | # add a new disk
|
8659 | 24991749 | Iustin Pop | if instance.disk_template == constants.DT_FILE:
|
8660 | 24991749 | Iustin Pop | file_driver, file_path = instance.disks[0].logical_id
|
8661 | 24991749 | Iustin Pop | file_path = os.path.dirname(file_path) |
8662 | 24991749 | Iustin Pop | else:
|
8663 | 24991749 | Iustin Pop | file_driver = file_path = None
|
8664 | 24991749 | Iustin Pop | disk_idx_base = len(instance.disks)
|
8665 | 24991749 | Iustin Pop | new_disk = _GenerateDiskTemplate(self,
|
8666 | 24991749 | Iustin Pop | instance.disk_template, |
8667 | 32388e6d | Iustin Pop | instance.name, instance.primary_node, |
8668 | 24991749 | Iustin Pop | instance.secondary_nodes, |
8669 | 24991749 | Iustin Pop | [disk_dict], |
8670 | 24991749 | Iustin Pop | file_path, |
8671 | 24991749 | Iustin Pop | file_driver, |
8672 | 24991749 | Iustin Pop | disk_idx_base)[0]
|
8673 | 24991749 | Iustin Pop | instance.disks.append(new_disk) |
8674 | 24991749 | Iustin Pop | info = _GetInstanceInfoText(instance) |
8675 | 24991749 | Iustin Pop | |
8676 | 24991749 | Iustin Pop | logging.info("Creating volume %s for instance %s",
|
8677 | 24991749 | Iustin Pop | new_disk.iv_name, instance.name) |
8678 | 24991749 | Iustin Pop | # Note: this needs to be kept in sync with _CreateDisks
|
8679 | 24991749 | Iustin Pop | #HARDCODE
|
8680 | 428958aa | Iustin Pop | for node in instance.all_nodes: |
8681 | 428958aa | Iustin Pop | f_create = node == instance.primary_node |
8682 | 796cab27 | Iustin Pop | try:
|
8683 | 428958aa | Iustin Pop | _CreateBlockDev(self, node, instance, new_disk,
|
8684 | 428958aa | Iustin Pop | f_create, info, f_create) |
8685 | 1492cca7 | Iustin Pop | except errors.OpExecError, err:
|
8686 | 24991749 | Iustin Pop | self.LogWarning("Failed to create volume %s (%s) on" |
8687 | 428958aa | Iustin Pop | " node %s: %s",
|
8688 | 428958aa | Iustin Pop | new_disk.iv_name, new_disk, node, err) |
8689 | 24991749 | Iustin Pop | result.append(("disk/%d" % disk_idx_base, "add:size=%s,mode=%s" % |
8690 | 24991749 | Iustin Pop | (new_disk.size, new_disk.mode))) |
8691 | 24991749 | Iustin Pop | else:
|
8692 | 24991749 | Iustin Pop | # change a given disk
|
8693 | 24991749 | Iustin Pop | instance.disks[disk_op].mode = disk_dict['mode']
|
8694 | 24991749 | Iustin Pop | result.append(("disk.mode/%d" % disk_op, disk_dict['mode'])) |
8695 | e29e9550 | Iustin Pop | |
8696 | e29e9550 | Iustin Pop | if self.op.disk_template: |
8697 | e29e9550 | Iustin Pop | r_shut = _ShutdownInstanceDisks(self, instance)
|
8698 | e29e9550 | Iustin Pop | if not r_shut: |
8699 | e29e9550 | Iustin Pop | raise errors.OpExecError("Cannot shutdow instance disks, unable to" |
8700 | e29e9550 | Iustin Pop | " proceed with disk template conversion")
|
8701 | e29e9550 | Iustin Pop | mode = (instance.disk_template, self.op.disk_template)
|
8702 | e29e9550 | Iustin Pop | try:
|
8703 | e29e9550 | Iustin Pop | self._DISK_CONVERSIONS[mode](self, feedback_fn) |
8704 | e29e9550 | Iustin Pop | except:
|
8705 | e29e9550 | Iustin Pop | self.cfg.ReleaseDRBDMinors(instance.name)
|
8706 | e29e9550 | Iustin Pop | raise
|
8707 | e29e9550 | Iustin Pop | result.append(("disk_template", self.op.disk_template)) |
8708 | e29e9550 | Iustin Pop | |
8709 | 24991749 | Iustin Pop | # NIC changes
|
8710 | 24991749 | Iustin Pop | for nic_op, nic_dict in self.op.nics: |
8711 | 24991749 | Iustin Pop | if nic_op == constants.DDM_REMOVE:
|
8712 | 24991749 | Iustin Pop | # remove the last nic
|
8713 | 24991749 | Iustin Pop | del instance.nics[-1] |
8714 | 24991749 | Iustin Pop | result.append(("nic.%d" % len(instance.nics), "remove")) |
8715 | 24991749 | Iustin Pop | elif nic_op == constants.DDM_ADD:
|
8716 | 5c44da6a | Guido Trotter | # mac and bridge should be set, by now
|
8717 | 5c44da6a | Guido Trotter | mac = nic_dict['mac']
|
8718 | cd098c41 | Guido Trotter | ip = nic_dict.get('ip', None) |
8719 | cd098c41 | Guido Trotter | nicparams = self.nic_pinst[constants.DDM_ADD]
|
8720 | cd098c41 | Guido Trotter | new_nic = objects.NIC(mac=mac, ip=ip, nicparams=nicparams) |
8721 | 24991749 | Iustin Pop | instance.nics.append(new_nic) |
8722 | 24991749 | Iustin Pop | result.append(("nic.%d" % (len(instance.nics) - 1), |
8723 | cd098c41 | Guido Trotter | "add:mac=%s,ip=%s,mode=%s,link=%s" %
|
8724 | cd098c41 | Guido Trotter | (new_nic.mac, new_nic.ip, |
8725 | cd098c41 | Guido Trotter | self.nic_pnew[constants.DDM_ADD][constants.NIC_MODE],
|
8726 | cd098c41 | Guido Trotter | self.nic_pnew[constants.DDM_ADD][constants.NIC_LINK]
|
8727 | cd098c41 | Guido Trotter | ))) |
8728 | 24991749 | Iustin Pop | else:
|
8729 | cd098c41 | Guido Trotter | for key in 'mac', 'ip': |
8730 | 24991749 | Iustin Pop | if key in nic_dict: |
8731 | 24991749 | Iustin Pop | setattr(instance.nics[nic_op], key, nic_dict[key])
|
8732 | beabf067 | Guido Trotter | if nic_op in self.nic_pinst: |
8733 | beabf067 | Guido Trotter | instance.nics[nic_op].nicparams = self.nic_pinst[nic_op]
|
8734 | cd098c41 | Guido Trotter | for key, val in nic_dict.iteritems(): |
8735 | cd098c41 | Guido Trotter | result.append(("nic.%s/%d" % (key, nic_op), val))
|
8736 | 24991749 | Iustin Pop | |
8737 | 24991749 | Iustin Pop | # hvparams changes
|
8738 | 74409b12 | Iustin Pop | if self.op.hvparams: |
8739 | 12649e35 | Guido Trotter | instance.hvparams = self.hv_inst
|
8740 | 74409b12 | Iustin Pop | for key, val in self.op.hvparams.iteritems(): |
8741 | 74409b12 | Iustin Pop | result.append(("hv/%s" % key, val))
|
8742 | 24991749 | Iustin Pop | |
8743 | 24991749 | Iustin Pop | # beparams changes
|
8744 | 338e51e8 | Iustin Pop | if self.op.beparams: |
8745 | 338e51e8 | Iustin Pop | instance.beparams = self.be_inst
|
8746 | 338e51e8 | Iustin Pop | for key, val in self.op.beparams.iteritems(): |
8747 | 338e51e8 | Iustin Pop | result.append(("be/%s" % key, val))
|
8748 | a8083063 | Iustin Pop | |
8749 | 96b39bcc | Iustin Pop | # OS change
|
8750 | 96b39bcc | Iustin Pop | if self.op.os_name: |
8751 | 96b39bcc | Iustin Pop | instance.os = self.op.os_name
|
8752 | 96b39bcc | Iustin Pop | |
8753 | a4eae71f | Michael Hanselmann | self.cfg.Update(instance, feedback_fn)
|
8754 | a8083063 | Iustin Pop | |
8755 | a8083063 | Iustin Pop | return result
|
8756 | a8083063 | Iustin Pop | |
8757 | e29e9550 | Iustin Pop | _DISK_CONVERSIONS = { |
8758 | e29e9550 | Iustin Pop | (constants.DT_PLAIN, constants.DT_DRBD8): _ConvertPlainToDrbd, |
8759 | 2f414c48 | Iustin Pop | (constants.DT_DRBD8, constants.DT_PLAIN): _ConvertDrbdToPlain, |
8760 | e29e9550 | Iustin Pop | } |
8761 | a8083063 | Iustin Pop | |
8762 | a8083063 | Iustin Pop | class LUQueryExports(NoHooksLU): |
8763 | a8083063 | Iustin Pop | """Query the exports list
|
8764 | a8083063 | Iustin Pop |
|
8765 | a8083063 | Iustin Pop | """
|
8766 | 895ecd9c | Guido Trotter | _OP_REQP = ['nodes']
|
8767 | 21a15682 | Guido Trotter | REQ_BGL = False
|
8768 | 21a15682 | Guido Trotter | |
8769 | 21a15682 | Guido Trotter | def ExpandNames(self): |
8770 | 21a15682 | Guido Trotter | self.needed_locks = {}
|
8771 | 21a15682 | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
8772 | 21a15682 | Guido Trotter | if not self.op.nodes: |
8773 | e310b019 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
8774 | 21a15682 | Guido Trotter | else:
|
8775 | 21a15682 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = \
|
8776 | 21a15682 | Guido Trotter | _GetWantedNodes(self, self.op.nodes) |
8777 | a8083063 | Iustin Pop | |
8778 | a8083063 | Iustin Pop | def CheckPrereq(self): |
8779 | 21a15682 | Guido Trotter | """Check prerequisites.
|
8780 | a8083063 | Iustin Pop |
|
8781 | a8083063 | Iustin Pop | """
|
8782 | 21a15682 | Guido Trotter | self.nodes = self.acquired_locks[locking.LEVEL_NODE] |
8783 | a8083063 | Iustin Pop | |
8784 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
8785 | a8083063 | Iustin Pop | """Compute the list of all the exported system images.
|
8786 | a8083063 | Iustin Pop |
|
8787 | e4376078 | Iustin Pop | @rtype: dict
|
8788 | e4376078 | Iustin Pop | @return: a dictionary with the structure node->(export-list)
|
8789 | e4376078 | Iustin Pop | where export-list is a list of the instances exported on
|
8790 | e4376078 | Iustin Pop | that node.
|
8791 | a8083063 | Iustin Pop |
|
8792 | a8083063 | Iustin Pop | """
|
8793 | b04285f2 | Guido Trotter | rpcresult = self.rpc.call_export_list(self.nodes) |
8794 | b04285f2 | Guido Trotter | result = {} |
8795 | b04285f2 | Guido Trotter | for node in rpcresult: |
8796 | 4c4e4e1e | Iustin Pop | if rpcresult[node].fail_msg:
|
8797 | b04285f2 | Guido Trotter | result[node] = False
|
8798 | b04285f2 | Guido Trotter | else:
|
8799 | 1b7bfbb7 | Iustin Pop | result[node] = rpcresult[node].payload |
8800 | b04285f2 | Guido Trotter | |
8801 | b04285f2 | Guido Trotter | return result
|
8802 | a8083063 | Iustin Pop | |
8803 | a8083063 | Iustin Pop | |
8804 | a8083063 | Iustin Pop | class LUExportInstance(LogicalUnit): |
8805 | a8083063 | Iustin Pop | """Export an instance to an image in the cluster.
|
8806 | a8083063 | Iustin Pop |
|
8807 | a8083063 | Iustin Pop | """
|
8808 | a8083063 | Iustin Pop | HPATH = "instance-export"
|
8809 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_INSTANCE |
8810 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name", "target_node", "shutdown"] |
8811 | 6657590e | Guido Trotter | REQ_BGL = False
|
8812 | 6657590e | Guido Trotter | |
8813 | 17c3f802 | Guido Trotter | def CheckArguments(self): |
8814 | 17c3f802 | Guido Trotter | """Check the arguments.
|
8815 | 17c3f802 | Guido Trotter |
|
8816 | 17c3f802 | Guido Trotter | """
|
8817 | 17c3f802 | Guido Trotter | self.shutdown_timeout = getattr(self.op, "shutdown_timeout", |
8818 | 17c3f802 | Guido Trotter | constants.DEFAULT_SHUTDOWN_TIMEOUT) |
8819 | 17c3f802 | Guido Trotter | |
8820 | 6657590e | Guido Trotter | def ExpandNames(self): |
8821 | 6657590e | Guido Trotter | self._ExpandAndLockInstance()
|
8822 | 6657590e | Guido Trotter | # FIXME: lock only instance primary and destination node
|
8823 | 6657590e | Guido Trotter | #
|
8824 | 6657590e | Guido Trotter | # Sad but true, for now we have do lock all nodes, as we don't know where
|
8825 | 6657590e | Guido Trotter | # the previous export might be, and and in this LU we search for it and
|
8826 | 6657590e | Guido Trotter | # remove it from its current node. In the future we could fix this by:
|
8827 | 6657590e | Guido Trotter | # - making a tasklet to search (share-lock all), then create the new one,
|
8828 | 6657590e | Guido Trotter | # then one to remove, after
|
8829 | 5bbd3f7f | Michael Hanselmann | # - removing the removal operation altogether
|
8830 | 6657590e | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
8831 | 6657590e | Guido Trotter | |
8832 | 6657590e | Guido Trotter | def DeclareLocks(self, level): |
8833 | 6657590e | Guido Trotter | """Last minute lock declaration."""
|
8834 | 6657590e | Guido Trotter | # All nodes are locked anyway, so nothing to do here.
|
8835 | a8083063 | Iustin Pop | |
8836 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
8837 | a8083063 | Iustin Pop | """Build hooks env.
|
8838 | a8083063 | Iustin Pop |
|
8839 | a8083063 | Iustin Pop | This will run on the master, primary node and target node.
|
8840 | a8083063 | Iustin Pop |
|
8841 | a8083063 | Iustin Pop | """
|
8842 | a8083063 | Iustin Pop | env = { |
8843 | a8083063 | Iustin Pop | "EXPORT_NODE": self.op.target_node, |
8844 | a8083063 | Iustin Pop | "EXPORT_DO_SHUTDOWN": self.op.shutdown, |
8845 | 17c3f802 | Guido Trotter | "SHUTDOWN_TIMEOUT": self.shutdown_timeout, |
8846 | a8083063 | Iustin Pop | } |
8847 | 338e51e8 | Iustin Pop | env.update(_BuildInstanceHookEnvByObject(self, self.instance)) |
8848 | d6a02168 | Michael Hanselmann | nl = [self.cfg.GetMasterNode(), self.instance.primary_node, |
8849 | a8083063 | Iustin Pop | self.op.target_node]
|
8850 | a8083063 | Iustin Pop | return env, nl, nl
|
8851 | a8083063 | Iustin Pop | |
8852 | a8083063 | Iustin Pop | def CheckPrereq(self): |
8853 | a8083063 | Iustin Pop | """Check prerequisites.
|
8854 | a8083063 | Iustin Pop |
|
8855 | 9ac99fda | Guido Trotter | This checks that the instance and node names are valid.
|
8856 | a8083063 | Iustin Pop |
|
8857 | a8083063 | Iustin Pop | """
|
8858 | 6657590e | Guido Trotter | instance_name = self.op.instance_name
|
8859 | a8083063 | Iustin Pop | self.instance = self.cfg.GetInstanceInfo(instance_name) |
8860 | 6657590e | Guido Trotter | assert self.instance is not None, \ |
8861 | 6657590e | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
8862 | 43017d26 | Iustin Pop | _CheckNodeOnline(self, self.instance.primary_node) |
8863 | a8083063 | Iustin Pop | |
8864 | cf26a87a | Iustin Pop | self.op.target_node = _ExpandNodeName(self.cfg, self.op.target_node) |
8865 | cf26a87a | Iustin Pop | self.dst_node = self.cfg.GetNodeInfo(self.op.target_node) |
8866 | cf26a87a | Iustin Pop | assert self.dst_node is not None |
8867 | a8083063 | Iustin Pop | |
8868 | aeb83a2b | Iustin Pop | _CheckNodeOnline(self, self.dst_node.name) |
8869 | 733a2b6a | Iustin Pop | _CheckNodeNotDrained(self, self.dst_node.name) |
8870 | a8083063 | Iustin Pop | |
8871 | b6023d6c | Manuel Franceschini | # instance disk type verification
|
8872 | b6023d6c | Manuel Franceschini | for disk in self.instance.disks: |
8873 | b6023d6c | Manuel Franceschini | if disk.dev_type == constants.LD_FILE:
|
8874 | b6023d6c | Manuel Franceschini | raise errors.OpPrereqError("Export not supported for instances with" |
8875 | 5c983ee5 | Iustin Pop | " file-based disks", errors.ECODE_INVAL)
|
8876 | b6023d6c | Manuel Franceschini | |
8877 | e311ed53 | Michael Hanselmann | def _CreateSnapshots(self, feedback_fn): |
8878 | e311ed53 | Michael Hanselmann | """Creates an LVM snapshot for every disk of the instance.
|
8879 | e311ed53 | Michael Hanselmann |
|
8880 | e311ed53 | Michael Hanselmann | @return: List of snapshots as L{objects.Disk} instances
|
8881 | e311ed53 | Michael Hanselmann |
|
8882 | e311ed53 | Michael Hanselmann | """
|
8883 | e311ed53 | Michael Hanselmann | instance = self.instance
|
8884 | e311ed53 | Michael Hanselmann | src_node = instance.primary_node |
8885 | e311ed53 | Michael Hanselmann | |
8886 | e311ed53 | Michael Hanselmann | vgname = self.cfg.GetVGName()
|
8887 | e311ed53 | Michael Hanselmann | |
8888 | e311ed53 | Michael Hanselmann | snap_disks = [] |
8889 | e311ed53 | Michael Hanselmann | |
8890 | e311ed53 | Michael Hanselmann | for idx, disk in enumerate(instance.disks): |
8891 | e311ed53 | Michael Hanselmann | feedback_fn("Creating a snapshot of disk/%s on node %s" %
|
8892 | e311ed53 | Michael Hanselmann | (idx, src_node)) |
8893 | e311ed53 | Michael Hanselmann | |
8894 | e311ed53 | Michael Hanselmann | # result.payload will be a snapshot of an lvm leaf of the one we
|
8895 | e311ed53 | Michael Hanselmann | # passed
|
8896 | e311ed53 | Michael Hanselmann | result = self.rpc.call_blockdev_snapshot(src_node, disk)
|
8897 | e311ed53 | Michael Hanselmann | msg = result.fail_msg |
8898 | e311ed53 | Michael Hanselmann | if msg:
|
8899 | e311ed53 | Michael Hanselmann | self.LogWarning("Could not snapshot disk/%s on node %s: %s", |
8900 | e311ed53 | Michael Hanselmann | idx, src_node, msg) |
8901 | e311ed53 | Michael Hanselmann | snap_disks.append(False)
|
8902 | e311ed53 | Michael Hanselmann | else:
|
8903 | e311ed53 | Michael Hanselmann | disk_id = (vgname, result.payload) |
8904 | e311ed53 | Michael Hanselmann | new_dev = objects.Disk(dev_type=constants.LD_LV, size=disk.size, |
8905 | e311ed53 | Michael Hanselmann | logical_id=disk_id, physical_id=disk_id, |
8906 | e311ed53 | Michael Hanselmann | iv_name=disk.iv_name) |
8907 | e311ed53 | Michael Hanselmann | snap_disks.append(new_dev) |
8908 | e311ed53 | Michael Hanselmann | |
8909 | e311ed53 | Michael Hanselmann | return snap_disks
|
8910 | e311ed53 | Michael Hanselmann | |
8911 | e311ed53 | Michael Hanselmann | def _RemoveSnapshot(self, feedback_fn, snap_disks, disk_index): |
8912 | e311ed53 | Michael Hanselmann | """Removes an LVM snapshot.
|
8913 | e311ed53 | Michael Hanselmann |
|
8914 | e311ed53 | Michael Hanselmann | @type snap_disks: list
|
8915 | e311ed53 | Michael Hanselmann | @param snap_disks: The list of all snapshots as returned by
|
8916 | e311ed53 | Michael Hanselmann | L{_CreateSnapshots}
|
8917 | e311ed53 | Michael Hanselmann | @type disk_index: number
|
8918 | e311ed53 | Michael Hanselmann | @param disk_index: Index of the snapshot to be removed
|
8919 | e311ed53 | Michael Hanselmann | @rtype: bool
|
8920 | e311ed53 | Michael Hanselmann | @return: Whether removal was successful or not
|
8921 | e311ed53 | Michael Hanselmann |
|
8922 | e311ed53 | Michael Hanselmann | """
|
8923 | e311ed53 | Michael Hanselmann | disk = snap_disks[disk_index] |
8924 | e311ed53 | Michael Hanselmann | if disk:
|
8925 | e311ed53 | Michael Hanselmann | src_node = self.instance.primary_node
|
8926 | e311ed53 | Michael Hanselmann | |
8927 | e311ed53 | Michael Hanselmann | feedback_fn("Removing snapshot of disk/%s on node %s" %
|
8928 | e311ed53 | Michael Hanselmann | (disk_index, src_node)) |
8929 | e311ed53 | Michael Hanselmann | |
8930 | e311ed53 | Michael Hanselmann | result = self.rpc.call_blockdev_remove(src_node, disk)
|
8931 | e311ed53 | Michael Hanselmann | if not result.fail_msg: |
8932 | e311ed53 | Michael Hanselmann | return True |
8933 | e311ed53 | Michael Hanselmann | |
8934 | e311ed53 | Michael Hanselmann | self.LogWarning("Could not remove snapshot for disk/%d from node" |
8935 | e311ed53 | Michael Hanselmann | " %s: %s", disk_index, src_node, result.fail_msg)
|
8936 | e311ed53 | Michael Hanselmann | |
8937 | e311ed53 | Michael Hanselmann | return False |
8938 | e311ed53 | Michael Hanselmann | |
8939 | e311ed53 | Michael Hanselmann | def _CleanupExports(self, feedback_fn): |
8940 | e311ed53 | Michael Hanselmann | """Removes exports of current instance from all other nodes.
|
8941 | e311ed53 | Michael Hanselmann |
|
8942 | e311ed53 | Michael Hanselmann | If an instance in a cluster with nodes A..D was exported to node C, its
|
8943 | e311ed53 | Michael Hanselmann | exports will be removed from the nodes A, B and D.
|
8944 | e311ed53 | Michael Hanselmann |
|
8945 | e311ed53 | Michael Hanselmann | """
|
8946 | e311ed53 | Michael Hanselmann | nodelist = self.cfg.GetNodeList()
|
8947 | e311ed53 | Michael Hanselmann | nodelist.remove(self.dst_node.name)
|
8948 | e311ed53 | Michael Hanselmann | |
8949 | e311ed53 | Michael Hanselmann | # on one-node clusters nodelist will be empty after the removal
|
8950 | e311ed53 | Michael Hanselmann | # if we proceed the backup would be removed because OpQueryExports
|
8951 | e311ed53 | Michael Hanselmann | # substitutes an empty list with the full cluster node list.
|
8952 | e311ed53 | Michael Hanselmann | iname = self.instance.name
|
8953 | e311ed53 | Michael Hanselmann | if nodelist:
|
8954 | e311ed53 | Michael Hanselmann | feedback_fn("Removing old exports for instance %s" % iname)
|
8955 | e311ed53 | Michael Hanselmann | exportlist = self.rpc.call_export_list(nodelist)
|
8956 | e311ed53 | Michael Hanselmann | for node in exportlist: |
8957 | e311ed53 | Michael Hanselmann | if exportlist[node].fail_msg:
|
8958 | e311ed53 | Michael Hanselmann | continue
|
8959 | e311ed53 | Michael Hanselmann | if iname in exportlist[node].payload: |
8960 | e311ed53 | Michael Hanselmann | msg = self.rpc.call_export_remove(node, iname).fail_msg
|
8961 | e311ed53 | Michael Hanselmann | if msg:
|
8962 | e311ed53 | Michael Hanselmann | self.LogWarning("Could not remove older export for instance %s" |
8963 | e311ed53 | Michael Hanselmann | " on node %s: %s", iname, node, msg)
|
8964 | e311ed53 | Michael Hanselmann | |
8965 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
8966 | a8083063 | Iustin Pop | """Export an instance to an image in the cluster.
|
8967 | a8083063 | Iustin Pop |
|
8968 | a8083063 | Iustin Pop | """
|
8969 | a8083063 | Iustin Pop | instance = self.instance
|
8970 | a8083063 | Iustin Pop | dst_node = self.dst_node
|
8971 | a8083063 | Iustin Pop | src_node = instance.primary_node |
8972 | 37972df0 | Michael Hanselmann | |
8973 | a8083063 | Iustin Pop | if self.op.shutdown: |
8974 | fb300fb7 | Guido Trotter | # shutdown the instance, but not the disks
|
8975 | 37972df0 | Michael Hanselmann | feedback_fn("Shutting down instance %s" % instance.name)
|
8976 | 17c3f802 | Guido Trotter | result = self.rpc.call_instance_shutdown(src_node, instance,
|
8977 | 17c3f802 | Guido Trotter | self.shutdown_timeout)
|
8978 | 4c4e4e1e | Iustin Pop | result.Raise("Could not shutdown instance %s on"
|
8979 | 4c4e4e1e | Iustin Pop | " node %s" % (instance.name, src_node))
|
8980 | a8083063 | Iustin Pop | |
8981 | 998c712c | Iustin Pop | # set the disks ID correctly since call_instance_start needs the
|
8982 | 998c712c | Iustin Pop | # correct drbd minor to create the symlinks
|
8983 | 998c712c | Iustin Pop | for disk in instance.disks: |
8984 | 998c712c | Iustin Pop | self.cfg.SetDiskID(disk, src_node)
|
8985 | 998c712c | Iustin Pop | |
8986 | 3e53a60b | Michael Hanselmann | activate_disks = (not instance.admin_up)
|
8987 | 3e53a60b | Michael Hanselmann | |
8988 | 3e53a60b | Michael Hanselmann | if activate_disks:
|
8989 | 3e53a60b | Michael Hanselmann | # Activate the instance disks if we'exporting a stopped instance
|
8990 | 3e53a60b | Michael Hanselmann | feedback_fn("Activating disks for %s" % instance.name)
|
8991 | 3e53a60b | Michael Hanselmann | _StartInstanceDisks(self, instance, None) |
8992 | 3e53a60b | Michael Hanselmann | |
8993 | a8083063 | Iustin Pop | try:
|
8994 | 3e53a60b | Michael Hanselmann | # per-disk results
|
8995 | 3e53a60b | Michael Hanselmann | dresults = [] |
8996 | e311ed53 | Michael Hanselmann | removed_snaps = [False] * len(instance.disks) |
8997 | e311ed53 | Michael Hanselmann | |
8998 | e311ed53 | Michael Hanselmann | snap_disks = None
|
8999 | 3e53a60b | Michael Hanselmann | try:
|
9000 | e311ed53 | Michael Hanselmann | try:
|
9001 | e311ed53 | Michael Hanselmann | snap_disks = self._CreateSnapshots(feedback_fn)
|
9002 | e311ed53 | Michael Hanselmann | finally:
|
9003 | e311ed53 | Michael Hanselmann | if self.op.shutdown and instance.admin_up: |
9004 | e311ed53 | Michael Hanselmann | feedback_fn("Starting instance %s" % instance.name)
|
9005 | e311ed53 | Michael Hanselmann | result = self.rpc.call_instance_start(src_node, instance,
|
9006 | e311ed53 | Michael Hanselmann | None, None) |
9007 | e311ed53 | Michael Hanselmann | msg = result.fail_msg |
9008 | e311ed53 | Michael Hanselmann | if msg:
|
9009 | e311ed53 | Michael Hanselmann | _ShutdownInstanceDisks(self, instance)
|
9010 | e311ed53 | Michael Hanselmann | raise errors.OpExecError("Could not start instance: %s" % msg) |
9011 | 37972df0 | Michael Hanselmann | |
9012 | e311ed53 | Michael Hanselmann | assert len(snap_disks) == len(instance.disks) |
9013 | e311ed53 | Michael Hanselmann | assert len(removed_snaps) == len(instance.disks) |
9014 | e311ed53 | Michael Hanselmann | |
9015 | e311ed53 | Michael Hanselmann | # TODO: check for size
|
9016 | e311ed53 | Michael Hanselmann | |
9017 | e311ed53 | Michael Hanselmann | cluster_name = self.cfg.GetClusterName()
|
9018 | e311ed53 | Michael Hanselmann | for idx, dev in enumerate(snap_disks): |
9019 | e311ed53 | Michael Hanselmann | feedback_fn("Exporting snapshot %s from %s to %s" %
|
9020 | e311ed53 | Michael Hanselmann | (idx, src_node, dst_node.name)) |
9021 | e311ed53 | Michael Hanselmann | if dev:
|
9022 | e311ed53 | Michael Hanselmann | # FIXME: pass debug from opcode to backend
|
9023 | e311ed53 | Michael Hanselmann | result = self.rpc.call_snapshot_export(src_node, dev, dst_node.name,
|
9024 | e311ed53 | Michael Hanselmann | instance, cluster_name, |
9025 | e311ed53 | Michael Hanselmann | idx, self.op.debug_level)
|
9026 | e311ed53 | Michael Hanselmann | msg = result.fail_msg |
9027 | e311ed53 | Michael Hanselmann | if msg:
|
9028 | e311ed53 | Michael Hanselmann | self.LogWarning("Could not export disk/%s from node %s to" |
9029 | e311ed53 | Michael Hanselmann | " node %s: %s", idx, src_node, dst_node.name, msg)
|
9030 | e311ed53 | Michael Hanselmann | dresults.append(False)
|
9031 | e311ed53 | Michael Hanselmann | else:
|
9032 | e311ed53 | Michael Hanselmann | dresults.append(True)
|
9033 | e311ed53 | Michael Hanselmann | |
9034 | e311ed53 | Michael Hanselmann | # Remove snapshot
|
9035 | e311ed53 | Michael Hanselmann | if self._RemoveSnapshot(feedback_fn, snap_disks, idx): |
9036 | e311ed53 | Michael Hanselmann | removed_snaps[idx] = True
|
9037 | 3e53a60b | Michael Hanselmann | else:
|
9038 | e311ed53 | Michael Hanselmann | dresults.append(False)
|
9039 | a8083063 | Iustin Pop | |
9040 | e311ed53 | Michael Hanselmann | assert len(dresults) == len(instance.disks) |
9041 | e311ed53 | Michael Hanselmann | |
9042 | e311ed53 | Michael Hanselmann | # Check for backwards compatibility
|
9043 | e311ed53 | Michael Hanselmann | assert compat.all(isinstance(i, bool) for i in dresults), \ |
9044 | e311ed53 | Michael Hanselmann | "Not all results are boolean: %r" % dresults
|
9045 | e311ed53 | Michael Hanselmann | |
9046 | e311ed53 | Michael Hanselmann | feedback_fn("Finalizing export on %s" % dst_node.name)
|
9047 | e311ed53 | Michael Hanselmann | result = self.rpc.call_finalize_export(dst_node.name, instance,
|
9048 | e311ed53 | Michael Hanselmann | snap_disks) |
9049 | e311ed53 | Michael Hanselmann | msg = result.fail_msg |
9050 | e311ed53 | Michael Hanselmann | fin_resu = not msg
|
9051 | e311ed53 | Michael Hanselmann | if msg:
|
9052 | e311ed53 | Michael Hanselmann | self.LogWarning("Could not finalize export for instance %s" |
9053 | e311ed53 | Michael Hanselmann | " on node %s: %s", instance.name, dst_node.name, msg)
|
9054 | e311ed53 | Michael Hanselmann | |
9055 | e311ed53 | Michael Hanselmann | finally:
|
9056 | e311ed53 | Michael Hanselmann | # Remove all snapshots
|
9057 | e311ed53 | Michael Hanselmann | assert len(removed_snaps) == len(instance.disks) |
9058 | e311ed53 | Michael Hanselmann | for idx, removed in enumerate(removed_snaps): |
9059 | e311ed53 | Michael Hanselmann | if not removed: |
9060 | e311ed53 | Michael Hanselmann | self._RemoveSnapshot(feedback_fn, snap_disks, idx)
|
9061 | 3e53a60b | Michael Hanselmann | |
9062 | 3e53a60b | Michael Hanselmann | finally:
|
9063 | 3e53a60b | Michael Hanselmann | if activate_disks:
|
9064 | 3e53a60b | Michael Hanselmann | feedback_fn("Deactivating disks for %s" % instance.name)
|
9065 | 3e53a60b | Michael Hanselmann | _ShutdownInstanceDisks(self, instance)
|
9066 | a8083063 | Iustin Pop | |
9067 | e311ed53 | Michael Hanselmann | self._CleanupExports(feedback_fn)
|
9068 | a8083063 | Iustin Pop | |
9069 | 084f05a5 | Iustin Pop | return fin_resu, dresults
|
9070 | 5c947f38 | Iustin Pop | |
9071 | 5c947f38 | Iustin Pop | |
9072 | 9ac99fda | Guido Trotter | class LURemoveExport(NoHooksLU): |
9073 | 9ac99fda | Guido Trotter | """Remove exports related to the named instance.
|
9074 | 9ac99fda | Guido Trotter |
|
9075 | 9ac99fda | Guido Trotter | """
|
9076 | 9ac99fda | Guido Trotter | _OP_REQP = ["instance_name"]
|
9077 | 3656b3af | Guido Trotter | REQ_BGL = False
|
9078 | 3656b3af | Guido Trotter | |
9079 | 3656b3af | Guido Trotter | def ExpandNames(self): |
9080 | 3656b3af | Guido Trotter | self.needed_locks = {}
|
9081 | 3656b3af | Guido Trotter | # We need all nodes to be locked in order for RemoveExport to work, but we
|
9082 | 3656b3af | Guido Trotter | # don't need to lock the instance itself, as nothing will happen to it (and
|
9083 | 3656b3af | Guido Trotter | # we can remove exports also for a removed instance)
|
9084 | 3656b3af | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
9085 | 9ac99fda | Guido Trotter | |
9086 | 9ac99fda | Guido Trotter | def CheckPrereq(self): |
9087 | 9ac99fda | Guido Trotter | """Check prerequisites.
|
9088 | 9ac99fda | Guido Trotter | """
|
9089 | 9ac99fda | Guido Trotter | pass
|
9090 | 9ac99fda | Guido Trotter | |
9091 | 9ac99fda | Guido Trotter | def Exec(self, feedback_fn): |
9092 | 9ac99fda | Guido Trotter | """Remove any export.
|
9093 | 9ac99fda | Guido Trotter |
|
9094 | 9ac99fda | Guido Trotter | """
|
9095 | 9ac99fda | Guido Trotter | instance_name = self.cfg.ExpandInstanceName(self.op.instance_name) |
9096 | 9ac99fda | Guido Trotter | # If the instance was not found we'll try with the name that was passed in.
|
9097 | 9ac99fda | Guido Trotter | # This will only work if it was an FQDN, though.
|
9098 | 9ac99fda | Guido Trotter | fqdn_warn = False
|
9099 | 9ac99fda | Guido Trotter | if not instance_name: |
9100 | 9ac99fda | Guido Trotter | fqdn_warn = True
|
9101 | 9ac99fda | Guido Trotter | instance_name = self.op.instance_name
|
9102 | 9ac99fda | Guido Trotter | |
9103 | 1b7bfbb7 | Iustin Pop | locked_nodes = self.acquired_locks[locking.LEVEL_NODE]
|
9104 | 1b7bfbb7 | Iustin Pop | exportlist = self.rpc.call_export_list(locked_nodes)
|
9105 | 9ac99fda | Guido Trotter | found = False
|
9106 | 9ac99fda | Guido Trotter | for node in exportlist: |
9107 | 4c4e4e1e | Iustin Pop | msg = exportlist[node].fail_msg |
9108 | 1b7bfbb7 | Iustin Pop | if msg:
|
9109 | 1b7bfbb7 | Iustin Pop | self.LogWarning("Failed to query node %s (continuing): %s", node, msg) |
9110 | 781de953 | Iustin Pop | continue
|
9111 | 1b7bfbb7 | Iustin Pop | if instance_name in exportlist[node].payload: |
9112 | 9ac99fda | Guido Trotter | found = True
|
9113 | 781de953 | Iustin Pop | result = self.rpc.call_export_remove(node, instance_name)
|
9114 | 4c4e4e1e | Iustin Pop | msg = result.fail_msg |
9115 | 35fbcd11 | Iustin Pop | if msg:
|
9116 | 9a4f63d1 | Iustin Pop | logging.error("Could not remove export for instance %s"
|
9117 | 35fbcd11 | Iustin Pop | " on node %s: %s", instance_name, node, msg)
|
9118 | 9ac99fda | Guido Trotter | |
9119 | 9ac99fda | Guido Trotter | if fqdn_warn and not found: |
9120 | 9ac99fda | Guido Trotter | feedback_fn("Export not found. If trying to remove an export belonging"
|
9121 | 9ac99fda | Guido Trotter | " to a deleted instance please use its Fully Qualified"
|
9122 | 9ac99fda | Guido Trotter | " Domain Name.")
|
9123 | 9ac99fda | Guido Trotter | |
9124 | 9ac99fda | Guido Trotter | |
9125 | fe267188 | Iustin Pop | class TagsLU(NoHooksLU): # pylint: disable-msg=W0223 |
9126 | 5c947f38 | Iustin Pop | """Generic tags LU.
|
9127 | 5c947f38 | Iustin Pop |
|
9128 | 5c947f38 | Iustin Pop | This is an abstract class which is the parent of all the other tags LUs.
|
9129 | 5c947f38 | Iustin Pop |
|
9130 | 5c947f38 | Iustin Pop | """
|
9131 | 5c947f38 | Iustin Pop | |
9132 | 8646adce | Guido Trotter | def ExpandNames(self): |
9133 | 8646adce | Guido Trotter | self.needed_locks = {}
|
9134 | 8646adce | Guido Trotter | if self.op.kind == constants.TAG_NODE: |
9135 | cf26a87a | Iustin Pop | self.op.name = _ExpandNodeName(self.cfg, self.op.name) |
9136 | cf26a87a | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = self.op.name |
9137 | 5c947f38 | Iustin Pop | elif self.op.kind == constants.TAG_INSTANCE: |
9138 | cf26a87a | Iustin Pop | self.op.name = _ExpandInstanceName(self.cfg, self.op.name) |
9139 | cf26a87a | Iustin Pop | self.needed_locks[locking.LEVEL_INSTANCE] = self.op.name |
9140 | 8646adce | Guido Trotter | |
9141 | 8646adce | Guido Trotter | def CheckPrereq(self): |
9142 | 8646adce | Guido Trotter | """Check prerequisites.
|
9143 | 8646adce | Guido Trotter |
|
9144 | 8646adce | Guido Trotter | """
|
9145 | 8646adce | Guido Trotter | if self.op.kind == constants.TAG_CLUSTER: |
9146 | 8646adce | Guido Trotter | self.target = self.cfg.GetClusterInfo() |
9147 | 8646adce | Guido Trotter | elif self.op.kind == constants.TAG_NODE: |
9148 | 8646adce | Guido Trotter | self.target = self.cfg.GetNodeInfo(self.op.name) |
9149 | 8646adce | Guido Trotter | elif self.op.kind == constants.TAG_INSTANCE: |
9150 | 8646adce | Guido Trotter | self.target = self.cfg.GetInstanceInfo(self.op.name) |
9151 | 5c947f38 | Iustin Pop | else:
|
9152 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Wrong tag type requested (%s)" % |
9153 | 5c983ee5 | Iustin Pop | str(self.op.kind), errors.ECODE_INVAL) |
9154 | 5c947f38 | Iustin Pop | |
9155 | 5c947f38 | Iustin Pop | |
9156 | 5c947f38 | Iustin Pop | class LUGetTags(TagsLU): |
9157 | 5c947f38 | Iustin Pop | """Returns the tags of a given object.
|
9158 | 5c947f38 | Iustin Pop |
|
9159 | 5c947f38 | Iustin Pop | """
|
9160 | 5c947f38 | Iustin Pop | _OP_REQP = ["kind", "name"] |
9161 | 8646adce | Guido Trotter | REQ_BGL = False
|
9162 | 5c947f38 | Iustin Pop | |
9163 | 5c947f38 | Iustin Pop | def Exec(self, feedback_fn): |
9164 | 5c947f38 | Iustin Pop | """Returns the tag list.
|
9165 | 5c947f38 | Iustin Pop |
|
9166 | 5c947f38 | Iustin Pop | """
|
9167 | 5d414478 | Oleksiy Mishchenko | return list(self.target.GetTags()) |
9168 | 5c947f38 | Iustin Pop | |
9169 | 5c947f38 | Iustin Pop | |
9170 | 73415719 | Iustin Pop | class LUSearchTags(NoHooksLU): |
9171 | 73415719 | Iustin Pop | """Searches the tags for a given pattern.
|
9172 | 73415719 | Iustin Pop |
|
9173 | 73415719 | Iustin Pop | """
|
9174 | 73415719 | Iustin Pop | _OP_REQP = ["pattern"]
|
9175 | 8646adce | Guido Trotter | REQ_BGL = False
|
9176 | 8646adce | Guido Trotter | |
9177 | 8646adce | Guido Trotter | def ExpandNames(self): |
9178 | 8646adce | Guido Trotter | self.needed_locks = {}
|
9179 | 73415719 | Iustin Pop | |
9180 | 73415719 | Iustin Pop | def CheckPrereq(self): |
9181 | 73415719 | Iustin Pop | """Check prerequisites.
|
9182 | 73415719 | Iustin Pop |
|
9183 | 73415719 | Iustin Pop | This checks the pattern passed for validity by compiling it.
|
9184 | 73415719 | Iustin Pop |
|
9185 | 73415719 | Iustin Pop | """
|
9186 | 73415719 | Iustin Pop | try:
|
9187 | 73415719 | Iustin Pop | self.re = re.compile(self.op.pattern) |
9188 | 73415719 | Iustin Pop | except re.error, err:
|
9189 | 73415719 | Iustin Pop | raise errors.OpPrereqError("Invalid search pattern '%s': %s" % |
9190 | 5c983ee5 | Iustin Pop | (self.op.pattern, err), errors.ECODE_INVAL)
|
9191 | 73415719 | Iustin Pop | |
9192 | 73415719 | Iustin Pop | def Exec(self, feedback_fn): |
9193 | 73415719 | Iustin Pop | """Returns the tag list.
|
9194 | 73415719 | Iustin Pop |
|
9195 | 73415719 | Iustin Pop | """
|
9196 | 73415719 | Iustin Pop | cfg = self.cfg
|
9197 | 73415719 | Iustin Pop | tgts = [("/cluster", cfg.GetClusterInfo())]
|
9198 | 8646adce | Guido Trotter | ilist = cfg.GetAllInstancesInfo().values() |
9199 | 73415719 | Iustin Pop | tgts.extend([("/instances/%s" % i.name, i) for i in ilist]) |
9200 | 8646adce | Guido Trotter | nlist = cfg.GetAllNodesInfo().values() |
9201 | 73415719 | Iustin Pop | tgts.extend([("/nodes/%s" % n.name, n) for n in nlist]) |
9202 | 73415719 | Iustin Pop | results = [] |
9203 | 73415719 | Iustin Pop | for path, target in tgts: |
9204 | 73415719 | Iustin Pop | for tag in target.GetTags(): |
9205 | 73415719 | Iustin Pop | if self.re.search(tag): |
9206 | 73415719 | Iustin Pop | results.append((path, tag)) |
9207 | 73415719 | Iustin Pop | return results
|
9208 | 73415719 | Iustin Pop | |
9209 | 73415719 | Iustin Pop | |
9210 | f27302fa | Iustin Pop | class LUAddTags(TagsLU): |
9211 | 5c947f38 | Iustin Pop | """Sets a tag on a given object.
|
9212 | 5c947f38 | Iustin Pop |
|
9213 | 5c947f38 | Iustin Pop | """
|
9214 | f27302fa | Iustin Pop | _OP_REQP = ["kind", "name", "tags"] |
9215 | 8646adce | Guido Trotter | REQ_BGL = False
|
9216 | 5c947f38 | Iustin Pop | |
9217 | 5c947f38 | Iustin Pop | def CheckPrereq(self): |
9218 | 5c947f38 | Iustin Pop | """Check prerequisites.
|
9219 | 5c947f38 | Iustin Pop |
|
9220 | 5c947f38 | Iustin Pop | This checks the type and length of the tag name and value.
|
9221 | 5c947f38 | Iustin Pop |
|
9222 | 5c947f38 | Iustin Pop | """
|
9223 | 5c947f38 | Iustin Pop | TagsLU.CheckPrereq(self)
|
9224 | f27302fa | Iustin Pop | for tag in self.op.tags: |
9225 | f27302fa | Iustin Pop | objects.TaggableObject.ValidateTag(tag) |
9226 | 5c947f38 | Iustin Pop | |
9227 | 5c947f38 | Iustin Pop | def Exec(self, feedback_fn): |
9228 | 5c947f38 | Iustin Pop | """Sets the tag.
|
9229 | 5c947f38 | Iustin Pop |
|
9230 | 5c947f38 | Iustin Pop | """
|
9231 | 5c947f38 | Iustin Pop | try:
|
9232 | f27302fa | Iustin Pop | for tag in self.op.tags: |
9233 | f27302fa | Iustin Pop | self.target.AddTag(tag)
|
9234 | 5c947f38 | Iustin Pop | except errors.TagError, err:
|
9235 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Error while setting tag: %s" % str(err)) |
9236 | 159d4ec6 | Iustin Pop | self.cfg.Update(self.target, feedback_fn) |
9237 | 5c947f38 | Iustin Pop | |
9238 | 5c947f38 | Iustin Pop | |
9239 | f27302fa | Iustin Pop | class LUDelTags(TagsLU): |
9240 | f27302fa | Iustin Pop | """Delete a list of tags from a given object.
|
9241 | 5c947f38 | Iustin Pop |
|
9242 | 5c947f38 | Iustin Pop | """
|
9243 | f27302fa | Iustin Pop | _OP_REQP = ["kind", "name", "tags"] |
9244 | 8646adce | Guido Trotter | REQ_BGL = False
|
9245 | 5c947f38 | Iustin Pop | |
9246 | 5c947f38 | Iustin Pop | def CheckPrereq(self): |
9247 | 5c947f38 | Iustin Pop | """Check prerequisites.
|
9248 | 5c947f38 | Iustin Pop |
|
9249 | 5c947f38 | Iustin Pop | This checks that we have the given tag.
|
9250 | 5c947f38 | Iustin Pop |
|
9251 | 5c947f38 | Iustin Pop | """
|
9252 | 5c947f38 | Iustin Pop | TagsLU.CheckPrereq(self)
|
9253 | f27302fa | Iustin Pop | for tag in self.op.tags: |
9254 | f27302fa | Iustin Pop | objects.TaggableObject.ValidateTag(tag) |
9255 | f27302fa | Iustin Pop | del_tags = frozenset(self.op.tags) |
9256 | f27302fa | Iustin Pop | cur_tags = self.target.GetTags()
|
9257 | f27302fa | Iustin Pop | if not del_tags <= cur_tags: |
9258 | f27302fa | Iustin Pop | diff_tags = del_tags - cur_tags |
9259 | f27302fa | Iustin Pop | diff_names = ["'%s'" % tag for tag in diff_tags] |
9260 | f27302fa | Iustin Pop | diff_names.sort() |
9261 | f27302fa | Iustin Pop | raise errors.OpPrereqError("Tag(s) %s not found" % |
9262 | 5c983ee5 | Iustin Pop | (",".join(diff_names)), errors.ECODE_NOENT)
|
9263 | 5c947f38 | Iustin Pop | |
9264 | 5c947f38 | Iustin Pop | def Exec(self, feedback_fn): |
9265 | 5c947f38 | Iustin Pop | """Remove the tag from the object.
|
9266 | 5c947f38 | Iustin Pop |
|
9267 | 5c947f38 | Iustin Pop | """
|
9268 | f27302fa | Iustin Pop | for tag in self.op.tags: |
9269 | f27302fa | Iustin Pop | self.target.RemoveTag(tag)
|
9270 | 159d4ec6 | Iustin Pop | self.cfg.Update(self.target, feedback_fn) |
9271 | 06009e27 | Iustin Pop | |
9272 | 0eed6e61 | Guido Trotter | |
9273 | 06009e27 | Iustin Pop | class LUTestDelay(NoHooksLU): |
9274 | 06009e27 | Iustin Pop | """Sleep for a specified amount of time.
|
9275 | 06009e27 | Iustin Pop |
|
9276 | 0b097284 | Guido Trotter | This LU sleeps on the master and/or nodes for a specified amount of
|
9277 | 06009e27 | Iustin Pop | time.
|
9278 | 06009e27 | Iustin Pop |
|
9279 | 06009e27 | Iustin Pop | """
|
9280 | 06009e27 | Iustin Pop | _OP_REQP = ["duration", "on_master", "on_nodes"] |
9281 | fbe9022f | Guido Trotter | REQ_BGL = False
|
9282 | 06009e27 | Iustin Pop | |
9283 | fbe9022f | Guido Trotter | def ExpandNames(self): |
9284 | fbe9022f | Guido Trotter | """Expand names and set required locks.
|
9285 | 06009e27 | Iustin Pop |
|
9286 | fbe9022f | Guido Trotter | This expands the node list, if any.
|
9287 | 06009e27 | Iustin Pop |
|
9288 | 06009e27 | Iustin Pop | """
|
9289 | fbe9022f | Guido Trotter | self.needed_locks = {}
|
9290 | 06009e27 | Iustin Pop | if self.op.on_nodes: |
9291 | fbe9022f | Guido Trotter | # _GetWantedNodes can be used here, but is not always appropriate to use
|
9292 | fbe9022f | Guido Trotter | # this way in ExpandNames. Check LogicalUnit.ExpandNames docstring for
|
9293 | fbe9022f | Guido Trotter | # more information.
|
9294 | 06009e27 | Iustin Pop | self.op.on_nodes = _GetWantedNodes(self, self.op.on_nodes) |
9295 | fbe9022f | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = self.op.on_nodes |
9296 | fbe9022f | Guido Trotter | |
9297 | fbe9022f | Guido Trotter | def CheckPrereq(self): |
9298 | fbe9022f | Guido Trotter | """Check prerequisites.
|
9299 | fbe9022f | Guido Trotter |
|
9300 | fbe9022f | Guido Trotter | """
|
9301 | 06009e27 | Iustin Pop | |
9302 | 06009e27 | Iustin Pop | def Exec(self, feedback_fn): |
9303 | 06009e27 | Iustin Pop | """Do the actual sleep.
|
9304 | 06009e27 | Iustin Pop |
|
9305 | 06009e27 | Iustin Pop | """
|
9306 | 06009e27 | Iustin Pop | if self.op.on_master: |
9307 | 06009e27 | Iustin Pop | if not utils.TestDelay(self.op.duration): |
9308 | 06009e27 | Iustin Pop | raise errors.OpExecError("Error during master delay test") |
9309 | 06009e27 | Iustin Pop | if self.op.on_nodes: |
9310 | 72737a7f | Iustin Pop | result = self.rpc.call_test_delay(self.op.on_nodes, self.op.duration) |
9311 | 06009e27 | Iustin Pop | for node, node_result in result.items(): |
9312 | 4c4e4e1e | Iustin Pop | node_result.Raise("Failure during rpc call to node %s" % node)
|
9313 | d61df03e | Iustin Pop | |
9314 | d61df03e | Iustin Pop | |
9315 | d1c2dd75 | Iustin Pop | class IAllocator(object): |
9316 | d1c2dd75 | Iustin Pop | """IAllocator framework.
|
9317 | d61df03e | Iustin Pop |
|
9318 | d1c2dd75 | Iustin Pop | An IAllocator instance has three sets of attributes:
|
9319 | d6a02168 | Michael Hanselmann | - cfg that is needed to query the cluster
|
9320 | d1c2dd75 | Iustin Pop | - input data (all members of the _KEYS class attribute are required)
|
9321 | d1c2dd75 | Iustin Pop | - four buffer attributes (in|out_data|text), that represent the
|
9322 | d1c2dd75 | Iustin Pop | input (to the external script) in text and data structure format,
|
9323 | d1c2dd75 | Iustin Pop | and the output from it, again in two formats
|
9324 | d1c2dd75 | Iustin Pop | - the result variables from the script (success, info, nodes) for
|
9325 | d1c2dd75 | Iustin Pop | easy usage
|
9326 | d61df03e | Iustin Pop |
|
9327 | d61df03e | Iustin Pop | """
|
9328 | 7260cfbe | Iustin Pop | # pylint: disable-msg=R0902
|
9329 | 7260cfbe | Iustin Pop | # lots of instance attributes
|
9330 | 29859cb7 | Iustin Pop | _ALLO_KEYS = [ |
9331 | 8d3f86a0 | Iustin Pop | "name", "mem_size", "disks", "disk_template", |
9332 | 8cc7e742 | Guido Trotter | "os", "tags", "nics", "vcpus", "hypervisor", |
9333 | d1c2dd75 | Iustin Pop | ] |
9334 | 29859cb7 | Iustin Pop | _RELO_KEYS = [ |
9335 | 8d3f86a0 | Iustin Pop | "name", "relocate_from", |
9336 | 29859cb7 | Iustin Pop | ] |
9337 | 7f60a422 | Iustin Pop | _EVAC_KEYS = [ |
9338 | 7f60a422 | Iustin Pop | "evac_nodes",
|
9339 | 7f60a422 | Iustin Pop | ] |
9340 | d1c2dd75 | Iustin Pop | |
9341 | 8d3f86a0 | Iustin Pop | def __init__(self, cfg, rpc, mode, **kwargs): |
9342 | 923ddac0 | Michael Hanselmann | self.cfg = cfg
|
9343 | 923ddac0 | Michael Hanselmann | self.rpc = rpc
|
9344 | d1c2dd75 | Iustin Pop | # init buffer variables
|
9345 | d1c2dd75 | Iustin Pop | self.in_text = self.out_text = self.in_data = self.out_data = None |
9346 | d1c2dd75 | Iustin Pop | # init all input fields so that pylint is happy
|
9347 | 29859cb7 | Iustin Pop | self.mode = mode
|
9348 | d1c2dd75 | Iustin Pop | self.mem_size = self.disks = self.disk_template = None |
9349 | d1c2dd75 | Iustin Pop | self.os = self.tags = self.nics = self.vcpus = None |
9350 | a0add446 | Iustin Pop | self.hypervisor = None |
9351 | 29859cb7 | Iustin Pop | self.relocate_from = None |
9352 | 8d3f86a0 | Iustin Pop | self.name = None |
9353 | 7f60a422 | Iustin Pop | self.evac_nodes = None |
9354 | 27579978 | Iustin Pop | # computed fields
|
9355 | 27579978 | Iustin Pop | self.required_nodes = None |
9356 | d1c2dd75 | Iustin Pop | # init result fields
|
9357 | 680f0a89 | Iustin Pop | self.success = self.info = self.result = None |
9358 | 29859cb7 | Iustin Pop | if self.mode == constants.IALLOCATOR_MODE_ALLOC: |
9359 | 29859cb7 | Iustin Pop | keyset = self._ALLO_KEYS
|
9360 | 9757cc90 | Iustin Pop | fn = self._AddNewInstance
|
9361 | 29859cb7 | Iustin Pop | elif self.mode == constants.IALLOCATOR_MODE_RELOC: |
9362 | 29859cb7 | Iustin Pop | keyset = self._RELO_KEYS
|
9363 | 9757cc90 | Iustin Pop | fn = self._AddRelocateInstance
|
9364 | 7f60a422 | Iustin Pop | elif self.mode == constants.IALLOCATOR_MODE_MEVAC: |
9365 | 7f60a422 | Iustin Pop | keyset = self._EVAC_KEYS
|
9366 | 7f60a422 | Iustin Pop | fn = self._AddEvacuateNodes
|
9367 | 29859cb7 | Iustin Pop | else:
|
9368 | 29859cb7 | Iustin Pop | raise errors.ProgrammerError("Unknown mode '%s' passed to the" |
9369 | 29859cb7 | Iustin Pop | " IAllocator" % self.mode) |
9370 | d1c2dd75 | Iustin Pop | for key in kwargs: |
9371 | 29859cb7 | Iustin Pop | if key not in keyset: |
9372 | d1c2dd75 | Iustin Pop | raise errors.ProgrammerError("Invalid input parameter '%s' to" |
9373 | d1c2dd75 | Iustin Pop | " IAllocator" % key)
|
9374 | d1c2dd75 | Iustin Pop | setattr(self, key, kwargs[key]) |
9375 | 7f60a422 | Iustin Pop | |
9376 | 29859cb7 | Iustin Pop | for key in keyset: |
9377 | d1c2dd75 | Iustin Pop | if key not in kwargs: |
9378 | d1c2dd75 | Iustin Pop | raise errors.ProgrammerError("Missing input parameter '%s' to" |
9379 | d1c2dd75 | Iustin Pop | " IAllocator" % key)
|
9380 | 9757cc90 | Iustin Pop | self._BuildInputData(fn)
|
9381 | d1c2dd75 | Iustin Pop | |
9382 | d1c2dd75 | Iustin Pop | def _ComputeClusterData(self): |
9383 | d1c2dd75 | Iustin Pop | """Compute the generic allocator input data.
|
9384 | d1c2dd75 | Iustin Pop |
|
9385 | d1c2dd75 | Iustin Pop | This is the data that is independent of the actual operation.
|
9386 | d1c2dd75 | Iustin Pop |
|
9387 | d1c2dd75 | Iustin Pop | """
|
9388 | 923ddac0 | Michael Hanselmann | cfg = self.cfg
|
9389 | e69d05fd | Iustin Pop | cluster_info = cfg.GetClusterInfo() |
9390 | d1c2dd75 | Iustin Pop | # cluster data
|
9391 | d1c2dd75 | Iustin Pop | data = { |
9392 | 77031881 | Iustin Pop | "version": constants.IALLOCATOR_VERSION,
|
9393 | 72737a7f | Iustin Pop | "cluster_name": cfg.GetClusterName(),
|
9394 | e69d05fd | Iustin Pop | "cluster_tags": list(cluster_info.GetTags()), |
9395 | 1325da74 | Iustin Pop | "enabled_hypervisors": list(cluster_info.enabled_hypervisors), |
9396 | d1c2dd75 | Iustin Pop | # we don't have job IDs
|
9397 | d61df03e | Iustin Pop | } |
9398 | b57e9819 | Guido Trotter | iinfo = cfg.GetAllInstancesInfo().values() |
9399 | b57e9819 | Guido Trotter | i_list = [(inst, cluster_info.FillBE(inst)) for inst in iinfo] |
9400 | 6286519f | Iustin Pop | |
9401 | d1c2dd75 | Iustin Pop | # node data
|
9402 | d1c2dd75 | Iustin Pop | node_results = {} |
9403 | d1c2dd75 | Iustin Pop | node_list = cfg.GetNodeList() |
9404 | 8cc7e742 | Guido Trotter | |
9405 | 8cc7e742 | Guido Trotter | if self.mode == constants.IALLOCATOR_MODE_ALLOC: |
9406 | a0add446 | Iustin Pop | hypervisor_name = self.hypervisor
|
9407 | 8cc7e742 | Guido Trotter | elif self.mode == constants.IALLOCATOR_MODE_RELOC: |
9408 | a0add446 | Iustin Pop | hypervisor_name = cfg.GetInstanceInfo(self.name).hypervisor
|
9409 | 7f60a422 | Iustin Pop | elif self.mode == constants.IALLOCATOR_MODE_MEVAC: |
9410 | 7f60a422 | Iustin Pop | hypervisor_name = cluster_info.enabled_hypervisors[0]
|
9411 | 8cc7e742 | Guido Trotter | |
9412 | 923ddac0 | Michael Hanselmann | node_data = self.rpc.call_node_info(node_list, cfg.GetVGName(),
|
9413 | 923ddac0 | Michael Hanselmann | hypervisor_name) |
9414 | 923ddac0 | Michael Hanselmann | node_iinfo = \ |
9415 | 923ddac0 | Michael Hanselmann | self.rpc.call_all_instances_info(node_list,
|
9416 | 923ddac0 | Michael Hanselmann | cluster_info.enabled_hypervisors) |
9417 | 1325da74 | Iustin Pop | for nname, nresult in node_data.items(): |
9418 | 1325da74 | Iustin Pop | # first fill in static (config-based) values
|
9419 | d1c2dd75 | Iustin Pop | ninfo = cfg.GetNodeInfo(nname) |
9420 | d1c2dd75 | Iustin Pop | pnr = { |
9421 | d1c2dd75 | Iustin Pop | "tags": list(ninfo.GetTags()), |
9422 | d1c2dd75 | Iustin Pop | "primary_ip": ninfo.primary_ip,
|
9423 | d1c2dd75 | Iustin Pop | "secondary_ip": ninfo.secondary_ip,
|
9424 | fc0fe88c | Iustin Pop | "offline": ninfo.offline,
|
9425 | 0b2454b9 | Iustin Pop | "drained": ninfo.drained,
|
9426 | 1325da74 | Iustin Pop | "master_candidate": ninfo.master_candidate,
|
9427 | d1c2dd75 | Iustin Pop | } |
9428 | 1325da74 | Iustin Pop | |
9429 | 0d853843 | Iustin Pop | if not (ninfo.offline or ninfo.drained): |
9430 | 4c4e4e1e | Iustin Pop | nresult.Raise("Can't get data for node %s" % nname)
|
9431 | 4c4e4e1e | Iustin Pop | node_iinfo[nname].Raise("Can't get node instance info from node %s" %
|
9432 | 4c4e4e1e | Iustin Pop | nname) |
9433 | 070e998b | Iustin Pop | remote_info = nresult.payload |
9434 | b142ef15 | Iustin Pop | |
9435 | 1325da74 | Iustin Pop | for attr in ['memory_total', 'memory_free', 'memory_dom0', |
9436 | 1325da74 | Iustin Pop | 'vg_size', 'vg_free', 'cpu_total']: |
9437 | 1325da74 | Iustin Pop | if attr not in remote_info: |
9438 | 1325da74 | Iustin Pop | raise errors.OpExecError("Node '%s' didn't return attribute" |
9439 | 1325da74 | Iustin Pop | " '%s'" % (nname, attr))
|
9440 | 070e998b | Iustin Pop | if not isinstance(remote_info[attr], int): |
9441 | 1325da74 | Iustin Pop | raise errors.OpExecError("Node '%s' returned invalid value" |
9442 | 070e998b | Iustin Pop | " for '%s': %s" %
|
9443 | 070e998b | Iustin Pop | (nname, attr, remote_info[attr])) |
9444 | 1325da74 | Iustin Pop | # compute memory used by primary instances
|
9445 | 1325da74 | Iustin Pop | i_p_mem = i_p_up_mem = 0
|
9446 | 1325da74 | Iustin Pop | for iinfo, beinfo in i_list: |
9447 | 1325da74 | Iustin Pop | if iinfo.primary_node == nname:
|
9448 | 1325da74 | Iustin Pop | i_p_mem += beinfo[constants.BE_MEMORY] |
9449 | 2fa74ef4 | Iustin Pop | if iinfo.name not in node_iinfo[nname].payload: |
9450 | 1325da74 | Iustin Pop | i_used_mem = 0
|
9451 | 1325da74 | Iustin Pop | else:
|
9452 | 2fa74ef4 | Iustin Pop | i_used_mem = int(node_iinfo[nname].payload[iinfo.name]['memory']) |
9453 | 1325da74 | Iustin Pop | i_mem_diff = beinfo[constants.BE_MEMORY] - i_used_mem |
9454 | 1325da74 | Iustin Pop | remote_info['memory_free'] -= max(0, i_mem_diff) |
9455 | 1325da74 | Iustin Pop | |
9456 | 1325da74 | Iustin Pop | if iinfo.admin_up:
|
9457 | 1325da74 | Iustin Pop | i_p_up_mem += beinfo[constants.BE_MEMORY] |
9458 | 1325da74 | Iustin Pop | |
9459 | 1325da74 | Iustin Pop | # compute memory used by instances
|
9460 | 1325da74 | Iustin Pop | pnr_dyn = { |
9461 | 1325da74 | Iustin Pop | "total_memory": remote_info['memory_total'], |
9462 | 1325da74 | Iustin Pop | "reserved_memory": remote_info['memory_dom0'], |
9463 | 1325da74 | Iustin Pop | "free_memory": remote_info['memory_free'], |
9464 | 1325da74 | Iustin Pop | "total_disk": remote_info['vg_size'], |
9465 | 1325da74 | Iustin Pop | "free_disk": remote_info['vg_free'], |
9466 | 1325da74 | Iustin Pop | "total_cpus": remote_info['cpu_total'], |
9467 | 1325da74 | Iustin Pop | "i_pri_memory": i_p_mem,
|
9468 | 1325da74 | Iustin Pop | "i_pri_up_memory": i_p_up_mem,
|
9469 | 1325da74 | Iustin Pop | } |
9470 | 1325da74 | Iustin Pop | pnr.update(pnr_dyn) |
9471 | 1325da74 | Iustin Pop | |
9472 | d1c2dd75 | Iustin Pop | node_results[nname] = pnr |
9473 | d1c2dd75 | Iustin Pop | data["nodes"] = node_results
|
9474 | d1c2dd75 | Iustin Pop | |
9475 | d1c2dd75 | Iustin Pop | # instance data
|
9476 | d1c2dd75 | Iustin Pop | instance_data = {} |
9477 | 338e51e8 | Iustin Pop | for iinfo, beinfo in i_list: |
9478 | a9fe7e8f | Guido Trotter | nic_data = [] |
9479 | a9fe7e8f | Guido Trotter | for nic in iinfo.nics: |
9480 | a9fe7e8f | Guido Trotter | filled_params = objects.FillDict( |
9481 | a9fe7e8f | Guido Trotter | cluster_info.nicparams[constants.PP_DEFAULT], |
9482 | a9fe7e8f | Guido Trotter | nic.nicparams) |
9483 | a9fe7e8f | Guido Trotter | nic_dict = {"mac": nic.mac,
|
9484 | a9fe7e8f | Guido Trotter | "ip": nic.ip,
|
9485 | a9fe7e8f | Guido Trotter | "mode": filled_params[constants.NIC_MODE],
|
9486 | a9fe7e8f | Guido Trotter | "link": filled_params[constants.NIC_LINK],
|
9487 | a9fe7e8f | Guido Trotter | } |
9488 | a9fe7e8f | Guido Trotter | if filled_params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
|
9489 | a9fe7e8f | Guido Trotter | nic_dict["bridge"] = filled_params[constants.NIC_LINK]
|
9490 | a9fe7e8f | Guido Trotter | nic_data.append(nic_dict) |
9491 | d1c2dd75 | Iustin Pop | pir = { |
9492 | d1c2dd75 | Iustin Pop | "tags": list(iinfo.GetTags()), |
9493 | 1325da74 | Iustin Pop | "admin_up": iinfo.admin_up,
|
9494 | 338e51e8 | Iustin Pop | "vcpus": beinfo[constants.BE_VCPUS],
|
9495 | 338e51e8 | Iustin Pop | "memory": beinfo[constants.BE_MEMORY],
|
9496 | d1c2dd75 | Iustin Pop | "os": iinfo.os,
|
9497 | 1325da74 | Iustin Pop | "nodes": [iinfo.primary_node] + list(iinfo.secondary_nodes), |
9498 | d1c2dd75 | Iustin Pop | "nics": nic_data,
|
9499 | 1325da74 | Iustin Pop | "disks": [{"size": dsk.size, "mode": dsk.mode} for dsk in iinfo.disks], |
9500 | d1c2dd75 | Iustin Pop | "disk_template": iinfo.disk_template,
|
9501 | e69d05fd | Iustin Pop | "hypervisor": iinfo.hypervisor,
|
9502 | d1c2dd75 | Iustin Pop | } |
9503 | 88ae4f85 | Iustin Pop | pir["disk_space_total"] = _ComputeDiskSize(iinfo.disk_template,
|
9504 | 88ae4f85 | Iustin Pop | pir["disks"])
|
9505 | 768f0a80 | Iustin Pop | instance_data[iinfo.name] = pir |
9506 | d61df03e | Iustin Pop | |
9507 | d1c2dd75 | Iustin Pop | data["instances"] = instance_data
|
9508 | d61df03e | Iustin Pop | |
9509 | d1c2dd75 | Iustin Pop | self.in_data = data
|
9510 | d61df03e | Iustin Pop | |
9511 | d1c2dd75 | Iustin Pop | def _AddNewInstance(self): |
9512 | d1c2dd75 | Iustin Pop | """Add new instance data to allocator structure.
|
9513 | d61df03e | Iustin Pop |
|
9514 | d1c2dd75 | Iustin Pop | This in combination with _AllocatorGetClusterData will create the
|
9515 | d1c2dd75 | Iustin Pop | correct structure needed as input for the allocator.
|
9516 | d61df03e | Iustin Pop |
|
9517 | d1c2dd75 | Iustin Pop | The checks for the completeness of the opcode must have already been
|
9518 | d1c2dd75 | Iustin Pop | done.
|
9519 | d61df03e | Iustin Pop |
|
9520 | d1c2dd75 | Iustin Pop | """
|
9521 | dafc7302 | Guido Trotter | disk_space = _ComputeDiskSize(self.disk_template, self.disks) |
9522 | d1c2dd75 | Iustin Pop | |
9523 | 27579978 | Iustin Pop | if self.disk_template in constants.DTS_NET_MIRROR: |
9524 | 27579978 | Iustin Pop | self.required_nodes = 2 |
9525 | 27579978 | Iustin Pop | else:
|
9526 | 27579978 | Iustin Pop | self.required_nodes = 1 |
9527 | d1c2dd75 | Iustin Pop | request = { |
9528 | d1c2dd75 | Iustin Pop | "name": self.name, |
9529 | d1c2dd75 | Iustin Pop | "disk_template": self.disk_template, |
9530 | d1c2dd75 | Iustin Pop | "tags": self.tags, |
9531 | d1c2dd75 | Iustin Pop | "os": self.os, |
9532 | d1c2dd75 | Iustin Pop | "vcpus": self.vcpus, |
9533 | d1c2dd75 | Iustin Pop | "memory": self.mem_size, |
9534 | d1c2dd75 | Iustin Pop | "disks": self.disks, |
9535 | d1c2dd75 | Iustin Pop | "disk_space_total": disk_space,
|
9536 | d1c2dd75 | Iustin Pop | "nics": self.nics, |
9537 | 27579978 | Iustin Pop | "required_nodes": self.required_nodes, |
9538 | d1c2dd75 | Iustin Pop | } |
9539 | 9757cc90 | Iustin Pop | return request
|
9540 | 298fe380 | Iustin Pop | |
9541 | d1c2dd75 | Iustin Pop | def _AddRelocateInstance(self): |
9542 | d1c2dd75 | Iustin Pop | """Add relocate instance data to allocator structure.
|
9543 | 298fe380 | Iustin Pop |
|
9544 | d1c2dd75 | Iustin Pop | This in combination with _IAllocatorGetClusterData will create the
|
9545 | d1c2dd75 | Iustin Pop | correct structure needed as input for the allocator.
|
9546 | d61df03e | Iustin Pop |
|
9547 | d1c2dd75 | Iustin Pop | The checks for the completeness of the opcode must have already been
|
9548 | d1c2dd75 | Iustin Pop | done.
|
9549 | d61df03e | Iustin Pop |
|
9550 | d1c2dd75 | Iustin Pop | """
|
9551 | 923ddac0 | Michael Hanselmann | instance = self.cfg.GetInstanceInfo(self.name) |
9552 | 27579978 | Iustin Pop | if instance is None: |
9553 | 27579978 | Iustin Pop | raise errors.ProgrammerError("Unknown instance '%s' passed to" |
9554 | 27579978 | Iustin Pop | " IAllocator" % self.name) |
9555 | 27579978 | Iustin Pop | |
9556 | 27579978 | Iustin Pop | if instance.disk_template not in constants.DTS_NET_MIRROR: |
9557 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Can't relocate non-mirrored instances", |
9558 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
9559 | 27579978 | Iustin Pop | |
9560 | 2a139bb0 | Iustin Pop | if len(instance.secondary_nodes) != 1: |
9561 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Instance has not exactly one secondary node", |
9562 | 5c983ee5 | Iustin Pop | errors.ECODE_STATE) |
9563 | 2a139bb0 | Iustin Pop | |
9564 | 27579978 | Iustin Pop | self.required_nodes = 1 |
9565 | dafc7302 | Guido Trotter | disk_sizes = [{'size': disk.size} for disk in instance.disks] |
9566 | dafc7302 | Guido Trotter | disk_space = _ComputeDiskSize(instance.disk_template, disk_sizes) |
9567 | 27579978 | Iustin Pop | |
9568 | d1c2dd75 | Iustin Pop | request = { |
9569 | d1c2dd75 | Iustin Pop | "name": self.name, |
9570 | 27579978 | Iustin Pop | "disk_space_total": disk_space,
|
9571 | 27579978 | Iustin Pop | "required_nodes": self.required_nodes, |
9572 | 29859cb7 | Iustin Pop | "relocate_from": self.relocate_from, |
9573 | d1c2dd75 | Iustin Pop | } |
9574 | 9757cc90 | Iustin Pop | return request
|
9575 | d61df03e | Iustin Pop | |
9576 | 7f60a422 | Iustin Pop | def _AddEvacuateNodes(self): |
9577 | 7f60a422 | Iustin Pop | """Add evacuate nodes data to allocator structure.
|
9578 | 7f60a422 | Iustin Pop |
|
9579 | 7f60a422 | Iustin Pop | """
|
9580 | 7f60a422 | Iustin Pop | request = { |
9581 | 7f60a422 | Iustin Pop | "evac_nodes": self.evac_nodes |
9582 | 7f60a422 | Iustin Pop | } |
9583 | 7f60a422 | Iustin Pop | return request
|
9584 | 7f60a422 | Iustin Pop | |
9585 | 9757cc90 | Iustin Pop | def _BuildInputData(self, fn): |
9586 | d1c2dd75 | Iustin Pop | """Build input data structures.
|
9587 | d61df03e | Iustin Pop |
|
9588 | d1c2dd75 | Iustin Pop | """
|
9589 | d1c2dd75 | Iustin Pop | self._ComputeClusterData()
|
9590 | d61df03e | Iustin Pop | |
9591 | 9757cc90 | Iustin Pop | request = fn() |
9592 | 9757cc90 | Iustin Pop | request["type"] = self.mode |
9593 | 9757cc90 | Iustin Pop | self.in_data["request"] = request |
9594 | d61df03e | Iustin Pop | |
9595 | d1c2dd75 | Iustin Pop | self.in_text = serializer.Dump(self.in_data) |
9596 | d61df03e | Iustin Pop | |
9597 | 72737a7f | Iustin Pop | def Run(self, name, validate=True, call_fn=None): |
9598 | d1c2dd75 | Iustin Pop | """Run an instance allocator and return the results.
|
9599 | 298fe380 | Iustin Pop |
|
9600 | d1c2dd75 | Iustin Pop | """
|
9601 | 72737a7f | Iustin Pop | if call_fn is None: |
9602 | 923ddac0 | Michael Hanselmann | call_fn = self.rpc.call_iallocator_runner
|
9603 | 298fe380 | Iustin Pop | |
9604 | 923ddac0 | Michael Hanselmann | result = call_fn(self.cfg.GetMasterNode(), name, self.in_text) |
9605 | 4c4e4e1e | Iustin Pop | result.Raise("Failure while running the iallocator script")
|
9606 | 8d528b7c | Iustin Pop | |
9607 | 87f5c298 | Iustin Pop | self.out_text = result.payload
|
9608 | d1c2dd75 | Iustin Pop | if validate:
|
9609 | d1c2dd75 | Iustin Pop | self._ValidateResult()
|
9610 | 298fe380 | Iustin Pop | |
9611 | d1c2dd75 | Iustin Pop | def _ValidateResult(self): |
9612 | d1c2dd75 | Iustin Pop | """Process the allocator results.
|
9613 | 538475ca | Iustin Pop |
|
9614 | d1c2dd75 | Iustin Pop | This will process and if successful save the result in
|
9615 | d1c2dd75 | Iustin Pop | self.out_data and the other parameters.
|
9616 | 538475ca | Iustin Pop |
|
9617 | d1c2dd75 | Iustin Pop | """
|
9618 | d1c2dd75 | Iustin Pop | try:
|
9619 | d1c2dd75 | Iustin Pop | rdict = serializer.Load(self.out_text)
|
9620 | d1c2dd75 | Iustin Pop | except Exception, err: |
9621 | d1c2dd75 | Iustin Pop | raise errors.OpExecError("Can't parse iallocator results: %s" % str(err)) |
9622 | d1c2dd75 | Iustin Pop | |
9623 | d1c2dd75 | Iustin Pop | if not isinstance(rdict, dict): |
9624 | d1c2dd75 | Iustin Pop | raise errors.OpExecError("Can't parse iallocator results: not a dict") |
9625 | 538475ca | Iustin Pop | |
9626 | 680f0a89 | Iustin Pop | # TODO: remove backwards compatiblity in later versions
|
9627 | 680f0a89 | Iustin Pop | if "nodes" in rdict and "result" not in rdict: |
9628 | 680f0a89 | Iustin Pop | rdict["result"] = rdict["nodes"] |
9629 | 680f0a89 | Iustin Pop | del rdict["nodes"] |
9630 | 680f0a89 | Iustin Pop | |
9631 | 680f0a89 | Iustin Pop | for key in "success", "info", "result": |
9632 | d1c2dd75 | Iustin Pop | if key not in rdict: |
9633 | d1c2dd75 | Iustin Pop | raise errors.OpExecError("Can't parse iallocator results:" |
9634 | d1c2dd75 | Iustin Pop | " missing key '%s'" % key)
|
9635 | d1c2dd75 | Iustin Pop | setattr(self, key, rdict[key]) |
9636 | 538475ca | Iustin Pop | |
9637 | 680f0a89 | Iustin Pop | if not isinstance(rdict["result"], list): |
9638 | 680f0a89 | Iustin Pop | raise errors.OpExecError("Can't parse iallocator results: 'result' key" |
9639 | d1c2dd75 | Iustin Pop | " is not a list")
|
9640 | d1c2dd75 | Iustin Pop | self.out_data = rdict
|
9641 | 538475ca | Iustin Pop | |
9642 | 538475ca | Iustin Pop | |
9643 | d61df03e | Iustin Pop | class LUTestAllocator(NoHooksLU): |
9644 | d61df03e | Iustin Pop | """Run allocator tests.
|
9645 | d61df03e | Iustin Pop |
|
9646 | d61df03e | Iustin Pop | This LU runs the allocator tests
|
9647 | d61df03e | Iustin Pop |
|
9648 | d61df03e | Iustin Pop | """
|
9649 | d61df03e | Iustin Pop | _OP_REQP = ["direction", "mode", "name"] |
9650 | d61df03e | Iustin Pop | |
9651 | d61df03e | Iustin Pop | def CheckPrereq(self): |
9652 | d61df03e | Iustin Pop | """Check prerequisites.
|
9653 | d61df03e | Iustin Pop |
|
9654 | d61df03e | Iustin Pop | This checks the opcode parameters depending on the director and mode test.
|
9655 | d61df03e | Iustin Pop |
|
9656 | d61df03e | Iustin Pop | """
|
9657 | 298fe380 | Iustin Pop | if self.op.mode == constants.IALLOCATOR_MODE_ALLOC: |
9658 | d61df03e | Iustin Pop | for attr in ["name", "mem_size", "disks", "disk_template", |
9659 | d61df03e | Iustin Pop | "os", "tags", "nics", "vcpus"]: |
9660 | d61df03e | Iustin Pop | if not hasattr(self.op, attr): |
9661 | d61df03e | Iustin Pop | raise errors.OpPrereqError("Missing attribute '%s' on opcode input" % |
9662 | 5c983ee5 | Iustin Pop | attr, errors.ECODE_INVAL) |
9663 | d61df03e | Iustin Pop | iname = self.cfg.ExpandInstanceName(self.op.name) |
9664 | d61df03e | Iustin Pop | if iname is not None: |
9665 | d61df03e | Iustin Pop | raise errors.OpPrereqError("Instance '%s' already in the cluster" % |
9666 | 5c983ee5 | Iustin Pop | iname, errors.ECODE_EXISTS) |
9667 | d61df03e | Iustin Pop | if not isinstance(self.op.nics, list): |
9668 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid parameter 'nics'", |
9669 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
9670 | d61df03e | Iustin Pop | for row in self.op.nics: |
9671 | d61df03e | Iustin Pop | if (not isinstance(row, dict) or |
9672 | d61df03e | Iustin Pop | "mac" not in row or |
9673 | d61df03e | Iustin Pop | "ip" not in row or |
9674 | d61df03e | Iustin Pop | "bridge" not in row): |
9675 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid contents of the 'nics'" |
9676 | 5c983ee5 | Iustin Pop | " parameter", errors.ECODE_INVAL)
|
9677 | d61df03e | Iustin Pop | if not isinstance(self.op.disks, list): |
9678 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid parameter 'disks'", |
9679 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
9680 | d61df03e | Iustin Pop | for row in self.op.disks: |
9681 | d61df03e | Iustin Pop | if (not isinstance(row, dict) or |
9682 | d61df03e | Iustin Pop | "size" not in row or |
9683 | d61df03e | Iustin Pop | not isinstance(row["size"], int) or |
9684 | d61df03e | Iustin Pop | "mode" not in row or |
9685 | d61df03e | Iustin Pop | row["mode"] not in ['r', 'w']): |
9686 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Invalid contents of the 'disks'" |
9687 | 5c983ee5 | Iustin Pop | " parameter", errors.ECODE_INVAL)
|
9688 | 8901997e | Iustin Pop | if not hasattr(self.op, "hypervisor") or self.op.hypervisor is None: |
9689 | 8cc7e742 | Guido Trotter | self.op.hypervisor = self.cfg.GetHypervisorType() |
9690 | 298fe380 | Iustin Pop | elif self.op.mode == constants.IALLOCATOR_MODE_RELOC: |
9691 | d61df03e | Iustin Pop | if not hasattr(self.op, "name"): |
9692 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Missing attribute 'name' on opcode input", |
9693 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
9694 | cf26a87a | Iustin Pop | fname = _ExpandInstanceName(self.cfg, self.op.name) |
9695 | d61df03e | Iustin Pop | self.op.name = fname
|
9696 | 29859cb7 | Iustin Pop | self.relocate_from = self.cfg.GetInstanceInfo(fname).secondary_nodes |
9697 | 823a72bc | Iustin Pop | elif self.op.mode == constants.IALLOCATOR_MODE_MEVAC: |
9698 | 823a72bc | Iustin Pop | if not hasattr(self.op, "evac_nodes"): |
9699 | 823a72bc | Iustin Pop | raise errors.OpPrereqError("Missing attribute 'evac_nodes' on" |
9700 | 823a72bc | Iustin Pop | " opcode input", errors.ECODE_INVAL)
|
9701 | d61df03e | Iustin Pop | else:
|
9702 | d61df03e | Iustin Pop | raise errors.OpPrereqError("Invalid test allocator mode '%s'" % |
9703 | 5c983ee5 | Iustin Pop | self.op.mode, errors.ECODE_INVAL)
|
9704 | d61df03e | Iustin Pop | |
9705 | 298fe380 | Iustin Pop | if self.op.direction == constants.IALLOCATOR_DIR_OUT: |
9706 | 298fe380 | Iustin Pop | if not hasattr(self.op, "allocator") or self.op.allocator is None: |
9707 | 5c983ee5 | Iustin Pop | raise errors.OpPrereqError("Missing allocator name", |
9708 | 5c983ee5 | Iustin Pop | errors.ECODE_INVAL) |
9709 | 298fe380 | Iustin Pop | elif self.op.direction != constants.IALLOCATOR_DIR_IN: |
9710 | d61df03e | Iustin Pop | raise errors.OpPrereqError("Wrong allocator test '%s'" % |
9711 | 5c983ee5 | Iustin Pop | self.op.direction, errors.ECODE_INVAL)
|
9712 | d61df03e | Iustin Pop | |
9713 | d61df03e | Iustin Pop | def Exec(self, feedback_fn): |
9714 | d61df03e | Iustin Pop | """Run the allocator test.
|
9715 | d61df03e | Iustin Pop |
|
9716 | d61df03e | Iustin Pop | """
|
9717 | 29859cb7 | Iustin Pop | if self.op.mode == constants.IALLOCATOR_MODE_ALLOC: |
9718 | 923ddac0 | Michael Hanselmann | ial = IAllocator(self.cfg, self.rpc, |
9719 | 29859cb7 | Iustin Pop | mode=self.op.mode,
|
9720 | 29859cb7 | Iustin Pop | name=self.op.name,
|
9721 | 29859cb7 | Iustin Pop | mem_size=self.op.mem_size,
|
9722 | 29859cb7 | Iustin Pop | disks=self.op.disks,
|
9723 | 29859cb7 | Iustin Pop | disk_template=self.op.disk_template,
|
9724 | 29859cb7 | Iustin Pop | os=self.op.os,
|
9725 | 29859cb7 | Iustin Pop | tags=self.op.tags,
|
9726 | 29859cb7 | Iustin Pop | nics=self.op.nics,
|
9727 | 29859cb7 | Iustin Pop | vcpus=self.op.vcpus,
|
9728 | 8cc7e742 | Guido Trotter | hypervisor=self.op.hypervisor,
|
9729 | 29859cb7 | Iustin Pop | ) |
9730 | 823a72bc | Iustin Pop | elif self.op.mode == constants.IALLOCATOR_MODE_RELOC: |
9731 | 923ddac0 | Michael Hanselmann | ial = IAllocator(self.cfg, self.rpc, |
9732 | 29859cb7 | Iustin Pop | mode=self.op.mode,
|
9733 | 29859cb7 | Iustin Pop | name=self.op.name,
|
9734 | 29859cb7 | Iustin Pop | relocate_from=list(self.relocate_from), |
9735 | 29859cb7 | Iustin Pop | ) |
9736 | 823a72bc | Iustin Pop | elif self.op.mode == constants.IALLOCATOR_MODE_MEVAC: |
9737 | 823a72bc | Iustin Pop | ial = IAllocator(self.cfg, self.rpc, |
9738 | 823a72bc | Iustin Pop | mode=self.op.mode,
|
9739 | 823a72bc | Iustin Pop | evac_nodes=self.op.evac_nodes)
|
9740 | 823a72bc | Iustin Pop | else:
|
9741 | 823a72bc | Iustin Pop | raise errors.ProgrammerError("Uncatched mode %s in" |
9742 | 823a72bc | Iustin Pop | " LUTestAllocator.Exec", self.op.mode) |
9743 | d61df03e | Iustin Pop | |
9744 | 298fe380 | Iustin Pop | if self.op.direction == constants.IALLOCATOR_DIR_IN: |
9745 | d1c2dd75 | Iustin Pop | result = ial.in_text |
9746 | 298fe380 | Iustin Pop | else:
|
9747 | d1c2dd75 | Iustin Pop | ial.Run(self.op.allocator, validate=False) |
9748 | d1c2dd75 | Iustin Pop | result = ial.out_text |
9749 | 298fe380 | Iustin Pop | return result |