root / lib / cmdlib.py @ 8b3fd458
History | View | Annotate | Download (184.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 | a8083063 | Iustin Pop | # pylint: disable-msg=W0613,W0201
|
25 | a8083063 | Iustin Pop | |
26 | a8083063 | Iustin Pop | import os |
27 | a8083063 | Iustin Pop | import os.path |
28 | a8083063 | Iustin Pop | import sha |
29 | a8083063 | Iustin Pop | import time |
30 | a8083063 | Iustin Pop | import tempfile |
31 | a8083063 | Iustin Pop | import re |
32 | a8083063 | Iustin Pop | import platform |
33 | ffa1c0dc | Iustin Pop | import logging |
34 | 74409b12 | Iustin Pop | import copy |
35 | a8083063 | Iustin Pop | |
36 | a8083063 | Iustin Pop | from ganeti import ssh |
37 | a8083063 | Iustin Pop | from ganeti import logger |
38 | a8083063 | Iustin Pop | from ganeti import utils |
39 | a8083063 | Iustin Pop | from ganeti import errors |
40 | a8083063 | Iustin Pop | from ganeti import hypervisor |
41 | 6048c986 | Guido Trotter | from ganeti import locking |
42 | a8083063 | Iustin Pop | from ganeti import constants |
43 | a8083063 | Iustin Pop | from ganeti import objects |
44 | a8083063 | Iustin Pop | from ganeti import opcodes |
45 | 8d14b30d | Iustin Pop | from ganeti import serializer |
46 | d61df03e | Iustin Pop | |
47 | d61df03e | Iustin Pop | |
48 | a8083063 | Iustin Pop | class LogicalUnit(object): |
49 | 396e1b78 | Michael Hanselmann | """Logical Unit base class.
|
50 | a8083063 | Iustin Pop |
|
51 | a8083063 | Iustin Pop | Subclasses must follow these rules:
|
52 | d465bdc8 | Guido Trotter | - implement ExpandNames
|
53 | d465bdc8 | Guido Trotter | - implement CheckPrereq
|
54 | a8083063 | Iustin Pop | - implement Exec
|
55 | a8083063 | Iustin Pop | - implement BuildHooksEnv
|
56 | a8083063 | Iustin Pop | - redefine HPATH and HTYPE
|
57 | 05f86716 | Guido Trotter | - optionally redefine their run requirements:
|
58 | 05f86716 | Guido Trotter | REQ_MASTER: the LU needs to run on the master node
|
59 | 7e55040e | Guido Trotter | REQ_BGL: the LU needs to hold the Big Ganeti Lock exclusively
|
60 | 05f86716 | Guido Trotter |
|
61 | 05f86716 | Guido Trotter | Note that all commands require root permissions.
|
62 | a8083063 | Iustin Pop |
|
63 | a8083063 | Iustin Pop | """
|
64 | a8083063 | Iustin Pop | HPATH = None
|
65 | a8083063 | Iustin Pop | HTYPE = None
|
66 | a8083063 | Iustin Pop | _OP_REQP = [] |
67 | a8083063 | Iustin Pop | REQ_MASTER = True
|
68 | 7e55040e | Guido Trotter | REQ_BGL = True
|
69 | a8083063 | Iustin Pop | |
70 | 72737a7f | Iustin Pop | def __init__(self, processor, op, context, rpc): |
71 | a8083063 | Iustin Pop | """Constructor for LogicalUnit.
|
72 | a8083063 | Iustin Pop |
|
73 | a8083063 | Iustin Pop | This needs to be overriden in derived classes in order to check op
|
74 | a8083063 | Iustin Pop | validity.
|
75 | a8083063 | Iustin Pop |
|
76 | a8083063 | Iustin Pop | """
|
77 | 5bfac263 | Iustin Pop | self.proc = processor
|
78 | a8083063 | Iustin Pop | self.op = op
|
79 | 77b657a3 | Guido Trotter | self.cfg = context.cfg
|
80 | 77b657a3 | Guido Trotter | self.context = context
|
81 | 72737a7f | Iustin Pop | self.rpc = rpc
|
82 | ca2a79e1 | Guido Trotter | # Dicts used to declare locking needs to mcpu
|
83 | d465bdc8 | Guido Trotter | self.needed_locks = None |
84 | 6683bba2 | Guido Trotter | self.acquired_locks = {}
|
85 | 3977a4c1 | Guido Trotter | self.share_locks = dict(((i, 0) for i in locking.LEVELS)) |
86 | ca2a79e1 | Guido Trotter | self.add_locks = {}
|
87 | ca2a79e1 | Guido Trotter | self.remove_locks = {}
|
88 | c4a2fee1 | Guido Trotter | # Used to force good behavior when calling helper functions
|
89 | c4a2fee1 | Guido Trotter | self.recalculate_locks = {}
|
90 | c92b310a | Michael Hanselmann | self.__ssh = None |
91 | c92b310a | Michael Hanselmann | |
92 | a8083063 | Iustin Pop | for attr_name in self._OP_REQP: |
93 | a8083063 | Iustin Pop | attr_val = getattr(op, attr_name, None) |
94 | a8083063 | Iustin Pop | if attr_val is None: |
95 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Required parameter '%s' missing" % |
96 | 3ecf6786 | Iustin Pop | attr_name) |
97 | c6d58a2b | Michael Hanselmann | |
98 | f64c9de6 | Guido Trotter | if not self.cfg.IsCluster(): |
99 | c6d58a2b | Michael Hanselmann | raise errors.OpPrereqError("Cluster not initialized yet," |
100 | c6d58a2b | Michael Hanselmann | " use 'gnt-cluster init' first.")
|
101 | c6d58a2b | Michael Hanselmann | if self.REQ_MASTER: |
102 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
103 | c6d58a2b | Michael Hanselmann | if master != utils.HostInfo().name:
|
104 | c6d58a2b | Michael Hanselmann | raise errors.OpPrereqError("Commands must be run on the master" |
105 | c6d58a2b | Michael Hanselmann | " node %s" % master)
|
106 | a8083063 | Iustin Pop | |
107 | c92b310a | Michael Hanselmann | def __GetSSH(self): |
108 | c92b310a | Michael Hanselmann | """Returns the SshRunner object
|
109 | c92b310a | Michael Hanselmann |
|
110 | c92b310a | Michael Hanselmann | """
|
111 | c92b310a | Michael Hanselmann | if not self.__ssh: |
112 | 6b0469d2 | Iustin Pop | self.__ssh = ssh.SshRunner(self.cfg.GetClusterName()) |
113 | c92b310a | Michael Hanselmann | return self.__ssh |
114 | c92b310a | Michael Hanselmann | |
115 | c92b310a | Michael Hanselmann | ssh = property(fget=__GetSSH)
|
116 | c92b310a | Michael Hanselmann | |
117 | d465bdc8 | Guido Trotter | def ExpandNames(self): |
118 | d465bdc8 | Guido Trotter | """Expand names for this LU.
|
119 | d465bdc8 | Guido Trotter |
|
120 | d465bdc8 | Guido Trotter | This method is called before starting to execute the opcode, and it should
|
121 | d465bdc8 | Guido Trotter | update all the parameters of the opcode to their canonical form (e.g. a
|
122 | d465bdc8 | Guido Trotter | short node name must be fully expanded after this method has successfully
|
123 | d465bdc8 | Guido Trotter | completed). This way locking, hooks, logging, ecc. can work correctly.
|
124 | d465bdc8 | Guido Trotter |
|
125 | d465bdc8 | Guido Trotter | LUs which implement this method must also populate the self.needed_locks
|
126 | d465bdc8 | Guido Trotter | member, as a dict with lock levels as keys, and a list of needed lock names
|
127 | d465bdc8 | Guido Trotter | as values. Rules:
|
128 | d465bdc8 | Guido Trotter | - Use an empty dict if you don't need any lock
|
129 | d465bdc8 | Guido Trotter | - If you don't need any lock at a particular level omit that level
|
130 | d465bdc8 | Guido Trotter | - Don't put anything for the BGL level
|
131 | e310b019 | Guido Trotter | - If you want all locks at a level use locking.ALL_SET as a value
|
132 | d465bdc8 | Guido Trotter |
|
133 | 3977a4c1 | Guido Trotter | If you need to share locks (rather than acquire them exclusively) at one
|
134 | 3977a4c1 | Guido Trotter | level you can modify self.share_locks, setting a true value (usually 1) for
|
135 | 3977a4c1 | Guido Trotter | that level. By default locks are not shared.
|
136 | 3977a4c1 | Guido Trotter |
|
137 | d465bdc8 | Guido Trotter | Examples:
|
138 | d465bdc8 | Guido Trotter | # Acquire all nodes and one instance
|
139 | d465bdc8 | Guido Trotter | self.needed_locks = {
|
140 | e310b019 | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET,
|
141 | 3a5d7305 | Guido Trotter | locking.LEVEL_INSTANCE: ['instance1.example.tld'],
|
142 | d465bdc8 | Guido Trotter | }
|
143 | d465bdc8 | Guido Trotter | # Acquire just two nodes
|
144 | d465bdc8 | Guido Trotter | self.needed_locks = {
|
145 | d465bdc8 | Guido Trotter | locking.LEVEL_NODE: ['node1.example.tld', 'node2.example.tld'],
|
146 | d465bdc8 | Guido Trotter | }
|
147 | d465bdc8 | Guido Trotter | # Acquire no locks
|
148 | d465bdc8 | Guido Trotter | self.needed_locks = {} # No, you can't leave it to the default value None
|
149 | d465bdc8 | Guido Trotter |
|
150 | d465bdc8 | Guido Trotter | """
|
151 | d465bdc8 | Guido Trotter | # The implementation of this method is mandatory only if the new LU is
|
152 | d465bdc8 | Guido Trotter | # concurrent, so that old LUs don't need to be changed all at the same
|
153 | d465bdc8 | Guido Trotter | # time.
|
154 | d465bdc8 | Guido Trotter | if self.REQ_BGL: |
155 | d465bdc8 | Guido Trotter | self.needed_locks = {} # Exclusive LUs don't need locks. |
156 | d465bdc8 | Guido Trotter | else:
|
157 | d465bdc8 | Guido Trotter | raise NotImplementedError |
158 | d465bdc8 | Guido Trotter | |
159 | fb8dcb62 | Guido Trotter | def DeclareLocks(self, level): |
160 | fb8dcb62 | Guido Trotter | """Declare LU locking needs for a level
|
161 | fb8dcb62 | Guido Trotter |
|
162 | fb8dcb62 | Guido Trotter | While most LUs can just declare their locking needs at ExpandNames time,
|
163 | fb8dcb62 | Guido Trotter | sometimes there's the need to calculate some locks after having acquired
|
164 | fb8dcb62 | Guido Trotter | the ones before. This function is called just before acquiring locks at a
|
165 | fb8dcb62 | Guido Trotter | particular level, but after acquiring the ones at lower levels, and permits
|
166 | fb8dcb62 | Guido Trotter | such calculations. It can be used to modify self.needed_locks, and by
|
167 | fb8dcb62 | Guido Trotter | default it does nothing.
|
168 | fb8dcb62 | Guido Trotter |
|
169 | fb8dcb62 | Guido Trotter | This function is only called if you have something already set in
|
170 | fb8dcb62 | Guido Trotter | self.needed_locks for the level.
|
171 | fb8dcb62 | Guido Trotter |
|
172 | fb8dcb62 | Guido Trotter | @param level: Locking level which is going to be locked
|
173 | fb8dcb62 | Guido Trotter | @type level: member of ganeti.locking.LEVELS
|
174 | fb8dcb62 | Guido Trotter |
|
175 | fb8dcb62 | Guido Trotter | """
|
176 | fb8dcb62 | Guido Trotter | |
177 | a8083063 | Iustin Pop | def CheckPrereq(self): |
178 | a8083063 | Iustin Pop | """Check prerequisites for this LU.
|
179 | a8083063 | Iustin Pop |
|
180 | a8083063 | Iustin Pop | This method should check that the prerequisites for the execution
|
181 | a8083063 | Iustin Pop | of this LU are fulfilled. It can do internode communication, but
|
182 | a8083063 | Iustin Pop | it should be idempotent - no cluster or system changes are
|
183 | a8083063 | Iustin Pop | allowed.
|
184 | a8083063 | Iustin Pop |
|
185 | a8083063 | Iustin Pop | The method should raise errors.OpPrereqError in case something is
|
186 | a8083063 | Iustin Pop | not fulfilled. Its return value is ignored.
|
187 | a8083063 | Iustin Pop |
|
188 | a8083063 | Iustin Pop | This method should also update all the parameters of the opcode to
|
189 | d465bdc8 | Guido Trotter | their canonical form if it hasn't been done by ExpandNames before.
|
190 | a8083063 | Iustin Pop |
|
191 | a8083063 | Iustin Pop | """
|
192 | a8083063 | Iustin Pop | raise NotImplementedError |
193 | a8083063 | Iustin Pop | |
194 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
195 | a8083063 | Iustin Pop | """Execute the LU.
|
196 | a8083063 | Iustin Pop |
|
197 | a8083063 | Iustin Pop | This method should implement the actual work. It should raise
|
198 | a8083063 | Iustin Pop | errors.OpExecError for failures that are somewhat dealt with in
|
199 | a8083063 | Iustin Pop | code, or expected.
|
200 | a8083063 | Iustin Pop |
|
201 | a8083063 | Iustin Pop | """
|
202 | a8083063 | Iustin Pop | raise NotImplementedError |
203 | a8083063 | Iustin Pop | |
204 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
205 | a8083063 | Iustin Pop | """Build hooks environment for this LU.
|
206 | a8083063 | Iustin Pop |
|
207 | a8083063 | Iustin Pop | This method should return a three-node tuple consisting of: a dict
|
208 | a8083063 | Iustin Pop | containing the environment that will be used for running the
|
209 | a8083063 | Iustin Pop | specific hook for this LU, a list of node names on which the hook
|
210 | a8083063 | Iustin Pop | should run before the execution, and a list of node names on which
|
211 | a8083063 | Iustin Pop | the hook should run after the execution.
|
212 | a8083063 | Iustin Pop |
|
213 | a8083063 | Iustin Pop | The keys of the dict must not have 'GANETI_' prefixed as this will
|
214 | a8083063 | Iustin Pop | be handled in the hooks runner. Also note additional keys will be
|
215 | a8083063 | Iustin Pop | added by the hooks runner. If the LU doesn't define any
|
216 | a8083063 | Iustin Pop | environment, an empty dict (and not None) should be returned.
|
217 | a8083063 | Iustin Pop |
|
218 | 8a3fe350 | Guido Trotter | No nodes should be returned as an empty list (and not None).
|
219 | a8083063 | Iustin Pop |
|
220 | a8083063 | Iustin Pop | Note that if the HPATH for a LU class is None, this function will
|
221 | a8083063 | Iustin Pop | not be called.
|
222 | a8083063 | Iustin Pop |
|
223 | a8083063 | Iustin Pop | """
|
224 | a8083063 | Iustin Pop | raise NotImplementedError |
225 | a8083063 | Iustin Pop | |
226 | 1fce5219 | Guido Trotter | def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result): |
227 | 1fce5219 | Guido Trotter | """Notify the LU about the results of its hooks.
|
228 | 1fce5219 | Guido Trotter |
|
229 | 1fce5219 | Guido Trotter | This method is called every time a hooks phase is executed, and notifies
|
230 | 1fce5219 | Guido Trotter | the Logical Unit about the hooks' result. The LU can then use it to alter
|
231 | 1fce5219 | Guido Trotter | its result based on the hooks. By default the method does nothing and the
|
232 | 1fce5219 | Guido Trotter | previous result is passed back unchanged but any LU can define it if it
|
233 | 1fce5219 | Guido Trotter | wants to use the local cluster hook-scripts somehow.
|
234 | 1fce5219 | Guido Trotter |
|
235 | 1fce5219 | Guido Trotter | Args:
|
236 | 1fce5219 | Guido Trotter | phase: the hooks phase that has just been run
|
237 | 1fce5219 | Guido Trotter | hooks_results: the results of the multi-node hooks rpc call
|
238 | 1fce5219 | Guido Trotter | feedback_fn: function to send feedback back to the caller
|
239 | 1fce5219 | Guido Trotter | lu_result: the previous result this LU had, or None in the PRE phase.
|
240 | 1fce5219 | Guido Trotter |
|
241 | 1fce5219 | Guido Trotter | """
|
242 | 1fce5219 | Guido Trotter | return lu_result
|
243 | 1fce5219 | Guido Trotter | |
244 | 43905206 | Guido Trotter | def _ExpandAndLockInstance(self): |
245 | 43905206 | Guido Trotter | """Helper function to expand and lock an instance.
|
246 | 43905206 | Guido Trotter |
|
247 | 43905206 | Guido Trotter | Many LUs that work on an instance take its name in self.op.instance_name
|
248 | 43905206 | Guido Trotter | and need to expand it and then declare the expanded name for locking. This
|
249 | 43905206 | Guido Trotter | function does it, and then updates self.op.instance_name to the expanded
|
250 | 43905206 | Guido Trotter | name. It also initializes needed_locks as a dict, if this hasn't been done
|
251 | 43905206 | Guido Trotter | before.
|
252 | 43905206 | Guido Trotter |
|
253 | 43905206 | Guido Trotter | """
|
254 | 43905206 | Guido Trotter | if self.needed_locks is None: |
255 | 43905206 | Guido Trotter | self.needed_locks = {}
|
256 | 43905206 | Guido Trotter | else:
|
257 | 43905206 | Guido Trotter | assert locking.LEVEL_INSTANCE not in self.needed_locks, \ |
258 | 43905206 | Guido Trotter | "_ExpandAndLockInstance called with instance-level locks set"
|
259 | 43905206 | Guido Trotter | expanded_name = self.cfg.ExpandInstanceName(self.op.instance_name) |
260 | 43905206 | Guido Trotter | if expanded_name is None: |
261 | 43905206 | Guido Trotter | raise errors.OpPrereqError("Instance '%s' not known" % |
262 | 43905206 | Guido Trotter | self.op.instance_name)
|
263 | 43905206 | Guido Trotter | self.needed_locks[locking.LEVEL_INSTANCE] = expanded_name
|
264 | 43905206 | Guido Trotter | self.op.instance_name = expanded_name
|
265 | 43905206 | Guido Trotter | |
266 | a82ce292 | Guido Trotter | def _LockInstancesNodes(self, primary_only=False): |
267 | c4a2fee1 | Guido Trotter | """Helper function to declare instances' nodes for locking.
|
268 | c4a2fee1 | Guido Trotter |
|
269 | c4a2fee1 | Guido Trotter | This function should be called after locking one or more instances to lock
|
270 | c4a2fee1 | Guido Trotter | their nodes. Its effect is populating self.needed_locks[locking.LEVEL_NODE]
|
271 | c4a2fee1 | Guido Trotter | with all primary or secondary nodes for instances already locked and
|
272 | c4a2fee1 | Guido Trotter | present in self.needed_locks[locking.LEVEL_INSTANCE].
|
273 | c4a2fee1 | Guido Trotter |
|
274 | c4a2fee1 | Guido Trotter | It should be called from DeclareLocks, and for safety only works if
|
275 | c4a2fee1 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] is set.
|
276 | c4a2fee1 | Guido Trotter |
|
277 | c4a2fee1 | Guido Trotter | In the future it may grow parameters to just lock some instance's nodes, or
|
278 | c4a2fee1 | Guido Trotter | to just lock primaries or secondary nodes, if needed.
|
279 | c4a2fee1 | Guido Trotter |
|
280 | c4a2fee1 | Guido Trotter | If should be called in DeclareLocks in a way similar to:
|
281 | c4a2fee1 | Guido Trotter |
|
282 | c4a2fee1 | Guido Trotter | if level == locking.LEVEL_NODE:
|
283 | c4a2fee1 | Guido Trotter | self._LockInstancesNodes()
|
284 | c4a2fee1 | Guido Trotter |
|
285 | a82ce292 | Guido Trotter | @type primary_only: boolean
|
286 | a82ce292 | Guido Trotter | @param primary_only: only lock primary nodes of locked instances
|
287 | a82ce292 | Guido Trotter |
|
288 | c4a2fee1 | Guido Trotter | """
|
289 | c4a2fee1 | Guido Trotter | assert locking.LEVEL_NODE in self.recalculate_locks, \ |
290 | c4a2fee1 | Guido Trotter | "_LockInstancesNodes helper function called with no nodes to recalculate"
|
291 | c4a2fee1 | Guido Trotter | |
292 | c4a2fee1 | Guido Trotter | # TODO: check if we're really been called with the instance locks held
|
293 | c4a2fee1 | Guido Trotter | |
294 | c4a2fee1 | Guido Trotter | # For now we'll replace self.needed_locks[locking.LEVEL_NODE], but in the
|
295 | c4a2fee1 | Guido Trotter | # future we might want to have different behaviors depending on the value
|
296 | c4a2fee1 | Guido Trotter | # of self.recalculate_locks[locking.LEVEL_NODE]
|
297 | c4a2fee1 | Guido Trotter | wanted_nodes = [] |
298 | 6683bba2 | Guido Trotter | for instance_name in self.acquired_locks[locking.LEVEL_INSTANCE]: |
299 | c4a2fee1 | Guido Trotter | instance = self.context.cfg.GetInstanceInfo(instance_name)
|
300 | c4a2fee1 | Guido Trotter | wanted_nodes.append(instance.primary_node) |
301 | a82ce292 | Guido Trotter | if not primary_only: |
302 | a82ce292 | Guido Trotter | wanted_nodes.extend(instance.secondary_nodes) |
303 | 9513b6ab | Guido Trotter | |
304 | 9513b6ab | Guido Trotter | if self.recalculate_locks[locking.LEVEL_NODE] == constants.LOCKS_REPLACE: |
305 | 9513b6ab | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = wanted_nodes
|
306 | 9513b6ab | Guido Trotter | elif self.recalculate_locks[locking.LEVEL_NODE] == constants.LOCKS_APPEND: |
307 | 9513b6ab | Guido Trotter | self.needed_locks[locking.LEVEL_NODE].extend(wanted_nodes)
|
308 | c4a2fee1 | Guido Trotter | |
309 | c4a2fee1 | Guido Trotter | del self.recalculate_locks[locking.LEVEL_NODE] |
310 | c4a2fee1 | Guido Trotter | |
311 | a8083063 | Iustin Pop | |
312 | a8083063 | Iustin Pop | class NoHooksLU(LogicalUnit): |
313 | a8083063 | Iustin Pop | """Simple LU which runs no hooks.
|
314 | a8083063 | Iustin Pop |
|
315 | a8083063 | Iustin Pop | This LU is intended as a parent for other LogicalUnits which will
|
316 | a8083063 | Iustin Pop | run no hooks, in order to reduce duplicate code.
|
317 | a8083063 | Iustin Pop |
|
318 | a8083063 | Iustin Pop | """
|
319 | a8083063 | Iustin Pop | HPATH = None
|
320 | a8083063 | Iustin Pop | HTYPE = None
|
321 | a8083063 | Iustin Pop | |
322 | a8083063 | Iustin Pop | |
323 | dcb93971 | Michael Hanselmann | def _GetWantedNodes(lu, nodes): |
324 | a7ba5e53 | Iustin Pop | """Returns list of checked and expanded node names.
|
325 | 83120a01 | Michael Hanselmann |
|
326 | 83120a01 | Michael Hanselmann | Args:
|
327 | 83120a01 | Michael Hanselmann | nodes: List of nodes (strings) or None for all
|
328 | 83120a01 | Michael Hanselmann |
|
329 | 83120a01 | Michael Hanselmann | """
|
330 | 3312b702 | Iustin Pop | if not isinstance(nodes, list): |
331 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Invalid argument type 'nodes'") |
332 | dcb93971 | Michael Hanselmann | |
333 | ea47808a | Guido Trotter | if not nodes: |
334 | ea47808a | Guido Trotter | raise errors.ProgrammerError("_GetWantedNodes should only be called with a" |
335 | ea47808a | Guido Trotter | " non-empty list of nodes whose name is to be expanded.")
|
336 | dcb93971 | Michael Hanselmann | |
337 | ea47808a | Guido Trotter | wanted = [] |
338 | ea47808a | Guido Trotter | for name in nodes: |
339 | ea47808a | Guido Trotter | node = lu.cfg.ExpandNodeName(name) |
340 | ea47808a | Guido Trotter | if node is None: |
341 | ea47808a | Guido Trotter | raise errors.OpPrereqError("No such node name '%s'" % name) |
342 | ea47808a | Guido Trotter | wanted.append(node) |
343 | dcb93971 | Michael Hanselmann | |
344 | a7ba5e53 | Iustin Pop | return utils.NiceSort(wanted)
|
345 | 3312b702 | Iustin Pop | |
346 | 3312b702 | Iustin Pop | |
347 | 3312b702 | Iustin Pop | def _GetWantedInstances(lu, instances): |
348 | a7ba5e53 | Iustin Pop | """Returns list of checked and expanded instance names.
|
349 | 3312b702 | Iustin Pop |
|
350 | 3312b702 | Iustin Pop | Args:
|
351 | 3312b702 | Iustin Pop | instances: List of instances (strings) or None for all
|
352 | 3312b702 | Iustin Pop |
|
353 | 3312b702 | Iustin Pop | """
|
354 | 3312b702 | Iustin Pop | if not isinstance(instances, list): |
355 | 3312b702 | Iustin Pop | raise errors.OpPrereqError("Invalid argument type 'instances'") |
356 | 3312b702 | Iustin Pop | |
357 | 3312b702 | Iustin Pop | if instances:
|
358 | 3312b702 | Iustin Pop | wanted = [] |
359 | 3312b702 | Iustin Pop | |
360 | 3312b702 | Iustin Pop | for name in instances: |
361 | a7ba5e53 | Iustin Pop | instance = lu.cfg.ExpandInstanceName(name) |
362 | 3312b702 | Iustin Pop | if instance is None: |
363 | 3312b702 | Iustin Pop | raise errors.OpPrereqError("No such instance name '%s'" % name) |
364 | 3312b702 | Iustin Pop | wanted.append(instance) |
365 | 3312b702 | Iustin Pop | |
366 | 3312b702 | Iustin Pop | else:
|
367 | a7ba5e53 | Iustin Pop | wanted = lu.cfg.GetInstanceList() |
368 | a7ba5e53 | Iustin Pop | return utils.NiceSort(wanted)
|
369 | dcb93971 | Michael Hanselmann | |
370 | dcb93971 | Michael Hanselmann | |
371 | dcb93971 | Michael Hanselmann | def _CheckOutputFields(static, dynamic, selected): |
372 | 83120a01 | Michael Hanselmann | """Checks whether all selected fields are valid.
|
373 | 83120a01 | Michael Hanselmann |
|
374 | 83120a01 | Michael Hanselmann | Args:
|
375 | 83120a01 | Michael Hanselmann | static: Static fields
|
376 | 83120a01 | Michael Hanselmann | dynamic: Dynamic fields
|
377 | 83120a01 | Michael Hanselmann |
|
378 | 83120a01 | Michael Hanselmann | """
|
379 | 83120a01 | Michael Hanselmann | static_fields = frozenset(static)
|
380 | 83120a01 | Michael Hanselmann | dynamic_fields = frozenset(dynamic)
|
381 | dcb93971 | Michael Hanselmann | |
382 | 83120a01 | Michael Hanselmann | all_fields = static_fields | dynamic_fields |
383 | dcb93971 | Michael Hanselmann | |
384 | 83120a01 | Michael Hanselmann | if not all_fields.issuperset(selected): |
385 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Unknown output fields selected: %s" |
386 | 3ecf6786 | Iustin Pop | % ",".join(frozenset(selected). |
387 | 3ecf6786 | Iustin Pop | difference(all_fields))) |
388 | dcb93971 | Michael Hanselmann | |
389 | dcb93971 | Michael Hanselmann | |
390 | ecb215b5 | Michael Hanselmann | def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, |
391 | 396e1b78 | Michael Hanselmann | memory, vcpus, nics): |
392 | ecb215b5 | Michael Hanselmann | """Builds instance related env variables for hooks from single variables.
|
393 | ecb215b5 | Michael Hanselmann |
|
394 | ecb215b5 | Michael Hanselmann | Args:
|
395 | ecb215b5 | Michael Hanselmann | secondary_nodes: List of secondary nodes as strings
|
396 | 396e1b78 | Michael Hanselmann | """
|
397 | 396e1b78 | Michael Hanselmann | env = { |
398 | 0e137c28 | Iustin Pop | "OP_TARGET": name,
|
399 | 396e1b78 | Michael Hanselmann | "INSTANCE_NAME": name,
|
400 | 396e1b78 | Michael Hanselmann | "INSTANCE_PRIMARY": primary_node,
|
401 | 396e1b78 | Michael Hanselmann | "INSTANCE_SECONDARIES": " ".join(secondary_nodes), |
402 | ecb215b5 | Michael Hanselmann | "INSTANCE_OS_TYPE": os_type,
|
403 | 396e1b78 | Michael Hanselmann | "INSTANCE_STATUS": status,
|
404 | 396e1b78 | Michael Hanselmann | "INSTANCE_MEMORY": memory,
|
405 | 396e1b78 | Michael Hanselmann | "INSTANCE_VCPUS": vcpus,
|
406 | 396e1b78 | Michael Hanselmann | } |
407 | 396e1b78 | Michael Hanselmann | |
408 | 396e1b78 | Michael Hanselmann | if nics:
|
409 | 396e1b78 | Michael Hanselmann | nic_count = len(nics)
|
410 | 53e4e875 | Guido Trotter | for idx, (ip, bridge, mac) in enumerate(nics): |
411 | 396e1b78 | Michael Hanselmann | if ip is None: |
412 | 396e1b78 | Michael Hanselmann | ip = ""
|
413 | 396e1b78 | Michael Hanselmann | env["INSTANCE_NIC%d_IP" % idx] = ip
|
414 | 396e1b78 | Michael Hanselmann | env["INSTANCE_NIC%d_BRIDGE" % idx] = bridge
|
415 | 53e4e875 | Guido Trotter | env["INSTANCE_NIC%d_HWADDR" % idx] = mac
|
416 | 396e1b78 | Michael Hanselmann | else:
|
417 | 396e1b78 | Michael Hanselmann | nic_count = 0
|
418 | 396e1b78 | Michael Hanselmann | |
419 | 396e1b78 | Michael Hanselmann | env["INSTANCE_NIC_COUNT"] = nic_count
|
420 | 396e1b78 | Michael Hanselmann | |
421 | 396e1b78 | Michael Hanselmann | return env
|
422 | 396e1b78 | Michael Hanselmann | |
423 | 396e1b78 | Michael Hanselmann | |
424 | 396e1b78 | Michael Hanselmann | def _BuildInstanceHookEnvByObject(instance, override=None): |
425 | ecb215b5 | Michael Hanselmann | """Builds instance related env variables for hooks from an object.
|
426 | ecb215b5 | Michael Hanselmann |
|
427 | ecb215b5 | Michael Hanselmann | Args:
|
428 | ecb215b5 | Michael Hanselmann | instance: objects.Instance object of instance
|
429 | ecb215b5 | Michael Hanselmann | override: dict of values to override
|
430 | ecb215b5 | Michael Hanselmann | """
|
431 | 396e1b78 | Michael Hanselmann | args = { |
432 | 396e1b78 | Michael Hanselmann | 'name': instance.name,
|
433 | 396e1b78 | Michael Hanselmann | 'primary_node': instance.primary_node,
|
434 | 396e1b78 | Michael Hanselmann | 'secondary_nodes': instance.secondary_nodes,
|
435 | ecb215b5 | Michael Hanselmann | 'os_type': instance.os,
|
436 | 396e1b78 | Michael Hanselmann | 'status': instance.os,
|
437 | 396e1b78 | Michael Hanselmann | 'memory': instance.memory,
|
438 | 396e1b78 | Michael Hanselmann | 'vcpus': instance.vcpus,
|
439 | 53e4e875 | Guido Trotter | 'nics': [(nic.ip, nic.bridge, nic.mac) for nic in instance.nics], |
440 | 396e1b78 | Michael Hanselmann | } |
441 | 396e1b78 | Michael Hanselmann | if override:
|
442 | 396e1b78 | Michael Hanselmann | args.update(override) |
443 | 396e1b78 | Michael Hanselmann | return _BuildInstanceHookEnv(**args)
|
444 | 396e1b78 | Michael Hanselmann | |
445 | 396e1b78 | Michael Hanselmann | |
446 | b9bddb6b | Iustin Pop | def _CheckInstanceBridgesExist(lu, instance): |
447 | bf6929a2 | Alexander Schreiber | """Check that the brigdes needed by an instance exist.
|
448 | bf6929a2 | Alexander Schreiber |
|
449 | bf6929a2 | Alexander Schreiber | """
|
450 | bf6929a2 | Alexander Schreiber | # check bridges existance
|
451 | bf6929a2 | Alexander Schreiber | brlist = [nic.bridge for nic in instance.nics] |
452 | 72737a7f | Iustin Pop | if not lu.rpc.call_bridges_exist(instance.primary_node, brlist): |
453 | bf6929a2 | Alexander Schreiber | raise errors.OpPrereqError("one or more target bridges %s does not" |
454 | bf6929a2 | Alexander Schreiber | " exist on destination node '%s'" %
|
455 | bf6929a2 | Alexander Schreiber | (brlist, instance.primary_node)) |
456 | bf6929a2 | Alexander Schreiber | |
457 | bf6929a2 | Alexander Schreiber | |
458 | a8083063 | Iustin Pop | class LUDestroyCluster(NoHooksLU): |
459 | a8083063 | Iustin Pop | """Logical unit for destroying the cluster.
|
460 | a8083063 | Iustin Pop |
|
461 | a8083063 | Iustin Pop | """
|
462 | a8083063 | Iustin Pop | _OP_REQP = [] |
463 | a8083063 | Iustin Pop | |
464 | a8083063 | Iustin Pop | def CheckPrereq(self): |
465 | a8083063 | Iustin Pop | """Check prerequisites.
|
466 | a8083063 | Iustin Pop |
|
467 | a8083063 | Iustin Pop | This checks whether the cluster is empty.
|
468 | a8083063 | Iustin Pop |
|
469 | a8083063 | Iustin Pop | Any errors are signalled by raising errors.OpPrereqError.
|
470 | a8083063 | Iustin Pop |
|
471 | a8083063 | Iustin Pop | """
|
472 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
473 | a8083063 | Iustin Pop | |
474 | a8083063 | Iustin Pop | nodelist = self.cfg.GetNodeList()
|
475 | db915bd1 | Michael Hanselmann | if len(nodelist) != 1 or nodelist[0] != master: |
476 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("There are still %d node(s) in" |
477 | 3ecf6786 | Iustin Pop | " this cluster." % (len(nodelist) - 1)) |
478 | db915bd1 | Michael Hanselmann | instancelist = self.cfg.GetInstanceList()
|
479 | db915bd1 | Michael Hanselmann | if instancelist:
|
480 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("There are still %d instance(s) in" |
481 | 3ecf6786 | Iustin Pop | " this cluster." % len(instancelist)) |
482 | a8083063 | Iustin Pop | |
483 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
484 | a8083063 | Iustin Pop | """Destroys the cluster.
|
485 | a8083063 | Iustin Pop |
|
486 | a8083063 | Iustin Pop | """
|
487 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
488 | 72737a7f | Iustin Pop | if not self.rpc.call_node_stop_master(master, False): |
489 | c9064964 | Iustin Pop | raise errors.OpExecError("Could not disable the master role") |
490 | 70d9e3d8 | Iustin Pop | priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS) |
491 | 70d9e3d8 | Iustin Pop | utils.CreateBackup(priv_key) |
492 | 70d9e3d8 | Iustin Pop | utils.CreateBackup(pub_key) |
493 | 140aa4a8 | Iustin Pop | return master
|
494 | a8083063 | Iustin Pop | |
495 | a8083063 | Iustin Pop | |
496 | d8fff41c | Guido Trotter | class LUVerifyCluster(LogicalUnit): |
497 | a8083063 | Iustin Pop | """Verifies the cluster status.
|
498 | a8083063 | Iustin Pop |
|
499 | a8083063 | Iustin Pop | """
|
500 | d8fff41c | Guido Trotter | HPATH = "cluster-verify"
|
501 | d8fff41c | Guido Trotter | HTYPE = constants.HTYPE_CLUSTER |
502 | e54c4c5e | Guido Trotter | _OP_REQP = ["skip_checks"]
|
503 | d4b9d97f | Guido Trotter | REQ_BGL = False
|
504 | d4b9d97f | Guido Trotter | |
505 | d4b9d97f | Guido Trotter | def ExpandNames(self): |
506 | d4b9d97f | Guido Trotter | self.needed_locks = {
|
507 | d4b9d97f | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET, |
508 | d4b9d97f | Guido Trotter | locking.LEVEL_INSTANCE: locking.ALL_SET, |
509 | d4b9d97f | Guido Trotter | } |
510 | d4b9d97f | Guido Trotter | self.share_locks = dict(((i, 1) for i in locking.LEVELS)) |
511 | a8083063 | Iustin Pop | |
512 | a8083063 | Iustin Pop | def _VerifyNode(self, node, file_list, local_cksum, vglist, node_result, |
513 | a8083063 | Iustin Pop | remote_version, feedback_fn): |
514 | a8083063 | Iustin Pop | """Run multiple tests against a node.
|
515 | a8083063 | Iustin Pop |
|
516 | a8083063 | Iustin Pop | Test list:
|
517 | a8083063 | Iustin Pop | - compares ganeti version
|
518 | a8083063 | Iustin Pop | - checks vg existance and size > 20G
|
519 | a8083063 | Iustin Pop | - checks config file checksum
|
520 | a8083063 | Iustin Pop | - checks ssh to other nodes
|
521 | a8083063 | Iustin Pop |
|
522 | a8083063 | Iustin Pop | Args:
|
523 | a8083063 | Iustin Pop | node: name of the node to check
|
524 | a8083063 | Iustin Pop | file_list: required list of files
|
525 | a8083063 | Iustin Pop | local_cksum: dictionary of local files and their checksums
|
526 | 098c0958 | Michael Hanselmann |
|
527 | a8083063 | Iustin Pop | """
|
528 | a8083063 | Iustin Pop | # compares ganeti version
|
529 | a8083063 | Iustin Pop | local_version = constants.PROTOCOL_VERSION |
530 | a8083063 | Iustin Pop | if not remote_version: |
531 | c840ae6f | Guido Trotter | feedback_fn(" - ERROR: connection to %s failed" % (node))
|
532 | a8083063 | Iustin Pop | return True |
533 | a8083063 | Iustin Pop | |
534 | a8083063 | Iustin Pop | if local_version != remote_version:
|
535 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: sw version mismatch: master %s, node(%s) %s" %
|
536 | a8083063 | Iustin Pop | (local_version, node, remote_version)) |
537 | a8083063 | Iustin Pop | return True |
538 | a8083063 | Iustin Pop | |
539 | a8083063 | Iustin Pop | # checks vg existance and size > 20G
|
540 | a8083063 | Iustin Pop | |
541 | a8083063 | Iustin Pop | bad = False
|
542 | a8083063 | Iustin Pop | if not vglist: |
543 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: unable to check volume groups on node %s." %
|
544 | a8083063 | Iustin Pop | (node,)) |
545 | a8083063 | Iustin Pop | bad = True
|
546 | a8083063 | Iustin Pop | else:
|
547 | 8d1a2a64 | Michael Hanselmann | vgstatus = utils.CheckVolumeGroupSize(vglist, self.cfg.GetVGName(),
|
548 | 8d1a2a64 | Michael Hanselmann | constants.MIN_VG_SIZE) |
549 | a8083063 | Iustin Pop | if vgstatus:
|
550 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: %s on node %s" % (vgstatus, node))
|
551 | a8083063 | Iustin Pop | bad = True
|
552 | a8083063 | Iustin Pop | |
553 | 2eb78bc8 | Guido Trotter | if not node_result: |
554 | 2eb78bc8 | Guido Trotter | feedback_fn(" - ERROR: unable to verify node %s." % (node,))
|
555 | 2eb78bc8 | Guido Trotter | return True |
556 | 2eb78bc8 | Guido Trotter | |
557 | a8083063 | Iustin Pop | # checks config file checksum
|
558 | a8083063 | Iustin Pop | # checks ssh to any
|
559 | a8083063 | Iustin Pop | |
560 | a8083063 | Iustin Pop | if 'filelist' not in node_result: |
561 | a8083063 | Iustin Pop | bad = True
|
562 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: node hasn't returned file checksum data")
|
563 | a8083063 | Iustin Pop | else:
|
564 | a8083063 | Iustin Pop | remote_cksum = node_result['filelist']
|
565 | a8083063 | Iustin Pop | for file_name in file_list: |
566 | a8083063 | Iustin Pop | if file_name not in remote_cksum: |
567 | a8083063 | Iustin Pop | bad = True
|
568 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: file '%s' missing" % file_name)
|
569 | a8083063 | Iustin Pop | elif remote_cksum[file_name] != local_cksum[file_name]:
|
570 | a8083063 | Iustin Pop | bad = True
|
571 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: file '%s' has wrong checksum" % file_name)
|
572 | a8083063 | Iustin Pop | |
573 | a8083063 | Iustin Pop | if 'nodelist' not in node_result: |
574 | a8083063 | Iustin Pop | bad = True
|
575 | 9d4bfc96 | Iustin Pop | feedback_fn(" - ERROR: node hasn't returned node ssh connectivity data")
|
576 | a8083063 | Iustin Pop | else:
|
577 | a8083063 | Iustin Pop | if node_result['nodelist']: |
578 | a8083063 | Iustin Pop | bad = True
|
579 | a8083063 | Iustin Pop | for node in node_result['nodelist']: |
580 | 9d4bfc96 | Iustin Pop | feedback_fn(" - ERROR: ssh communication with node '%s': %s" %
|
581 | a8083063 | Iustin Pop | (node, node_result['nodelist'][node]))
|
582 | 9d4bfc96 | Iustin Pop | if 'node-net-test' not in node_result: |
583 | 9d4bfc96 | Iustin Pop | bad = True
|
584 | 9d4bfc96 | Iustin Pop | feedback_fn(" - ERROR: node hasn't returned node tcp connectivity data")
|
585 | 9d4bfc96 | Iustin Pop | else:
|
586 | 9d4bfc96 | Iustin Pop | if node_result['node-net-test']: |
587 | 9d4bfc96 | Iustin Pop | bad = True
|
588 | 9d4bfc96 | Iustin Pop | nlist = utils.NiceSort(node_result['node-net-test'].keys())
|
589 | 9d4bfc96 | Iustin Pop | for node in nlist: |
590 | 9d4bfc96 | Iustin Pop | feedback_fn(" - ERROR: tcp communication with node '%s': %s" %
|
591 | 9d4bfc96 | Iustin Pop | (node, node_result['node-net-test'][node]))
|
592 | 9d4bfc96 | Iustin Pop | |
593 | a8083063 | Iustin Pop | hyp_result = node_result.get('hypervisor', None) |
594 | e69d05fd | Iustin Pop | if isinstance(hyp_result, dict): |
595 | e69d05fd | Iustin Pop | for hv_name, hv_result in hyp_result.iteritems(): |
596 | e69d05fd | Iustin Pop | if hv_result is not None: |
597 | e69d05fd | Iustin Pop | feedback_fn(" - ERROR: hypervisor %s verify failure: '%s'" %
|
598 | e69d05fd | Iustin Pop | (hv_name, hv_result)) |
599 | a8083063 | Iustin Pop | return bad
|
600 | a8083063 | Iustin Pop | |
601 | c5705f58 | Guido Trotter | def _VerifyInstance(self, instance, instanceconfig, node_vol_is, |
602 | c5705f58 | Guido Trotter | node_instance, feedback_fn): |
603 | a8083063 | Iustin Pop | """Verify an instance.
|
604 | a8083063 | Iustin Pop |
|
605 | a8083063 | Iustin Pop | This function checks to see if the required block devices are
|
606 | a8083063 | Iustin Pop | available on the instance's node.
|
607 | a8083063 | Iustin Pop |
|
608 | a8083063 | Iustin Pop | """
|
609 | a8083063 | Iustin Pop | bad = False
|
610 | a8083063 | Iustin Pop | |
611 | a8083063 | Iustin Pop | node_current = instanceconfig.primary_node |
612 | a8083063 | Iustin Pop | |
613 | a8083063 | Iustin Pop | node_vol_should = {} |
614 | a8083063 | Iustin Pop | instanceconfig.MapLVsByNode(node_vol_should) |
615 | a8083063 | Iustin Pop | |
616 | a8083063 | Iustin Pop | for node in node_vol_should: |
617 | a8083063 | Iustin Pop | for volume in node_vol_should[node]: |
618 | a8083063 | Iustin Pop | if node not in node_vol_is or volume not in node_vol_is[node]: |
619 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: volume %s missing on node %s" %
|
620 | a8083063 | Iustin Pop | (volume, node)) |
621 | a8083063 | Iustin Pop | bad = True
|
622 | a8083063 | Iustin Pop | |
623 | a8083063 | Iustin Pop | if not instanceconfig.status == 'down': |
624 | a872dae6 | Guido Trotter | if (node_current not in node_instance or |
625 | a872dae6 | Guido Trotter | not instance in node_instance[node_current]): |
626 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: instance %s not running on node %s" %
|
627 | a8083063 | Iustin Pop | (instance, node_current)) |
628 | a8083063 | Iustin Pop | bad = True
|
629 | a8083063 | Iustin Pop | |
630 | a8083063 | Iustin Pop | for node in node_instance: |
631 | a8083063 | Iustin Pop | if (not node == node_current): |
632 | a8083063 | Iustin Pop | if instance in node_instance[node]: |
633 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: instance %s should not run on node %s" %
|
634 | a8083063 | Iustin Pop | (instance, node)) |
635 | a8083063 | Iustin Pop | bad = True
|
636 | a8083063 | Iustin Pop | |
637 | 6a438c98 | Michael Hanselmann | return bad
|
638 | a8083063 | Iustin Pop | |
639 | a8083063 | Iustin Pop | def _VerifyOrphanVolumes(self, node_vol_should, node_vol_is, feedback_fn): |
640 | a8083063 | Iustin Pop | """Verify if there are any unknown volumes in the cluster.
|
641 | a8083063 | Iustin Pop |
|
642 | a8083063 | Iustin Pop | The .os, .swap and backup volumes are ignored. All other volumes are
|
643 | a8083063 | Iustin Pop | reported as unknown.
|
644 | a8083063 | Iustin Pop |
|
645 | a8083063 | Iustin Pop | """
|
646 | a8083063 | Iustin Pop | bad = False
|
647 | a8083063 | Iustin Pop | |
648 | a8083063 | Iustin Pop | for node in node_vol_is: |
649 | a8083063 | Iustin Pop | for volume in node_vol_is[node]: |
650 | a8083063 | Iustin Pop | if node not in node_vol_should or volume not in node_vol_should[node]: |
651 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: volume %s on node %s should not exist" %
|
652 | a8083063 | Iustin Pop | (volume, node)) |
653 | a8083063 | Iustin Pop | bad = True
|
654 | a8083063 | Iustin Pop | return bad
|
655 | a8083063 | Iustin Pop | |
656 | a8083063 | Iustin Pop | def _VerifyOrphanInstances(self, instancelist, node_instance, feedback_fn): |
657 | a8083063 | Iustin Pop | """Verify the list of running instances.
|
658 | a8083063 | Iustin Pop |
|
659 | a8083063 | Iustin Pop | This checks what instances are running but unknown to the cluster.
|
660 | a8083063 | Iustin Pop |
|
661 | a8083063 | Iustin Pop | """
|
662 | a8083063 | Iustin Pop | bad = False
|
663 | a8083063 | Iustin Pop | for node in node_instance: |
664 | a8083063 | Iustin Pop | for runninginstance in node_instance[node]: |
665 | a8083063 | Iustin Pop | if runninginstance not in instancelist: |
666 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: instance %s on node %s should not exist" %
|
667 | a8083063 | Iustin Pop | (runninginstance, node)) |
668 | a8083063 | Iustin Pop | bad = True
|
669 | a8083063 | Iustin Pop | return bad
|
670 | a8083063 | Iustin Pop | |
671 | 2b3b6ddd | Guido Trotter | def _VerifyNPlusOneMemory(self, node_info, instance_cfg, feedback_fn): |
672 | 2b3b6ddd | Guido Trotter | """Verify N+1 Memory Resilience.
|
673 | 2b3b6ddd | Guido Trotter |
|
674 | 2b3b6ddd | Guido Trotter | Check that if one single node dies we can still start all the instances it
|
675 | 2b3b6ddd | Guido Trotter | was primary for.
|
676 | 2b3b6ddd | Guido Trotter |
|
677 | 2b3b6ddd | Guido Trotter | """
|
678 | 2b3b6ddd | Guido Trotter | bad = False
|
679 | 2b3b6ddd | Guido Trotter | |
680 | 2b3b6ddd | Guido Trotter | for node, nodeinfo in node_info.iteritems(): |
681 | 2b3b6ddd | Guido Trotter | # This code checks that every node which is now listed as secondary has
|
682 | 2b3b6ddd | Guido Trotter | # enough memory to host all instances it is supposed to should a single
|
683 | 2b3b6ddd | Guido Trotter | # other node in the cluster fail.
|
684 | 2b3b6ddd | Guido Trotter | # FIXME: not ready for failover to an arbitrary node
|
685 | 2b3b6ddd | Guido Trotter | # FIXME: does not support file-backed instances
|
686 | 2b3b6ddd | Guido Trotter | # WARNING: we currently take into account down instances as well as up
|
687 | 2b3b6ddd | Guido Trotter | # ones, considering that even if they're down someone might want to start
|
688 | 2b3b6ddd | Guido Trotter | # them even in the event of a node failure.
|
689 | 2b3b6ddd | Guido Trotter | for prinode, instances in nodeinfo['sinst-by-pnode'].iteritems(): |
690 | 2b3b6ddd | Guido Trotter | needed_mem = 0
|
691 | 2b3b6ddd | Guido Trotter | for instance in instances: |
692 | 2b3b6ddd | Guido Trotter | needed_mem += instance_cfg[instance].memory |
693 | 2b3b6ddd | Guido Trotter | if nodeinfo['mfree'] < needed_mem: |
694 | 2b3b6ddd | Guido Trotter | feedback_fn(" - ERROR: not enough memory on node %s to accomodate"
|
695 | 2b3b6ddd | Guido Trotter | " failovers should node %s fail" % (node, prinode))
|
696 | 2b3b6ddd | Guido Trotter | bad = True
|
697 | 2b3b6ddd | Guido Trotter | return bad
|
698 | 2b3b6ddd | Guido Trotter | |
699 | a8083063 | Iustin Pop | def CheckPrereq(self): |
700 | a8083063 | Iustin Pop | """Check prerequisites.
|
701 | a8083063 | Iustin Pop |
|
702 | e54c4c5e | Guido Trotter | Transform the list of checks we're going to skip into a set and check that
|
703 | e54c4c5e | Guido Trotter | all its members are valid.
|
704 | a8083063 | Iustin Pop |
|
705 | a8083063 | Iustin Pop | """
|
706 | e54c4c5e | Guido Trotter | self.skip_set = frozenset(self.op.skip_checks) |
707 | e54c4c5e | Guido Trotter | if not constants.VERIFY_OPTIONAL_CHECKS.issuperset(self.skip_set): |
708 | e54c4c5e | Guido Trotter | raise errors.OpPrereqError("Invalid checks to be skipped specified") |
709 | a8083063 | Iustin Pop | |
710 | d8fff41c | Guido Trotter | def BuildHooksEnv(self): |
711 | d8fff41c | Guido Trotter | """Build hooks env.
|
712 | d8fff41c | Guido Trotter |
|
713 | d8fff41c | Guido Trotter | Cluster-Verify hooks just rone in the post phase and their failure makes
|
714 | d8fff41c | Guido Trotter | the output be logged in the verify output and the verification to fail.
|
715 | d8fff41c | Guido Trotter |
|
716 | d8fff41c | Guido Trotter | """
|
717 | d8fff41c | Guido Trotter | all_nodes = self.cfg.GetNodeList()
|
718 | d8fff41c | Guido Trotter | # TODO: populate the environment with useful information for verify hooks
|
719 | d8fff41c | Guido Trotter | env = {} |
720 | d8fff41c | Guido Trotter | return env, [], all_nodes
|
721 | d8fff41c | Guido Trotter | |
722 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
723 | a8083063 | Iustin Pop | """Verify integrity of cluster, performing various test on nodes.
|
724 | a8083063 | Iustin Pop |
|
725 | a8083063 | Iustin Pop | """
|
726 | a8083063 | Iustin Pop | bad = False
|
727 | a8083063 | Iustin Pop | feedback_fn("* Verifying global settings")
|
728 | 8522ceeb | Iustin Pop | for msg in self.cfg.VerifyConfig(): |
729 | 8522ceeb | Iustin Pop | feedback_fn(" - ERROR: %s" % msg)
|
730 | a8083063 | Iustin Pop | |
731 | a8083063 | Iustin Pop | vg_name = self.cfg.GetVGName()
|
732 | e69d05fd | Iustin Pop | hypervisors = self.cfg.GetClusterInfo().enabled_hypervisors
|
733 | a8083063 | Iustin Pop | nodelist = utils.NiceSort(self.cfg.GetNodeList())
|
734 | 9d4bfc96 | Iustin Pop | nodeinfo = [self.cfg.GetNodeInfo(nname) for nname in nodelist] |
735 | a8083063 | Iustin Pop | instancelist = utils.NiceSort(self.cfg.GetInstanceList())
|
736 | 93e4c50b | Guido Trotter | i_non_redundant = [] # Non redundant instances
|
737 | a8083063 | Iustin Pop | node_volume = {} |
738 | a8083063 | Iustin Pop | node_instance = {} |
739 | 9c9c7d30 | Guido Trotter | node_info = {} |
740 | 26b6af5e | Guido Trotter | instance_cfg = {} |
741 | a8083063 | Iustin Pop | |
742 | a8083063 | Iustin Pop | # FIXME: verify OS list
|
743 | a8083063 | Iustin Pop | # do local checksums
|
744 | d6a02168 | Michael Hanselmann | file_names = [] |
745 | cb91d46e | Iustin Pop | file_names.append(constants.SSL_CERT_FILE) |
746 | cb91d46e | Iustin Pop | file_names.append(constants.CLUSTER_CONF_FILE) |
747 | a8083063 | Iustin Pop | local_checksums = utils.FingerprintFiles(file_names) |
748 | a8083063 | Iustin Pop | |
749 | a8083063 | Iustin Pop | feedback_fn("* Gathering data (%d nodes)" % len(nodelist)) |
750 | 72737a7f | Iustin Pop | all_volumeinfo = self.rpc.call_volume_list(nodelist, vg_name)
|
751 | 72737a7f | Iustin Pop | all_instanceinfo = self.rpc.call_instance_list(nodelist, hypervisors)
|
752 | 72737a7f | Iustin Pop | all_vglist = self.rpc.call_vg_list(nodelist)
|
753 | a8083063 | Iustin Pop | node_verify_param = { |
754 | a8083063 | Iustin Pop | 'filelist': file_names,
|
755 | a8083063 | Iustin Pop | 'nodelist': nodelist,
|
756 | e69d05fd | Iustin Pop | 'hypervisor': hypervisors,
|
757 | 9d4bfc96 | Iustin Pop | 'node-net-test': [(node.name, node.primary_ip, node.secondary_ip)
|
758 | 9d4bfc96 | Iustin Pop | for node in nodeinfo] |
759 | a8083063 | Iustin Pop | } |
760 | 72737a7f | Iustin Pop | all_nvinfo = self.rpc.call_node_verify(nodelist, node_verify_param,
|
761 | 72737a7f | Iustin Pop | self.cfg.GetClusterName())
|
762 | 72737a7f | Iustin Pop | all_rversion = self.rpc.call_version(nodelist)
|
763 | 72737a7f | Iustin Pop | all_ninfo = self.rpc.call_node_info(nodelist, self.cfg.GetVGName(), |
764 | 72737a7f | Iustin Pop | self.cfg.GetHypervisorType())
|
765 | a8083063 | Iustin Pop | |
766 | a8083063 | Iustin Pop | for node in nodelist: |
767 | a8083063 | Iustin Pop | feedback_fn("* Verifying node %s" % node)
|
768 | a8083063 | Iustin Pop | result = self._VerifyNode(node, file_names, local_checksums,
|
769 | a8083063 | Iustin Pop | all_vglist[node], all_nvinfo[node], |
770 | a8083063 | Iustin Pop | all_rversion[node], feedback_fn) |
771 | a8083063 | Iustin Pop | bad = bad or result
|
772 | a8083063 | Iustin Pop | |
773 | a8083063 | Iustin Pop | # node_volume
|
774 | a8083063 | Iustin Pop | volumeinfo = all_volumeinfo[node] |
775 | a8083063 | Iustin Pop | |
776 | b63ed789 | Iustin Pop | if isinstance(volumeinfo, basestring): |
777 | b63ed789 | Iustin Pop | feedback_fn(" - ERROR: LVM problem on node %s: %s" %
|
778 | b63ed789 | Iustin Pop | (node, volumeinfo[-400:].encode('string_escape'))) |
779 | b63ed789 | Iustin Pop | bad = True
|
780 | b63ed789 | Iustin Pop | node_volume[node] = {} |
781 | b63ed789 | Iustin Pop | elif not isinstance(volumeinfo, dict): |
782 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: connection to %s failed" % (node,))
|
783 | a8083063 | Iustin Pop | bad = True
|
784 | a8083063 | Iustin Pop | continue
|
785 | b63ed789 | Iustin Pop | else:
|
786 | b63ed789 | Iustin Pop | node_volume[node] = volumeinfo |
787 | a8083063 | Iustin Pop | |
788 | a8083063 | Iustin Pop | # node_instance
|
789 | a8083063 | Iustin Pop | nodeinstance = all_instanceinfo[node] |
790 | a8083063 | Iustin Pop | if type(nodeinstance) != list: |
791 | a8083063 | Iustin Pop | feedback_fn(" - ERROR: connection to %s failed" % (node,))
|
792 | a8083063 | Iustin Pop | bad = True
|
793 | a8083063 | Iustin Pop | continue
|
794 | a8083063 | Iustin Pop | |
795 | a8083063 | Iustin Pop | node_instance[node] = nodeinstance |
796 | a8083063 | Iustin Pop | |
797 | 9c9c7d30 | Guido Trotter | # node_info
|
798 | 9c9c7d30 | Guido Trotter | nodeinfo = all_ninfo[node] |
799 | 9c9c7d30 | Guido Trotter | if not isinstance(nodeinfo, dict): |
800 | 9c9c7d30 | Guido Trotter | feedback_fn(" - ERROR: connection to %s failed" % (node,))
|
801 | 9c9c7d30 | Guido Trotter | bad = True
|
802 | 9c9c7d30 | Guido Trotter | continue
|
803 | 9c9c7d30 | Guido Trotter | |
804 | 9c9c7d30 | Guido Trotter | try:
|
805 | 9c9c7d30 | Guido Trotter | node_info[node] = { |
806 | 9c9c7d30 | Guido Trotter | "mfree": int(nodeinfo['memory_free']), |
807 | 9c9c7d30 | Guido Trotter | "dfree": int(nodeinfo['vg_free']), |
808 | 93e4c50b | Guido Trotter | "pinst": [],
|
809 | 93e4c50b | Guido Trotter | "sinst": [],
|
810 | 36e7da50 | Guido Trotter | # dictionary holding all instances this node is secondary for,
|
811 | 36e7da50 | Guido Trotter | # grouped by their primary node. Each key is a cluster node, and each
|
812 | 36e7da50 | Guido Trotter | # value is a list of instances which have the key as primary and the
|
813 | 36e7da50 | Guido Trotter | # current node as secondary. this is handy to calculate N+1 memory
|
814 | 36e7da50 | Guido Trotter | # availability if you can only failover from a primary to its
|
815 | 36e7da50 | Guido Trotter | # secondary.
|
816 | 36e7da50 | Guido Trotter | "sinst-by-pnode": {},
|
817 | 9c9c7d30 | Guido Trotter | } |
818 | 9c9c7d30 | Guido Trotter | except ValueError: |
819 | 9c9c7d30 | Guido Trotter | feedback_fn(" - ERROR: invalid value returned from node %s" % (node,))
|
820 | 9c9c7d30 | Guido Trotter | bad = True
|
821 | 9c9c7d30 | Guido Trotter | continue
|
822 | 9c9c7d30 | Guido Trotter | |
823 | a8083063 | Iustin Pop | node_vol_should = {} |
824 | a8083063 | Iustin Pop | |
825 | a8083063 | Iustin Pop | for instance in instancelist: |
826 | a8083063 | Iustin Pop | feedback_fn("* Verifying instance %s" % instance)
|
827 | a8083063 | Iustin Pop | inst_config = self.cfg.GetInstanceInfo(instance)
|
828 | c5705f58 | Guido Trotter | result = self._VerifyInstance(instance, inst_config, node_volume,
|
829 | c5705f58 | Guido Trotter | node_instance, feedback_fn) |
830 | c5705f58 | Guido Trotter | bad = bad or result
|
831 | a8083063 | Iustin Pop | |
832 | a8083063 | Iustin Pop | inst_config.MapLVsByNode(node_vol_should) |
833 | a8083063 | Iustin Pop | |
834 | 26b6af5e | Guido Trotter | instance_cfg[instance] = inst_config |
835 | 26b6af5e | Guido Trotter | |
836 | 93e4c50b | Guido Trotter | pnode = inst_config.primary_node |
837 | 93e4c50b | Guido Trotter | if pnode in node_info: |
838 | 93e4c50b | Guido Trotter | node_info[pnode]['pinst'].append(instance)
|
839 | 93e4c50b | Guido Trotter | else:
|
840 | 93e4c50b | Guido Trotter | feedback_fn(" - ERROR: instance %s, connection to primary node"
|
841 | 93e4c50b | Guido Trotter | " %s failed" % (instance, pnode))
|
842 | 93e4c50b | Guido Trotter | bad = True
|
843 | 93e4c50b | Guido Trotter | |
844 | 93e4c50b | Guido Trotter | # If the instance is non-redundant we cannot survive losing its primary
|
845 | 93e4c50b | Guido Trotter | # node, so we are not N+1 compliant. On the other hand we have no disk
|
846 | 93e4c50b | Guido Trotter | # templates with more than one secondary so that situation is not well
|
847 | 93e4c50b | Guido Trotter | # supported either.
|
848 | 93e4c50b | Guido Trotter | # FIXME: does not support file-backed instances
|
849 | 93e4c50b | Guido Trotter | if len(inst_config.secondary_nodes) == 0: |
850 | 93e4c50b | Guido Trotter | i_non_redundant.append(instance) |
851 | 93e4c50b | Guido Trotter | elif len(inst_config.secondary_nodes) > 1: |
852 | 93e4c50b | Guido Trotter | feedback_fn(" - WARNING: multiple secondaries for instance %s"
|
853 | 93e4c50b | Guido Trotter | % instance) |
854 | 93e4c50b | Guido Trotter | |
855 | 93e4c50b | Guido Trotter | for snode in inst_config.secondary_nodes: |
856 | 93e4c50b | Guido Trotter | if snode in node_info: |
857 | 93e4c50b | Guido Trotter | node_info[snode]['sinst'].append(instance)
|
858 | 36e7da50 | Guido Trotter | if pnode not in node_info[snode]['sinst-by-pnode']: |
859 | 36e7da50 | Guido Trotter | node_info[snode]['sinst-by-pnode'][pnode] = []
|
860 | 36e7da50 | Guido Trotter | node_info[snode]['sinst-by-pnode'][pnode].append(instance)
|
861 | 93e4c50b | Guido Trotter | else:
|
862 | 93e4c50b | Guido Trotter | feedback_fn(" - ERROR: instance %s, connection to secondary node"
|
863 | 93e4c50b | Guido Trotter | " %s failed" % (instance, snode))
|
864 | 93e4c50b | Guido Trotter | |
865 | a8083063 | Iustin Pop | feedback_fn("* Verifying orphan volumes")
|
866 | a8083063 | Iustin Pop | result = self._VerifyOrphanVolumes(node_vol_should, node_volume,
|
867 | a8083063 | Iustin Pop | feedback_fn) |
868 | a8083063 | Iustin Pop | bad = bad or result
|
869 | a8083063 | Iustin Pop | |
870 | a8083063 | Iustin Pop | feedback_fn("* Verifying remaining instances")
|
871 | a8083063 | Iustin Pop | result = self._VerifyOrphanInstances(instancelist, node_instance,
|
872 | a8083063 | Iustin Pop | feedback_fn) |
873 | a8083063 | Iustin Pop | bad = bad or result
|
874 | a8083063 | Iustin Pop | |
875 | e54c4c5e | Guido Trotter | if constants.VERIFY_NPLUSONE_MEM not in self.skip_set: |
876 | e54c4c5e | Guido Trotter | feedback_fn("* Verifying N+1 Memory redundancy")
|
877 | e54c4c5e | Guido Trotter | result = self._VerifyNPlusOneMemory(node_info, instance_cfg, feedback_fn)
|
878 | e54c4c5e | Guido Trotter | bad = bad or result
|
879 | 2b3b6ddd | Guido Trotter | |
880 | 2b3b6ddd | Guido Trotter | feedback_fn("* Other Notes")
|
881 | 2b3b6ddd | Guido Trotter | if i_non_redundant:
|
882 | 2b3b6ddd | Guido Trotter | feedback_fn(" - NOTICE: %d non-redundant instance(s) found."
|
883 | 2b3b6ddd | Guido Trotter | % len(i_non_redundant))
|
884 | 2b3b6ddd | Guido Trotter | |
885 | 34290825 | Michael Hanselmann | return not bad |
886 | a8083063 | Iustin Pop | |
887 | d8fff41c | Guido Trotter | def HooksCallBack(self, phase, hooks_results, feedback_fn, lu_result): |
888 | d8fff41c | Guido Trotter | """Analize the post-hooks' result, handle it, and send some
|
889 | d8fff41c | Guido Trotter | nicely-formatted feedback back to the user.
|
890 | d8fff41c | Guido Trotter |
|
891 | d8fff41c | Guido Trotter | Args:
|
892 | d8fff41c | Guido Trotter | phase: the hooks phase that has just been run
|
893 | d8fff41c | Guido Trotter | hooks_results: the results of the multi-node hooks rpc call
|
894 | d8fff41c | Guido Trotter | feedback_fn: function to send feedback back to the caller
|
895 | d8fff41c | Guido Trotter | lu_result: previous Exec result
|
896 | d8fff41c | Guido Trotter |
|
897 | d8fff41c | Guido Trotter | """
|
898 | 38206f3c | Iustin Pop | # We only really run POST phase hooks, and are only interested in
|
899 | 38206f3c | Iustin Pop | # their results
|
900 | d8fff41c | Guido Trotter | if phase == constants.HOOKS_PHASE_POST:
|
901 | d8fff41c | Guido Trotter | # Used to change hooks' output to proper indentation
|
902 | d8fff41c | Guido Trotter | indent_re = re.compile('^', re.M)
|
903 | d8fff41c | Guido Trotter | feedback_fn("* Hooks Results")
|
904 | d8fff41c | Guido Trotter | if not hooks_results: |
905 | d8fff41c | Guido Trotter | feedback_fn(" - ERROR: general communication failure")
|
906 | d8fff41c | Guido Trotter | lu_result = 1
|
907 | d8fff41c | Guido Trotter | else:
|
908 | d8fff41c | Guido Trotter | for node_name in hooks_results: |
909 | d8fff41c | Guido Trotter | show_node_header = True
|
910 | d8fff41c | Guido Trotter | res = hooks_results[node_name] |
911 | d8fff41c | Guido Trotter | if res is False or not isinstance(res, list): |
912 | d8fff41c | Guido Trotter | feedback_fn(" Communication failure")
|
913 | d8fff41c | Guido Trotter | lu_result = 1
|
914 | d8fff41c | Guido Trotter | continue
|
915 | d8fff41c | Guido Trotter | for script, hkr, output in res: |
916 | d8fff41c | Guido Trotter | if hkr == constants.HKR_FAIL:
|
917 | d8fff41c | Guido Trotter | # The node header is only shown once, if there are
|
918 | d8fff41c | Guido Trotter | # failing hooks on that node
|
919 | d8fff41c | Guido Trotter | if show_node_header:
|
920 | d8fff41c | Guido Trotter | feedback_fn(" Node %s:" % node_name)
|
921 | d8fff41c | Guido Trotter | show_node_header = False
|
922 | d8fff41c | Guido Trotter | feedback_fn(" ERROR: Script %s failed, output:" % script)
|
923 | d8fff41c | Guido Trotter | output = indent_re.sub(' ', output)
|
924 | d8fff41c | Guido Trotter | feedback_fn("%s" % output)
|
925 | d8fff41c | Guido Trotter | lu_result = 1
|
926 | d8fff41c | Guido Trotter | |
927 | d8fff41c | Guido Trotter | return lu_result
|
928 | d8fff41c | Guido Trotter | |
929 | a8083063 | Iustin Pop | |
930 | 2c95a8d4 | Iustin Pop | class LUVerifyDisks(NoHooksLU): |
931 | 2c95a8d4 | Iustin Pop | """Verifies the cluster disks status.
|
932 | 2c95a8d4 | Iustin Pop |
|
933 | 2c95a8d4 | Iustin Pop | """
|
934 | 2c95a8d4 | Iustin Pop | _OP_REQP = [] |
935 | d4b9d97f | Guido Trotter | REQ_BGL = False
|
936 | d4b9d97f | Guido Trotter | |
937 | d4b9d97f | Guido Trotter | def ExpandNames(self): |
938 | d4b9d97f | Guido Trotter | self.needed_locks = {
|
939 | d4b9d97f | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET, |
940 | d4b9d97f | Guido Trotter | locking.LEVEL_INSTANCE: locking.ALL_SET, |
941 | d4b9d97f | Guido Trotter | } |
942 | d4b9d97f | Guido Trotter | self.share_locks = dict(((i, 1) for i in locking.LEVELS)) |
943 | 2c95a8d4 | Iustin Pop | |
944 | 2c95a8d4 | Iustin Pop | def CheckPrereq(self): |
945 | 2c95a8d4 | Iustin Pop | """Check prerequisites.
|
946 | 2c95a8d4 | Iustin Pop |
|
947 | 2c95a8d4 | Iustin Pop | This has no prerequisites.
|
948 | 2c95a8d4 | Iustin Pop |
|
949 | 2c95a8d4 | Iustin Pop | """
|
950 | 2c95a8d4 | Iustin Pop | pass
|
951 | 2c95a8d4 | Iustin Pop | |
952 | 2c95a8d4 | Iustin Pop | def Exec(self, feedback_fn): |
953 | 2c95a8d4 | Iustin Pop | """Verify integrity of cluster disks.
|
954 | 2c95a8d4 | Iustin Pop |
|
955 | 2c95a8d4 | Iustin Pop | """
|
956 | b63ed789 | Iustin Pop | result = res_nodes, res_nlvm, res_instances, res_missing = [], {}, [], {} |
957 | 2c95a8d4 | Iustin Pop | |
958 | 2c95a8d4 | Iustin Pop | vg_name = self.cfg.GetVGName()
|
959 | 2c95a8d4 | Iustin Pop | nodes = utils.NiceSort(self.cfg.GetNodeList())
|
960 | 2c95a8d4 | Iustin Pop | instances = [self.cfg.GetInstanceInfo(name)
|
961 | 2c95a8d4 | Iustin Pop | for name in self.cfg.GetInstanceList()] |
962 | 2c95a8d4 | Iustin Pop | |
963 | 2c95a8d4 | Iustin Pop | nv_dict = {} |
964 | 2c95a8d4 | Iustin Pop | for inst in instances: |
965 | 2c95a8d4 | Iustin Pop | inst_lvs = {} |
966 | 2c95a8d4 | Iustin Pop | if (inst.status != "up" or |
967 | 2c95a8d4 | Iustin Pop | inst.disk_template not in constants.DTS_NET_MIRROR): |
968 | 2c95a8d4 | Iustin Pop | continue
|
969 | 2c95a8d4 | Iustin Pop | inst.MapLVsByNode(inst_lvs) |
970 | 2c95a8d4 | Iustin Pop | # transform { iname: {node: [vol,],},} to {(node, vol): iname}
|
971 | 2c95a8d4 | Iustin Pop | for node, vol_list in inst_lvs.iteritems(): |
972 | 2c95a8d4 | Iustin Pop | for vol in vol_list: |
973 | 2c95a8d4 | Iustin Pop | nv_dict[(node, vol)] = inst |
974 | 2c95a8d4 | Iustin Pop | |
975 | 2c95a8d4 | Iustin Pop | if not nv_dict: |
976 | 2c95a8d4 | Iustin Pop | return result
|
977 | 2c95a8d4 | Iustin Pop | |
978 | 72737a7f | Iustin Pop | node_lvs = self.rpc.call_volume_list(nodes, vg_name)
|
979 | 2c95a8d4 | Iustin Pop | |
980 | 2c95a8d4 | Iustin Pop | to_act = set()
|
981 | 2c95a8d4 | Iustin Pop | for node in nodes: |
982 | 2c95a8d4 | Iustin Pop | # node_volume
|
983 | 2c95a8d4 | Iustin Pop | lvs = node_lvs[node] |
984 | 2c95a8d4 | Iustin Pop | |
985 | b63ed789 | Iustin Pop | if isinstance(lvs, basestring): |
986 | b63ed789 | Iustin Pop | logger.Info("error enumerating LVs on node %s: %s" % (node, lvs))
|
987 | b63ed789 | Iustin Pop | res_nlvm[node] = lvs |
988 | b63ed789 | Iustin Pop | elif not isinstance(lvs, dict): |
989 | 2c95a8d4 | Iustin Pop | logger.Info("connection to node %s failed or invalid data returned" %
|
990 | 2c95a8d4 | Iustin Pop | (node,)) |
991 | 2c95a8d4 | Iustin Pop | res_nodes.append(node) |
992 | 2c95a8d4 | Iustin Pop | continue
|
993 | 2c95a8d4 | Iustin Pop | |
994 | 2c95a8d4 | Iustin Pop | for lv_name, (_, lv_inactive, lv_online) in lvs.iteritems(): |
995 | b63ed789 | Iustin Pop | inst = nv_dict.pop((node, lv_name), None)
|
996 | b63ed789 | Iustin Pop | if (not lv_online and inst is not None |
997 | b63ed789 | Iustin Pop | and inst.name not in res_instances): |
998 | b08d5a87 | Iustin Pop | res_instances.append(inst.name) |
999 | 2c95a8d4 | Iustin Pop | |
1000 | b63ed789 | Iustin Pop | # any leftover items in nv_dict are missing LVs, let's arrange the
|
1001 | b63ed789 | Iustin Pop | # data better
|
1002 | b63ed789 | Iustin Pop | for key, inst in nv_dict.iteritems(): |
1003 | b63ed789 | Iustin Pop | if inst.name not in res_missing: |
1004 | b63ed789 | Iustin Pop | res_missing[inst.name] = [] |
1005 | b63ed789 | Iustin Pop | res_missing[inst.name].append(key) |
1006 | b63ed789 | Iustin Pop | |
1007 | 2c95a8d4 | Iustin Pop | return result
|
1008 | 2c95a8d4 | Iustin Pop | |
1009 | 2c95a8d4 | Iustin Pop | |
1010 | 07bd8a51 | Iustin Pop | class LURenameCluster(LogicalUnit): |
1011 | 07bd8a51 | Iustin Pop | """Rename the cluster.
|
1012 | 07bd8a51 | Iustin Pop |
|
1013 | 07bd8a51 | Iustin Pop | """
|
1014 | 07bd8a51 | Iustin Pop | HPATH = "cluster-rename"
|
1015 | 07bd8a51 | Iustin Pop | HTYPE = constants.HTYPE_CLUSTER |
1016 | 07bd8a51 | Iustin Pop | _OP_REQP = ["name"]
|
1017 | 07bd8a51 | Iustin Pop | |
1018 | 07bd8a51 | Iustin Pop | def BuildHooksEnv(self): |
1019 | 07bd8a51 | Iustin Pop | """Build hooks env.
|
1020 | 07bd8a51 | Iustin Pop |
|
1021 | 07bd8a51 | Iustin Pop | """
|
1022 | 07bd8a51 | Iustin Pop | env = { |
1023 | d6a02168 | Michael Hanselmann | "OP_TARGET": self.cfg.GetClusterName(), |
1024 | 07bd8a51 | Iustin Pop | "NEW_NAME": self.op.name, |
1025 | 07bd8a51 | Iustin Pop | } |
1026 | d6a02168 | Michael Hanselmann | mn = self.cfg.GetMasterNode()
|
1027 | 07bd8a51 | Iustin Pop | return env, [mn], [mn]
|
1028 | 07bd8a51 | Iustin Pop | |
1029 | 07bd8a51 | Iustin Pop | def CheckPrereq(self): |
1030 | 07bd8a51 | Iustin Pop | """Verify that the passed name is a valid one.
|
1031 | 07bd8a51 | Iustin Pop |
|
1032 | 07bd8a51 | Iustin Pop | """
|
1033 | 89e1fc26 | Iustin Pop | hostname = utils.HostInfo(self.op.name)
|
1034 | 07bd8a51 | Iustin Pop | |
1035 | bcf043c9 | Iustin Pop | new_name = hostname.name |
1036 | bcf043c9 | Iustin Pop | self.ip = new_ip = hostname.ip
|
1037 | d6a02168 | Michael Hanselmann | old_name = self.cfg.GetClusterName()
|
1038 | d6a02168 | Michael Hanselmann | old_ip = self.cfg.GetMasterIP()
|
1039 | 07bd8a51 | Iustin Pop | if new_name == old_name and new_ip == old_ip: |
1040 | 07bd8a51 | Iustin Pop | raise errors.OpPrereqError("Neither the name nor the IP address of the" |
1041 | 07bd8a51 | Iustin Pop | " cluster has changed")
|
1042 | 07bd8a51 | Iustin Pop | if new_ip != old_ip:
|
1043 | 937f983d | Guido Trotter | if utils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
|
1044 | 07bd8a51 | Iustin Pop | raise errors.OpPrereqError("The given cluster IP address (%s) is" |
1045 | 07bd8a51 | Iustin Pop | " reachable on the network. Aborting." %
|
1046 | 07bd8a51 | Iustin Pop | new_ip) |
1047 | 07bd8a51 | Iustin Pop | |
1048 | 07bd8a51 | Iustin Pop | self.op.name = new_name
|
1049 | 07bd8a51 | Iustin Pop | |
1050 | 07bd8a51 | Iustin Pop | def Exec(self, feedback_fn): |
1051 | 07bd8a51 | Iustin Pop | """Rename the cluster.
|
1052 | 07bd8a51 | Iustin Pop |
|
1053 | 07bd8a51 | Iustin Pop | """
|
1054 | 07bd8a51 | Iustin Pop | clustername = self.op.name
|
1055 | 07bd8a51 | Iustin Pop | ip = self.ip
|
1056 | 07bd8a51 | Iustin Pop | |
1057 | 07bd8a51 | Iustin Pop | # shutdown the master IP
|
1058 | d6a02168 | Michael Hanselmann | master = self.cfg.GetMasterNode()
|
1059 | 72737a7f | Iustin Pop | if not self.rpc.call_node_stop_master(master, False): |
1060 | 07bd8a51 | Iustin Pop | raise errors.OpExecError("Could not disable the master role") |
1061 | 07bd8a51 | Iustin Pop | |
1062 | 07bd8a51 | Iustin Pop | try:
|
1063 | 07bd8a51 | Iustin Pop | # modify the sstore
|
1064 | d6a02168 | Michael Hanselmann | # TODO: sstore
|
1065 | 07bd8a51 | Iustin Pop | ss.SetKey(ss.SS_MASTER_IP, ip) |
1066 | 07bd8a51 | Iustin Pop | ss.SetKey(ss.SS_CLUSTER_NAME, clustername) |
1067 | 07bd8a51 | Iustin Pop | |
1068 | 07bd8a51 | Iustin Pop | # Distribute updated ss config to all nodes
|
1069 | 07bd8a51 | Iustin Pop | myself = self.cfg.GetNodeInfo(master)
|
1070 | 07bd8a51 | Iustin Pop | dist_nodes = self.cfg.GetNodeList()
|
1071 | 07bd8a51 | Iustin Pop | if myself.name in dist_nodes: |
1072 | 07bd8a51 | Iustin Pop | dist_nodes.remove(myself.name) |
1073 | 07bd8a51 | Iustin Pop | |
1074 | 07bd8a51 | Iustin Pop | logger.Debug("Copying updated ssconf data to all nodes")
|
1075 | 07bd8a51 | Iustin Pop | for keyname in [ss.SS_CLUSTER_NAME, ss.SS_MASTER_IP]: |
1076 | 07bd8a51 | Iustin Pop | fname = ss.KeyToFilename(keyname) |
1077 | 72737a7f | Iustin Pop | result = self.rpc.call_upload_file(dist_nodes, fname)
|
1078 | 07bd8a51 | Iustin Pop | for to_node in dist_nodes: |
1079 | 07bd8a51 | Iustin Pop | if not result[to_node]: |
1080 | 07bd8a51 | Iustin Pop | logger.Error("copy of file %s to node %s failed" %
|
1081 | 07bd8a51 | Iustin Pop | (fname, to_node)) |
1082 | 07bd8a51 | Iustin Pop | finally:
|
1083 | 72737a7f | Iustin Pop | if not self.rpc.call_node_start_master(master, False): |
1084 | f4bc1f2c | Michael Hanselmann | logger.Error("Could not re-enable the master role on the master,"
|
1085 | f4bc1f2c | Michael Hanselmann | " please restart manually.")
|
1086 | 07bd8a51 | Iustin Pop | |
1087 | 07bd8a51 | Iustin Pop | |
1088 | 8084f9f6 | Manuel Franceschini | def _RecursiveCheckIfLVMBased(disk): |
1089 | 8084f9f6 | Manuel Franceschini | """Check if the given disk or its children are lvm-based.
|
1090 | 8084f9f6 | Manuel Franceschini |
|
1091 | 8084f9f6 | Manuel Franceschini | Args:
|
1092 | 8084f9f6 | Manuel Franceschini | disk: ganeti.objects.Disk object
|
1093 | 8084f9f6 | Manuel Franceschini |
|
1094 | 8084f9f6 | Manuel Franceschini | Returns:
|
1095 | 8084f9f6 | Manuel Franceschini | boolean indicating whether a LD_LV dev_type was found or not
|
1096 | 8084f9f6 | Manuel Franceschini |
|
1097 | 8084f9f6 | Manuel Franceschini | """
|
1098 | 8084f9f6 | Manuel Franceschini | if disk.children:
|
1099 | 8084f9f6 | Manuel Franceschini | for chdisk in disk.children: |
1100 | 8084f9f6 | Manuel Franceschini | if _RecursiveCheckIfLVMBased(chdisk):
|
1101 | 8084f9f6 | Manuel Franceschini | return True |
1102 | 8084f9f6 | Manuel Franceschini | return disk.dev_type == constants.LD_LV
|
1103 | 8084f9f6 | Manuel Franceschini | |
1104 | 8084f9f6 | Manuel Franceschini | |
1105 | 8084f9f6 | Manuel Franceschini | class LUSetClusterParams(LogicalUnit): |
1106 | 8084f9f6 | Manuel Franceschini | """Change the parameters of the cluster.
|
1107 | 8084f9f6 | Manuel Franceschini |
|
1108 | 8084f9f6 | Manuel Franceschini | """
|
1109 | 8084f9f6 | Manuel Franceschini | HPATH = "cluster-modify"
|
1110 | 8084f9f6 | Manuel Franceschini | HTYPE = constants.HTYPE_CLUSTER |
1111 | 8084f9f6 | Manuel Franceschini | _OP_REQP = [] |
1112 | c53279cf | Guido Trotter | REQ_BGL = False
|
1113 | c53279cf | Guido Trotter | |
1114 | c53279cf | Guido Trotter | def ExpandNames(self): |
1115 | c53279cf | Guido Trotter | # FIXME: in the future maybe other cluster params won't require checking on
|
1116 | c53279cf | Guido Trotter | # all nodes to be modified.
|
1117 | c53279cf | Guido Trotter | self.needed_locks = {
|
1118 | c53279cf | Guido Trotter | locking.LEVEL_NODE: locking.ALL_SET, |
1119 | c53279cf | Guido Trotter | } |
1120 | c53279cf | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
1121 | 8084f9f6 | Manuel Franceschini | |
1122 | 8084f9f6 | Manuel Franceschini | def BuildHooksEnv(self): |
1123 | 8084f9f6 | Manuel Franceschini | """Build hooks env.
|
1124 | 8084f9f6 | Manuel Franceschini |
|
1125 | 8084f9f6 | Manuel Franceschini | """
|
1126 | 8084f9f6 | Manuel Franceschini | env = { |
1127 | d6a02168 | Michael Hanselmann | "OP_TARGET": self.cfg.GetClusterName(), |
1128 | 8084f9f6 | Manuel Franceschini | "NEW_VG_NAME": self.op.vg_name, |
1129 | 8084f9f6 | Manuel Franceschini | } |
1130 | d6a02168 | Michael Hanselmann | mn = self.cfg.GetMasterNode()
|
1131 | 8084f9f6 | Manuel Franceschini | return env, [mn], [mn]
|
1132 | 8084f9f6 | Manuel Franceschini | |
1133 | 8084f9f6 | Manuel Franceschini | def CheckPrereq(self): |
1134 | 8084f9f6 | Manuel Franceschini | """Check prerequisites.
|
1135 | 8084f9f6 | Manuel Franceschini |
|
1136 | 8084f9f6 | Manuel Franceschini | This checks whether the given params don't conflict and
|
1137 | 5f83e263 | Iustin Pop | if the given volume group is valid.
|
1138 | 8084f9f6 | Manuel Franceschini |
|
1139 | 8084f9f6 | Manuel Franceschini | """
|
1140 | c53279cf | Guido Trotter | # FIXME: This only works because there is only one parameter that can be
|
1141 | c53279cf | Guido Trotter | # changed or removed.
|
1142 | 8084f9f6 | Manuel Franceschini | if not self.op.vg_name: |
1143 | c53279cf | Guido Trotter | instances = self.cfg.GetAllInstancesInfo().values()
|
1144 | 8084f9f6 | Manuel Franceschini | for inst in instances: |
1145 | 8084f9f6 | Manuel Franceschini | for disk in inst.disks: |
1146 | 8084f9f6 | Manuel Franceschini | if _RecursiveCheckIfLVMBased(disk):
|
1147 | 8084f9f6 | Manuel Franceschini | raise errors.OpPrereqError("Cannot disable lvm storage while" |
1148 | 8084f9f6 | Manuel Franceschini | " lvm-based instances exist")
|
1149 | 8084f9f6 | Manuel Franceschini | |
1150 | 8084f9f6 | Manuel Franceschini | # if vg_name not None, checks given volume group on all nodes
|
1151 | 8084f9f6 | Manuel Franceschini | if self.op.vg_name: |
1152 | c53279cf | Guido Trotter | node_list = self.acquired_locks[locking.LEVEL_NODE]
|
1153 | 72737a7f | Iustin Pop | vglist = self.rpc.call_vg_list(node_list)
|
1154 | 8084f9f6 | Manuel Franceschini | for node in node_list: |
1155 | 8d1a2a64 | Michael Hanselmann | vgstatus = utils.CheckVolumeGroupSize(vglist[node], self.op.vg_name,
|
1156 | 8d1a2a64 | Michael Hanselmann | constants.MIN_VG_SIZE) |
1157 | 8084f9f6 | Manuel Franceschini | if vgstatus:
|
1158 | 8084f9f6 | Manuel Franceschini | raise errors.OpPrereqError("Error on node '%s': %s" % |
1159 | 8084f9f6 | Manuel Franceschini | (node, vgstatus)) |
1160 | 8084f9f6 | Manuel Franceschini | |
1161 | 8084f9f6 | Manuel Franceschini | def Exec(self, feedback_fn): |
1162 | 8084f9f6 | Manuel Franceschini | """Change the parameters of the cluster.
|
1163 | 8084f9f6 | Manuel Franceschini |
|
1164 | 8084f9f6 | Manuel Franceschini | """
|
1165 | 8084f9f6 | Manuel Franceschini | if self.op.vg_name != self.cfg.GetVGName(): |
1166 | 8084f9f6 | Manuel Franceschini | self.cfg.SetVGName(self.op.vg_name) |
1167 | 8084f9f6 | Manuel Franceschini | else:
|
1168 | 8084f9f6 | Manuel Franceschini | feedback_fn("Cluster LVM configuration already in desired"
|
1169 | 8084f9f6 | Manuel Franceschini | " state, not changing")
|
1170 | 8084f9f6 | Manuel Franceschini | |
1171 | 8084f9f6 | Manuel Franceschini | |
1172 | b9bddb6b | Iustin Pop | def _WaitForSync(lu, instance, oneshot=False, unlock=False): |
1173 | a8083063 | Iustin Pop | """Sleep and poll for an instance's disk to sync.
|
1174 | a8083063 | Iustin Pop |
|
1175 | a8083063 | Iustin Pop | """
|
1176 | a8083063 | Iustin Pop | if not instance.disks: |
1177 | a8083063 | Iustin Pop | return True |
1178 | a8083063 | Iustin Pop | |
1179 | a8083063 | Iustin Pop | if not oneshot: |
1180 | b9bddb6b | Iustin Pop | lu.proc.LogInfo("Waiting for instance %s to sync disks." % instance.name)
|
1181 | a8083063 | Iustin Pop | |
1182 | a8083063 | Iustin Pop | node = instance.primary_node |
1183 | a8083063 | Iustin Pop | |
1184 | a8083063 | Iustin Pop | for dev in instance.disks: |
1185 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(dev, node) |
1186 | a8083063 | Iustin Pop | |
1187 | a8083063 | Iustin Pop | retries = 0
|
1188 | a8083063 | Iustin Pop | while True: |
1189 | a8083063 | Iustin Pop | max_time = 0
|
1190 | a8083063 | Iustin Pop | done = True
|
1191 | a8083063 | Iustin Pop | cumul_degraded = False
|
1192 | 72737a7f | Iustin Pop | rstats = lu.rpc.call_blockdev_getmirrorstatus(node, instance.disks) |
1193 | a8083063 | Iustin Pop | if not rstats: |
1194 | b9bddb6b | Iustin Pop | lu.proc.LogWarning("Can't get any data from node %s" % node)
|
1195 | a8083063 | Iustin Pop | retries += 1
|
1196 | a8083063 | Iustin Pop | if retries >= 10: |
1197 | 3ecf6786 | Iustin Pop | raise errors.RemoteError("Can't contact node %s for mirror data," |
1198 | 3ecf6786 | Iustin Pop | " aborting." % node)
|
1199 | a8083063 | Iustin Pop | time.sleep(6)
|
1200 | a8083063 | Iustin Pop | continue
|
1201 | a8083063 | Iustin Pop | retries = 0
|
1202 | a8083063 | Iustin Pop | for i in range(len(rstats)): |
1203 | a8083063 | Iustin Pop | mstat = rstats[i] |
1204 | a8083063 | Iustin Pop | if mstat is None: |
1205 | b9bddb6b | Iustin Pop | lu.proc.LogWarning("Can't compute data for node %s/%s" %
|
1206 | b9bddb6b | Iustin Pop | (node, instance.disks[i].iv_name)) |
1207 | a8083063 | Iustin Pop | continue
|
1208 | 0834c866 | Iustin Pop | # we ignore the ldisk parameter
|
1209 | 0834c866 | Iustin Pop | perc_done, est_time, is_degraded, _ = mstat |
1210 | a8083063 | Iustin Pop | cumul_degraded = cumul_degraded or (is_degraded and perc_done is None) |
1211 | a8083063 | Iustin Pop | if perc_done is not None: |
1212 | a8083063 | Iustin Pop | done = False
|
1213 | a8083063 | Iustin Pop | if est_time is not None: |
1214 | a8083063 | Iustin Pop | rem_time = "%d estimated seconds remaining" % est_time
|
1215 | a8083063 | Iustin Pop | max_time = est_time |
1216 | a8083063 | Iustin Pop | else:
|
1217 | a8083063 | Iustin Pop | rem_time = "no time estimate"
|
1218 | b9bddb6b | Iustin Pop | lu.proc.LogInfo("- device %s: %5.2f%% done, %s" %
|
1219 | b9bddb6b | Iustin Pop | (instance.disks[i].iv_name, perc_done, rem_time)) |
1220 | a8083063 | Iustin Pop | if done or oneshot: |
1221 | a8083063 | Iustin Pop | break
|
1222 | a8083063 | Iustin Pop | |
1223 | d4fa5c23 | Iustin Pop | time.sleep(min(60, max_time)) |
1224 | a8083063 | Iustin Pop | |
1225 | a8083063 | Iustin Pop | if done:
|
1226 | b9bddb6b | Iustin Pop | lu.proc.LogInfo("Instance %s's disks are in sync." % instance.name)
|
1227 | a8083063 | Iustin Pop | return not cumul_degraded |
1228 | a8083063 | Iustin Pop | |
1229 | a8083063 | Iustin Pop | |
1230 | b9bddb6b | Iustin Pop | def _CheckDiskConsistency(lu, dev, node, on_primary, ldisk=False): |
1231 | a8083063 | Iustin Pop | """Check that mirrors are not degraded.
|
1232 | a8083063 | Iustin Pop |
|
1233 | 0834c866 | Iustin Pop | The ldisk parameter, if True, will change the test from the
|
1234 | 0834c866 | Iustin Pop | is_degraded attribute (which represents overall non-ok status for
|
1235 | 0834c866 | Iustin Pop | the device(s)) to the ldisk (representing the local storage status).
|
1236 | 0834c866 | Iustin Pop |
|
1237 | a8083063 | Iustin Pop | """
|
1238 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(dev, node) |
1239 | 0834c866 | Iustin Pop | if ldisk:
|
1240 | 0834c866 | Iustin Pop | idx = 6
|
1241 | 0834c866 | Iustin Pop | else:
|
1242 | 0834c866 | Iustin Pop | idx = 5
|
1243 | a8083063 | Iustin Pop | |
1244 | a8083063 | Iustin Pop | result = True
|
1245 | a8083063 | Iustin Pop | if on_primary or dev.AssembleOnSecondary(): |
1246 | 72737a7f | Iustin Pop | rstats = lu.rpc.call_blockdev_find(node, dev) |
1247 | a8083063 | Iustin Pop | if not rstats: |
1248 | aa9d0c32 | Guido Trotter | logger.ToStderr("Node %s: Disk degraded, not found or node down" % node)
|
1249 | a8083063 | Iustin Pop | result = False
|
1250 | a8083063 | Iustin Pop | else:
|
1251 | 0834c866 | Iustin Pop | result = result and (not rstats[idx]) |
1252 | a8083063 | Iustin Pop | if dev.children:
|
1253 | a8083063 | Iustin Pop | for child in dev.children: |
1254 | b9bddb6b | Iustin Pop | result = result and _CheckDiskConsistency(lu, child, node, on_primary)
|
1255 | a8083063 | Iustin Pop | |
1256 | a8083063 | Iustin Pop | return result
|
1257 | a8083063 | Iustin Pop | |
1258 | a8083063 | Iustin Pop | |
1259 | a8083063 | Iustin Pop | class LUDiagnoseOS(NoHooksLU): |
1260 | a8083063 | Iustin Pop | """Logical unit for OS diagnose/query.
|
1261 | a8083063 | Iustin Pop |
|
1262 | a8083063 | Iustin Pop | """
|
1263 | 1f9430d6 | Iustin Pop | _OP_REQP = ["output_fields", "names"] |
1264 | 6bf01bbb | Guido Trotter | REQ_BGL = False
|
1265 | a8083063 | Iustin Pop | |
1266 | 6bf01bbb | Guido Trotter | def ExpandNames(self): |
1267 | 1f9430d6 | Iustin Pop | if self.op.names: |
1268 | 1f9430d6 | Iustin Pop | raise errors.OpPrereqError("Selective OS query not supported") |
1269 | 1f9430d6 | Iustin Pop | |
1270 | 1f9430d6 | Iustin Pop | self.dynamic_fields = frozenset(["name", "valid", "node_status"]) |
1271 | 1f9430d6 | Iustin Pop | _CheckOutputFields(static=[], |
1272 | 1f9430d6 | Iustin Pop | dynamic=self.dynamic_fields,
|
1273 | 1f9430d6 | Iustin Pop | selected=self.op.output_fields)
|
1274 | 1f9430d6 | Iustin Pop | |
1275 | 6bf01bbb | Guido Trotter | # Lock all nodes, in shared mode
|
1276 | 6bf01bbb | Guido Trotter | self.needed_locks = {}
|
1277 | 6bf01bbb | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
1278 | e310b019 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
1279 | 6bf01bbb | Guido Trotter | |
1280 | 6bf01bbb | Guido Trotter | def CheckPrereq(self): |
1281 | 6bf01bbb | Guido Trotter | """Check prerequisites.
|
1282 | 6bf01bbb | Guido Trotter |
|
1283 | 6bf01bbb | Guido Trotter | """
|
1284 | 6bf01bbb | Guido Trotter | |
1285 | 1f9430d6 | Iustin Pop | @staticmethod
|
1286 | 1f9430d6 | Iustin Pop | def _DiagnoseByOS(node_list, rlist): |
1287 | 1f9430d6 | Iustin Pop | """Remaps a per-node return list into an a per-os per-node dictionary
|
1288 | 1f9430d6 | Iustin Pop |
|
1289 | 1f9430d6 | Iustin Pop | Args:
|
1290 | 1f9430d6 | Iustin Pop | node_list: a list with the names of all nodes
|
1291 | 1f9430d6 | Iustin Pop | rlist: a map with node names as keys and OS objects as values
|
1292 | 1f9430d6 | Iustin Pop |
|
1293 | 1f9430d6 | Iustin Pop | Returns:
|
1294 | 1f9430d6 | Iustin Pop | map: a map with osnames as keys and as value another map, with
|
1295 | 1f9430d6 | Iustin Pop | nodes as
|
1296 | 1f9430d6 | Iustin Pop | keys and list of OS objects as values
|
1297 | 1f9430d6 | Iustin Pop | e.g. {"debian-etch": {"node1": [<object>,...],
|
1298 | 1f9430d6 | Iustin Pop | "node2": [<object>,]}
|
1299 | 1f9430d6 | Iustin Pop | }
|
1300 | 1f9430d6 | Iustin Pop |
|
1301 | 1f9430d6 | Iustin Pop | """
|
1302 | 1f9430d6 | Iustin Pop | all_os = {} |
1303 | 1f9430d6 | Iustin Pop | for node_name, nr in rlist.iteritems(): |
1304 | 1f9430d6 | Iustin Pop | if not nr: |
1305 | 1f9430d6 | Iustin Pop | continue
|
1306 | b4de68a9 | Iustin Pop | for os_obj in nr: |
1307 | b4de68a9 | Iustin Pop | if os_obj.name not in all_os: |
1308 | 1f9430d6 | Iustin Pop | # build a list of nodes for this os containing empty lists
|
1309 | 1f9430d6 | Iustin Pop | # for each node in node_list
|
1310 | b4de68a9 | Iustin Pop | all_os[os_obj.name] = {} |
1311 | 1f9430d6 | Iustin Pop | for nname in node_list: |
1312 | b4de68a9 | Iustin Pop | all_os[os_obj.name][nname] = [] |
1313 | b4de68a9 | Iustin Pop | all_os[os_obj.name][node_name].append(os_obj) |
1314 | 1f9430d6 | Iustin Pop | return all_os
|
1315 | a8083063 | Iustin Pop | |
1316 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1317 | a8083063 | Iustin Pop | """Compute the list of OSes.
|
1318 | a8083063 | Iustin Pop |
|
1319 | a8083063 | Iustin Pop | """
|
1320 | 6bf01bbb | Guido Trotter | node_list = self.acquired_locks[locking.LEVEL_NODE]
|
1321 | 72737a7f | Iustin Pop | node_data = self.rpc.call_os_diagnose(node_list)
|
1322 | a8083063 | Iustin Pop | if node_data == False: |
1323 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Can't gather the list of OSes") |
1324 | 1f9430d6 | Iustin Pop | pol = self._DiagnoseByOS(node_list, node_data)
|
1325 | 1f9430d6 | Iustin Pop | output = [] |
1326 | 1f9430d6 | Iustin Pop | for os_name, os_data in pol.iteritems(): |
1327 | 1f9430d6 | Iustin Pop | row = [] |
1328 | 1f9430d6 | Iustin Pop | for field in self.op.output_fields: |
1329 | 1f9430d6 | Iustin Pop | if field == "name": |
1330 | 1f9430d6 | Iustin Pop | val = os_name |
1331 | 1f9430d6 | Iustin Pop | elif field == "valid": |
1332 | 1f9430d6 | Iustin Pop | val = utils.all([osl and osl[0] for osl in os_data.values()]) |
1333 | 1f9430d6 | Iustin Pop | elif field == "node_status": |
1334 | 1f9430d6 | Iustin Pop | val = {} |
1335 | 1f9430d6 | Iustin Pop | for node_name, nos_list in os_data.iteritems(): |
1336 | 1f9430d6 | Iustin Pop | val[node_name] = [(v.status, v.path) for v in nos_list] |
1337 | 1f9430d6 | Iustin Pop | else:
|
1338 | 1f9430d6 | Iustin Pop | raise errors.ParameterError(field)
|
1339 | 1f9430d6 | Iustin Pop | row.append(val) |
1340 | 1f9430d6 | Iustin Pop | output.append(row) |
1341 | 1f9430d6 | Iustin Pop | |
1342 | 1f9430d6 | Iustin Pop | return output
|
1343 | a8083063 | Iustin Pop | |
1344 | a8083063 | Iustin Pop | |
1345 | a8083063 | Iustin Pop | class LURemoveNode(LogicalUnit): |
1346 | a8083063 | Iustin Pop | """Logical unit for removing a node.
|
1347 | a8083063 | Iustin Pop |
|
1348 | a8083063 | Iustin Pop | """
|
1349 | a8083063 | Iustin Pop | HPATH = "node-remove"
|
1350 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_NODE |
1351 | a8083063 | Iustin Pop | _OP_REQP = ["node_name"]
|
1352 | a8083063 | Iustin Pop | |
1353 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
1354 | a8083063 | Iustin Pop | """Build hooks env.
|
1355 | a8083063 | Iustin Pop |
|
1356 | a8083063 | Iustin Pop | This doesn't run on the target node in the pre phase as a failed
|
1357 | d08869ee | Guido Trotter | node would then be impossible to remove.
|
1358 | a8083063 | Iustin Pop |
|
1359 | a8083063 | Iustin Pop | """
|
1360 | 396e1b78 | Michael Hanselmann | env = { |
1361 | 0e137c28 | Iustin Pop | "OP_TARGET": self.op.node_name, |
1362 | 396e1b78 | Michael Hanselmann | "NODE_NAME": self.op.node_name, |
1363 | 396e1b78 | Michael Hanselmann | } |
1364 | a8083063 | Iustin Pop | all_nodes = self.cfg.GetNodeList()
|
1365 | a8083063 | Iustin Pop | all_nodes.remove(self.op.node_name)
|
1366 | 396e1b78 | Michael Hanselmann | return env, all_nodes, all_nodes
|
1367 | a8083063 | Iustin Pop | |
1368 | a8083063 | Iustin Pop | def CheckPrereq(self): |
1369 | a8083063 | Iustin Pop | """Check prerequisites.
|
1370 | a8083063 | Iustin Pop |
|
1371 | a8083063 | Iustin Pop | This checks:
|
1372 | a8083063 | Iustin Pop | - the node exists in the configuration
|
1373 | a8083063 | Iustin Pop | - it does not have primary or secondary instances
|
1374 | a8083063 | Iustin Pop | - it's not the master
|
1375 | a8083063 | Iustin Pop |
|
1376 | a8083063 | Iustin Pop | Any errors are signalled by raising errors.OpPrereqError.
|
1377 | a8083063 | Iustin Pop |
|
1378 | a8083063 | Iustin Pop | """
|
1379 | a8083063 | Iustin Pop | node = self.cfg.GetNodeInfo(self.cfg.ExpandNodeName(self.op.node_name)) |
1380 | a8083063 | Iustin Pop | if node is None: |
1381 | a02bc76e | Iustin Pop | raise errors.OpPrereqError, ("Node '%s' is unknown." % self.op.node_name) |
1382 | a8083063 | Iustin Pop | |
1383 | a8083063 | Iustin Pop | instance_list = self.cfg.GetInstanceList()
|
1384 | a8083063 | Iustin Pop | |
1385 | d6a02168 | Michael Hanselmann | masternode = self.cfg.GetMasterNode()
|
1386 | a8083063 | Iustin Pop | if node.name == masternode:
|
1387 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Node is the master node," |
1388 | 3ecf6786 | Iustin Pop | " you need to failover first.")
|
1389 | a8083063 | Iustin Pop | |
1390 | a8083063 | Iustin Pop | for instance_name in instance_list: |
1391 | a8083063 | Iustin Pop | instance = self.cfg.GetInstanceInfo(instance_name)
|
1392 | a8083063 | Iustin Pop | if node.name == instance.primary_node:
|
1393 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Instance %s still running on the node," |
1394 | 3ecf6786 | Iustin Pop | " please remove first." % instance_name)
|
1395 | a8083063 | Iustin Pop | if node.name in instance.secondary_nodes: |
1396 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Instance %s has node as a secondary," |
1397 | 3ecf6786 | Iustin Pop | " please remove first." % instance_name)
|
1398 | a8083063 | Iustin Pop | self.op.node_name = node.name
|
1399 | a8083063 | Iustin Pop | self.node = node
|
1400 | a8083063 | Iustin Pop | |
1401 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1402 | a8083063 | Iustin Pop | """Removes the node from the cluster.
|
1403 | a8083063 | Iustin Pop |
|
1404 | a8083063 | Iustin Pop | """
|
1405 | a8083063 | Iustin Pop | node = self.node
|
1406 | a8083063 | Iustin Pop | logger.Info("stopping the node daemon and removing configs from node %s" %
|
1407 | a8083063 | Iustin Pop | node.name) |
1408 | a8083063 | Iustin Pop | |
1409 | d8470559 | Michael Hanselmann | self.context.RemoveNode(node.name)
|
1410 | a8083063 | Iustin Pop | |
1411 | 72737a7f | Iustin Pop | self.rpc.call_node_leave_cluster(node.name)
|
1412 | c8a0948f | Michael Hanselmann | |
1413 | a8083063 | Iustin Pop | |
1414 | a8083063 | Iustin Pop | class LUQueryNodes(NoHooksLU): |
1415 | a8083063 | Iustin Pop | """Logical unit for querying nodes.
|
1416 | a8083063 | Iustin Pop |
|
1417 | a8083063 | Iustin Pop | """
|
1418 | 246e180a | Iustin Pop | _OP_REQP = ["output_fields", "names"] |
1419 | 35705d8f | Guido Trotter | REQ_BGL = False
|
1420 | a8083063 | Iustin Pop | |
1421 | 35705d8f | Guido Trotter | def ExpandNames(self): |
1422 | e8a4c138 | Iustin Pop | self.dynamic_fields = frozenset([ |
1423 | e8a4c138 | Iustin Pop | "dtotal", "dfree", |
1424 | e8a4c138 | Iustin Pop | "mtotal", "mnode", "mfree", |
1425 | e8a4c138 | Iustin Pop | "bootid",
|
1426 | e8a4c138 | Iustin Pop | "ctotal",
|
1427 | e8a4c138 | Iustin Pop | ]) |
1428 | a8083063 | Iustin Pop | |
1429 | c8d8b4c8 | Iustin Pop | self.static_fields = frozenset([ |
1430 | c8d8b4c8 | Iustin Pop | "name", "pinst_cnt", "sinst_cnt", |
1431 | c8d8b4c8 | Iustin Pop | "pinst_list", "sinst_list", |
1432 | c8d8b4c8 | Iustin Pop | "pip", "sip", "tags", |
1433 | 38d7239a | Iustin Pop | "serial_no",
|
1434 | c8d8b4c8 | Iustin Pop | ]) |
1435 | c8d8b4c8 | Iustin Pop | |
1436 | c8d8b4c8 | Iustin Pop | _CheckOutputFields(static=self.static_fields,
|
1437 | dcb93971 | Michael Hanselmann | dynamic=self.dynamic_fields,
|
1438 | dcb93971 | Michael Hanselmann | selected=self.op.output_fields)
|
1439 | a8083063 | Iustin Pop | |
1440 | 35705d8f | Guido Trotter | self.needed_locks = {}
|
1441 | 35705d8f | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
1442 | c8d8b4c8 | Iustin Pop | |
1443 | c8d8b4c8 | Iustin Pop | if self.op.names: |
1444 | c8d8b4c8 | Iustin Pop | self.wanted = _GetWantedNodes(self, self.op.names) |
1445 | 35705d8f | Guido Trotter | else:
|
1446 | c8d8b4c8 | Iustin Pop | self.wanted = locking.ALL_SET
|
1447 | c8d8b4c8 | Iustin Pop | |
1448 | c8d8b4c8 | Iustin Pop | self.do_locking = not self.static_fields.issuperset(self.op.output_fields) |
1449 | c8d8b4c8 | Iustin Pop | if self.do_locking: |
1450 | c8d8b4c8 | Iustin Pop | # if we don't request only static fields, we need to lock the nodes
|
1451 | c8d8b4c8 | Iustin Pop | self.needed_locks[locking.LEVEL_NODE] = self.wanted |
1452 | c8d8b4c8 | Iustin Pop | |
1453 | 35705d8f | Guido Trotter | |
1454 | 35705d8f | Guido Trotter | def CheckPrereq(self): |
1455 | 35705d8f | Guido Trotter | """Check prerequisites.
|
1456 | 35705d8f | Guido Trotter |
|
1457 | 35705d8f | Guido Trotter | """
|
1458 | c8d8b4c8 | Iustin Pop | # The validation of the node list is done in the _GetWantedNodes,
|
1459 | c8d8b4c8 | Iustin Pop | # if non empty, and if empty, there's no validation to do
|
1460 | c8d8b4c8 | Iustin Pop | pass
|
1461 | a8083063 | Iustin Pop | |
1462 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1463 | a8083063 | Iustin Pop | """Computes the list of nodes and their attributes.
|
1464 | a8083063 | Iustin Pop |
|
1465 | a8083063 | Iustin Pop | """
|
1466 | c8d8b4c8 | Iustin Pop | all_info = self.cfg.GetAllNodesInfo()
|
1467 | c8d8b4c8 | Iustin Pop | if self.do_locking: |
1468 | c8d8b4c8 | Iustin Pop | nodenames = self.acquired_locks[locking.LEVEL_NODE]
|
1469 | 3fa93523 | Guido Trotter | elif self.wanted != locking.ALL_SET: |
1470 | 3fa93523 | Guido Trotter | nodenames = self.wanted
|
1471 | 3fa93523 | Guido Trotter | missing = set(nodenames).difference(all_info.keys())
|
1472 | 3fa93523 | Guido Trotter | if missing:
|
1473 | 7b3a8fb5 | Iustin Pop | raise errors.OpExecError(
|
1474 | 3fa93523 | Guido Trotter | "Some nodes were removed before retrieving their data: %s" % missing)
|
1475 | c8d8b4c8 | Iustin Pop | else:
|
1476 | c8d8b4c8 | Iustin Pop | nodenames = all_info.keys() |
1477 | c8d8b4c8 | Iustin Pop | nodelist = [all_info[name] for name in nodenames] |
1478 | a8083063 | Iustin Pop | |
1479 | a8083063 | Iustin Pop | # begin data gathering
|
1480 | a8083063 | Iustin Pop | |
1481 | a8083063 | Iustin Pop | if self.dynamic_fields.intersection(self.op.output_fields): |
1482 | a8083063 | Iustin Pop | live_data = {} |
1483 | 72737a7f | Iustin Pop | node_data = self.rpc.call_node_info(nodenames, self.cfg.GetVGName(), |
1484 | 72737a7f | Iustin Pop | self.cfg.GetHypervisorType())
|
1485 | a8083063 | Iustin Pop | for name in nodenames: |
1486 | a8083063 | Iustin Pop | nodeinfo = node_data.get(name, None)
|
1487 | a8083063 | Iustin Pop | if nodeinfo:
|
1488 | a8083063 | Iustin Pop | live_data[name] = { |
1489 | a8083063 | Iustin Pop | "mtotal": utils.TryConvert(int, nodeinfo['memory_total']), |
1490 | a8083063 | Iustin Pop | "mnode": utils.TryConvert(int, nodeinfo['memory_dom0']), |
1491 | a8083063 | Iustin Pop | "mfree": utils.TryConvert(int, nodeinfo['memory_free']), |
1492 | a8083063 | Iustin Pop | "dtotal": utils.TryConvert(int, nodeinfo['vg_size']), |
1493 | a8083063 | Iustin Pop | "dfree": utils.TryConvert(int, nodeinfo['vg_free']), |
1494 | e8a4c138 | Iustin Pop | "ctotal": utils.TryConvert(int, nodeinfo['cpu_total']), |
1495 | 3ef10550 | Michael Hanselmann | "bootid": nodeinfo['bootid'], |
1496 | a8083063 | Iustin Pop | } |
1497 | a8083063 | Iustin Pop | else:
|
1498 | a8083063 | Iustin Pop | live_data[name] = {} |
1499 | a8083063 | Iustin Pop | else:
|
1500 | a8083063 | Iustin Pop | live_data = dict.fromkeys(nodenames, {})
|
1501 | a8083063 | Iustin Pop | |
1502 | ec223efb | Iustin Pop | node_to_primary = dict([(name, set()) for name in nodenames]) |
1503 | ec223efb | Iustin Pop | node_to_secondary = dict([(name, set()) for name in nodenames]) |
1504 | a8083063 | Iustin Pop | |
1505 | ec223efb | Iustin Pop | inst_fields = frozenset(("pinst_cnt", "pinst_list", |
1506 | ec223efb | Iustin Pop | "sinst_cnt", "sinst_list")) |
1507 | ec223efb | Iustin Pop | if inst_fields & frozenset(self.op.output_fields): |
1508 | a8083063 | Iustin Pop | instancelist = self.cfg.GetInstanceList()
|
1509 | a8083063 | Iustin Pop | |
1510 | ec223efb | Iustin Pop | for instance_name in instancelist: |
1511 | ec223efb | Iustin Pop | inst = self.cfg.GetInstanceInfo(instance_name)
|
1512 | ec223efb | Iustin Pop | if inst.primary_node in node_to_primary: |
1513 | ec223efb | Iustin Pop | node_to_primary[inst.primary_node].add(inst.name) |
1514 | ec223efb | Iustin Pop | for secnode in inst.secondary_nodes: |
1515 | ec223efb | Iustin Pop | if secnode in node_to_secondary: |
1516 | ec223efb | Iustin Pop | node_to_secondary[secnode].add(inst.name) |
1517 | a8083063 | Iustin Pop | |
1518 | a8083063 | Iustin Pop | # end data gathering
|
1519 | a8083063 | Iustin Pop | |
1520 | a8083063 | Iustin Pop | output = [] |
1521 | a8083063 | Iustin Pop | for node in nodelist: |
1522 | a8083063 | Iustin Pop | node_output = [] |
1523 | a8083063 | Iustin Pop | for field in self.op.output_fields: |
1524 | a8083063 | Iustin Pop | if field == "name": |
1525 | a8083063 | Iustin Pop | val = node.name |
1526 | ec223efb | Iustin Pop | elif field == "pinst_list": |
1527 | ec223efb | Iustin Pop | val = list(node_to_primary[node.name])
|
1528 | ec223efb | Iustin Pop | elif field == "sinst_list": |
1529 | ec223efb | Iustin Pop | val = list(node_to_secondary[node.name])
|
1530 | ec223efb | Iustin Pop | elif field == "pinst_cnt": |
1531 | ec223efb | Iustin Pop | val = len(node_to_primary[node.name])
|
1532 | ec223efb | Iustin Pop | elif field == "sinst_cnt": |
1533 | ec223efb | Iustin Pop | val = len(node_to_secondary[node.name])
|
1534 | a8083063 | Iustin Pop | elif field == "pip": |
1535 | a8083063 | Iustin Pop | val = node.primary_ip |
1536 | a8083063 | Iustin Pop | elif field == "sip": |
1537 | a8083063 | Iustin Pop | val = node.secondary_ip |
1538 | 130a6a6f | Iustin Pop | elif field == "tags": |
1539 | 130a6a6f | Iustin Pop | val = list(node.GetTags())
|
1540 | 38d7239a | Iustin Pop | elif field == "serial_no": |
1541 | 38d7239a | Iustin Pop | val = node.serial_no |
1542 | a8083063 | Iustin Pop | elif field in self.dynamic_fields: |
1543 | ec223efb | Iustin Pop | val = live_data[node.name].get(field, None)
|
1544 | a8083063 | Iustin Pop | else:
|
1545 | 3ecf6786 | Iustin Pop | raise errors.ParameterError(field)
|
1546 | a8083063 | Iustin Pop | node_output.append(val) |
1547 | a8083063 | Iustin Pop | output.append(node_output) |
1548 | a8083063 | Iustin Pop | |
1549 | a8083063 | Iustin Pop | return output
|
1550 | a8083063 | Iustin Pop | |
1551 | a8083063 | Iustin Pop | |
1552 | dcb93971 | Michael Hanselmann | class LUQueryNodeVolumes(NoHooksLU): |
1553 | dcb93971 | Michael Hanselmann | """Logical unit for getting volumes on node(s).
|
1554 | dcb93971 | Michael Hanselmann |
|
1555 | dcb93971 | Michael Hanselmann | """
|
1556 | dcb93971 | Michael Hanselmann | _OP_REQP = ["nodes", "output_fields"] |
1557 | 21a15682 | Guido Trotter | REQ_BGL = False
|
1558 | 21a15682 | Guido Trotter | |
1559 | 21a15682 | Guido Trotter | def ExpandNames(self): |
1560 | 21a15682 | Guido Trotter | _CheckOutputFields(static=["node"],
|
1561 | 21a15682 | Guido Trotter | dynamic=["phys", "vg", "name", "size", "instance"], |
1562 | 21a15682 | Guido Trotter | selected=self.op.output_fields)
|
1563 | 21a15682 | Guido Trotter | |
1564 | 21a15682 | Guido Trotter | self.needed_locks = {}
|
1565 | 21a15682 | Guido Trotter | self.share_locks[locking.LEVEL_NODE] = 1 |
1566 | 21a15682 | Guido Trotter | if not self.op.nodes: |
1567 | e310b019 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
|
1568 | 21a15682 | Guido Trotter | else:
|
1569 | 21a15682 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = \
|
1570 | 21a15682 | Guido Trotter | _GetWantedNodes(self, self.op.nodes) |
1571 | dcb93971 | Michael Hanselmann | |
1572 | dcb93971 | Michael Hanselmann | def CheckPrereq(self): |
1573 | dcb93971 | Michael Hanselmann | """Check prerequisites.
|
1574 | dcb93971 | Michael Hanselmann |
|
1575 | dcb93971 | Michael Hanselmann | This checks that the fields required are valid output fields.
|
1576 | dcb93971 | Michael Hanselmann |
|
1577 | dcb93971 | Michael Hanselmann | """
|
1578 | 21a15682 | Guido Trotter | self.nodes = self.acquired_locks[locking.LEVEL_NODE] |
1579 | dcb93971 | Michael Hanselmann | |
1580 | dcb93971 | Michael Hanselmann | def Exec(self, feedback_fn): |
1581 | dcb93971 | Michael Hanselmann | """Computes the list of nodes and their attributes.
|
1582 | dcb93971 | Michael Hanselmann |
|
1583 | dcb93971 | Michael Hanselmann | """
|
1584 | a7ba5e53 | Iustin Pop | nodenames = self.nodes
|
1585 | 72737a7f | Iustin Pop | volumes = self.rpc.call_node_volumes(nodenames)
|
1586 | dcb93971 | Michael Hanselmann | |
1587 | dcb93971 | Michael Hanselmann | ilist = [self.cfg.GetInstanceInfo(iname) for iname |
1588 | dcb93971 | Michael Hanselmann | in self.cfg.GetInstanceList()] |
1589 | dcb93971 | Michael Hanselmann | |
1590 | dcb93971 | Michael Hanselmann | lv_by_node = dict([(inst, inst.MapLVsByNode()) for inst in ilist]) |
1591 | dcb93971 | Michael Hanselmann | |
1592 | dcb93971 | Michael Hanselmann | output = [] |
1593 | dcb93971 | Michael Hanselmann | for node in nodenames: |
1594 | 37d19eb2 | Michael Hanselmann | if node not in volumes or not volumes[node]: |
1595 | 37d19eb2 | Michael Hanselmann | continue
|
1596 | 37d19eb2 | Michael Hanselmann | |
1597 | dcb93971 | Michael Hanselmann | node_vols = volumes[node][:] |
1598 | dcb93971 | Michael Hanselmann | node_vols.sort(key=lambda vol: vol['dev']) |
1599 | dcb93971 | Michael Hanselmann | |
1600 | dcb93971 | Michael Hanselmann | for vol in node_vols: |
1601 | dcb93971 | Michael Hanselmann | node_output = [] |
1602 | dcb93971 | Michael Hanselmann | for field in self.op.output_fields: |
1603 | dcb93971 | Michael Hanselmann | if field == "node": |
1604 | dcb93971 | Michael Hanselmann | val = node |
1605 | dcb93971 | Michael Hanselmann | elif field == "phys": |
1606 | dcb93971 | Michael Hanselmann | val = vol['dev']
|
1607 | dcb93971 | Michael Hanselmann | elif field == "vg": |
1608 | dcb93971 | Michael Hanselmann | val = vol['vg']
|
1609 | dcb93971 | Michael Hanselmann | elif field == "name": |
1610 | dcb93971 | Michael Hanselmann | val = vol['name']
|
1611 | dcb93971 | Michael Hanselmann | elif field == "size": |
1612 | dcb93971 | Michael Hanselmann | val = int(float(vol['size'])) |
1613 | dcb93971 | Michael Hanselmann | elif field == "instance": |
1614 | dcb93971 | Michael Hanselmann | for inst in ilist: |
1615 | dcb93971 | Michael Hanselmann | if node not in lv_by_node[inst]: |
1616 | dcb93971 | Michael Hanselmann | continue
|
1617 | dcb93971 | Michael Hanselmann | if vol['name'] in lv_by_node[inst][node]: |
1618 | dcb93971 | Michael Hanselmann | val = inst.name |
1619 | dcb93971 | Michael Hanselmann | break
|
1620 | dcb93971 | Michael Hanselmann | else:
|
1621 | dcb93971 | Michael Hanselmann | val = '-'
|
1622 | dcb93971 | Michael Hanselmann | else:
|
1623 | 3ecf6786 | Iustin Pop | raise errors.ParameterError(field)
|
1624 | dcb93971 | Michael Hanselmann | node_output.append(str(val))
|
1625 | dcb93971 | Michael Hanselmann | |
1626 | dcb93971 | Michael Hanselmann | output.append(node_output) |
1627 | dcb93971 | Michael Hanselmann | |
1628 | dcb93971 | Michael Hanselmann | return output
|
1629 | dcb93971 | Michael Hanselmann | |
1630 | dcb93971 | Michael Hanselmann | |
1631 | a8083063 | Iustin Pop | class LUAddNode(LogicalUnit): |
1632 | a8083063 | Iustin Pop | """Logical unit for adding node to the cluster.
|
1633 | a8083063 | Iustin Pop |
|
1634 | a8083063 | Iustin Pop | """
|
1635 | a8083063 | Iustin Pop | HPATH = "node-add"
|
1636 | a8083063 | Iustin Pop | HTYPE = constants.HTYPE_NODE |
1637 | a8083063 | Iustin Pop | _OP_REQP = ["node_name"]
|
1638 | a8083063 | Iustin Pop | |
1639 | a8083063 | Iustin Pop | def BuildHooksEnv(self): |
1640 | a8083063 | Iustin Pop | """Build hooks env.
|
1641 | a8083063 | Iustin Pop |
|
1642 | a8083063 | Iustin Pop | This will run on all nodes before, and on all nodes + the new node after.
|
1643 | a8083063 | Iustin Pop |
|
1644 | a8083063 | Iustin Pop | """
|
1645 | a8083063 | Iustin Pop | env = { |
1646 | 0e137c28 | Iustin Pop | "OP_TARGET": self.op.node_name, |
1647 | a8083063 | Iustin Pop | "NODE_NAME": self.op.node_name, |
1648 | a8083063 | Iustin Pop | "NODE_PIP": self.op.primary_ip, |
1649 | a8083063 | Iustin Pop | "NODE_SIP": self.op.secondary_ip, |
1650 | a8083063 | Iustin Pop | } |
1651 | a8083063 | Iustin Pop | nodes_0 = self.cfg.GetNodeList()
|
1652 | a8083063 | Iustin Pop | nodes_1 = nodes_0 + [self.op.node_name, ]
|
1653 | a8083063 | Iustin Pop | return env, nodes_0, nodes_1
|
1654 | a8083063 | Iustin Pop | |
1655 | a8083063 | Iustin Pop | def CheckPrereq(self): |
1656 | a8083063 | Iustin Pop | """Check prerequisites.
|
1657 | a8083063 | Iustin Pop |
|
1658 | a8083063 | Iustin Pop | This checks:
|
1659 | a8083063 | Iustin Pop | - the new node is not already in the config
|
1660 | a8083063 | Iustin Pop | - it is resolvable
|
1661 | a8083063 | Iustin Pop | - its parameters (single/dual homed) matches the cluster
|
1662 | a8083063 | Iustin Pop |
|
1663 | a8083063 | Iustin Pop | Any errors are signalled by raising errors.OpPrereqError.
|
1664 | a8083063 | Iustin Pop |
|
1665 | a8083063 | Iustin Pop | """
|
1666 | a8083063 | Iustin Pop | node_name = self.op.node_name
|
1667 | a8083063 | Iustin Pop | cfg = self.cfg
|
1668 | a8083063 | Iustin Pop | |
1669 | 89e1fc26 | Iustin Pop | dns_data = utils.HostInfo(node_name) |
1670 | a8083063 | Iustin Pop | |
1671 | bcf043c9 | Iustin Pop | node = dns_data.name |
1672 | bcf043c9 | Iustin Pop | primary_ip = self.op.primary_ip = dns_data.ip
|
1673 | a8083063 | Iustin Pop | secondary_ip = getattr(self.op, "secondary_ip", None) |
1674 | a8083063 | Iustin Pop | if secondary_ip is None: |
1675 | a8083063 | Iustin Pop | secondary_ip = primary_ip |
1676 | a8083063 | Iustin Pop | if not utils.IsValidIP(secondary_ip): |
1677 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Invalid secondary IP given") |
1678 | a8083063 | Iustin Pop | self.op.secondary_ip = secondary_ip
|
1679 | e7c6e02b | Michael Hanselmann | |
1680 | a8083063 | Iustin Pop | node_list = cfg.GetNodeList() |
1681 | e7c6e02b | Michael Hanselmann | if not self.op.readd and node in node_list: |
1682 | e7c6e02b | Michael Hanselmann | raise errors.OpPrereqError("Node %s is already in the configuration" % |
1683 | e7c6e02b | Michael Hanselmann | node) |
1684 | e7c6e02b | Michael Hanselmann | elif self.op.readd and node not in node_list: |
1685 | e7c6e02b | Michael Hanselmann | raise errors.OpPrereqError("Node %s is not in the configuration" % node) |
1686 | a8083063 | Iustin Pop | |
1687 | a8083063 | Iustin Pop | for existing_node_name in node_list: |
1688 | a8083063 | Iustin Pop | existing_node = cfg.GetNodeInfo(existing_node_name) |
1689 | e7c6e02b | Michael Hanselmann | |
1690 | e7c6e02b | Michael Hanselmann | if self.op.readd and node == existing_node_name: |
1691 | e7c6e02b | Michael Hanselmann | if (existing_node.primary_ip != primary_ip or |
1692 | e7c6e02b | Michael Hanselmann | existing_node.secondary_ip != secondary_ip): |
1693 | e7c6e02b | Michael Hanselmann | raise errors.OpPrereqError("Readded node doesn't have the same IP" |
1694 | e7c6e02b | Michael Hanselmann | " address configuration as before")
|
1695 | e7c6e02b | Michael Hanselmann | continue
|
1696 | e7c6e02b | Michael Hanselmann | |
1697 | a8083063 | Iustin Pop | if (existing_node.primary_ip == primary_ip or |
1698 | a8083063 | Iustin Pop | existing_node.secondary_ip == primary_ip or
|
1699 | a8083063 | Iustin Pop | existing_node.primary_ip == secondary_ip or
|
1700 | a8083063 | Iustin Pop | existing_node.secondary_ip == secondary_ip): |
1701 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("New node ip address(es) conflict with" |
1702 | 3ecf6786 | Iustin Pop | " existing node %s" % existing_node.name)
|
1703 | a8083063 | Iustin Pop | |
1704 | a8083063 | Iustin Pop | # check that the type of the node (single versus dual homed) is the
|
1705 | a8083063 | Iustin Pop | # same as for the master
|
1706 | d6a02168 | Michael Hanselmann | myself = cfg.GetNodeInfo(self.cfg.GetMasterNode())
|
1707 | a8083063 | Iustin Pop | master_singlehomed = myself.secondary_ip == myself.primary_ip |
1708 | a8083063 | Iustin Pop | newbie_singlehomed = secondary_ip == primary_ip |
1709 | a8083063 | Iustin Pop | if master_singlehomed != newbie_singlehomed:
|
1710 | a8083063 | Iustin Pop | if master_singlehomed:
|
1711 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("The master has no private ip but the" |
1712 | 3ecf6786 | Iustin Pop | " new node has one")
|
1713 | a8083063 | Iustin Pop | else:
|
1714 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("The master has a private ip but the" |
1715 | 3ecf6786 | Iustin Pop | " new node doesn't have one")
|
1716 | a8083063 | Iustin Pop | |
1717 | a8083063 | Iustin Pop | # checks reachablity
|
1718 | b15d625f | Iustin Pop | if not utils.TcpPing(primary_ip, constants.DEFAULT_NODED_PORT): |
1719 | 3ecf6786 | Iustin Pop | raise errors.OpPrereqError("Node not reachable by ping") |
1720 | a8083063 | Iustin Pop | |
1721 | a8083063 | Iustin Pop | if not newbie_singlehomed: |
1722 | a8083063 | Iustin Pop | # check reachability from my secondary ip to newbie's secondary ip
|
1723 | b15d625f | Iustin Pop | if not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT, |
1724 | b15d625f | Iustin Pop | source=myself.secondary_ip): |
1725 | f4bc1f2c | Michael Hanselmann | raise errors.OpPrereqError("Node secondary ip not reachable by TCP" |
1726 | f4bc1f2c | Michael Hanselmann | " based ping to noded port")
|
1727 | a8083063 | Iustin Pop | |
1728 | a8083063 | Iustin Pop | self.new_node = objects.Node(name=node,
|
1729 | a8083063 | Iustin Pop | primary_ip=primary_ip, |
1730 | a8083063 | Iustin Pop | secondary_ip=secondary_ip) |
1731 | a8083063 | Iustin Pop | |
1732 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1733 | a8083063 | Iustin Pop | """Adds the new node to the cluster.
|
1734 | a8083063 | Iustin Pop |
|
1735 | a8083063 | Iustin Pop | """
|
1736 | a8083063 | Iustin Pop | new_node = self.new_node
|
1737 | a8083063 | Iustin Pop | node = new_node.name |
1738 | a8083063 | Iustin Pop | |
1739 | a8083063 | Iustin Pop | # check connectivity
|
1740 | 72737a7f | Iustin Pop | result = self.rpc.call_version([node])[node]
|
1741 | a8083063 | Iustin Pop | if result:
|
1742 | a8083063 | Iustin Pop | if constants.PROTOCOL_VERSION == result:
|
1743 | a8083063 | Iustin Pop | logger.Info("communication to node %s fine, sw version %s match" %
|
1744 | a8083063 | Iustin Pop | (node, result)) |
1745 | a8083063 | Iustin Pop | else:
|
1746 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Version mismatch master version %s," |
1747 | 3ecf6786 | Iustin Pop | " node version %s" %
|
1748 | 3ecf6786 | Iustin Pop | (constants.PROTOCOL_VERSION, result)) |
1749 | a8083063 | Iustin Pop | else:
|
1750 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Cannot get version from the new node") |
1751 | a8083063 | Iustin Pop | |
1752 | a8083063 | Iustin Pop | # setup ssh on node
|
1753 | a8083063 | Iustin Pop | logger.Info("copy ssh key to node %s" % node)
|
1754 | 70d9e3d8 | Iustin Pop | priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS) |
1755 | a8083063 | Iustin Pop | keyarray = [] |
1756 | 70d9e3d8 | Iustin Pop | keyfiles = [constants.SSH_HOST_DSA_PRIV, constants.SSH_HOST_DSA_PUB, |
1757 | 70d9e3d8 | Iustin Pop | constants.SSH_HOST_RSA_PRIV, constants.SSH_HOST_RSA_PUB, |
1758 | 70d9e3d8 | Iustin Pop | priv_key, pub_key] |
1759 | a8083063 | Iustin Pop | |
1760 | a8083063 | Iustin Pop | for i in keyfiles: |
1761 | a8083063 | Iustin Pop | f = open(i, 'r') |
1762 | a8083063 | Iustin Pop | try:
|
1763 | a8083063 | Iustin Pop | keyarray.append(f.read()) |
1764 | a8083063 | Iustin Pop | finally:
|
1765 | a8083063 | Iustin Pop | f.close() |
1766 | a8083063 | Iustin Pop | |
1767 | 72737a7f | Iustin Pop | result = self.rpc.call_node_add(node, keyarray[0], keyarray[1], |
1768 | 72737a7f | Iustin Pop | keyarray[2],
|
1769 | 72737a7f | Iustin Pop | keyarray[3], keyarray[4], keyarray[5]) |
1770 | a8083063 | Iustin Pop | |
1771 | a8083063 | Iustin Pop | if not result: |
1772 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Cannot transfer ssh keys to the new node") |
1773 | a8083063 | Iustin Pop | |
1774 | a8083063 | Iustin Pop | # Add node to our /etc/hosts, and add key to known_hosts
|
1775 | d9c02ca6 | Michael Hanselmann | utils.AddHostToEtcHosts(new_node.name) |
1776 | c8a0948f | Michael Hanselmann | |
1777 | a8083063 | Iustin Pop | if new_node.secondary_ip != new_node.primary_ip:
|
1778 | caad16e2 | Iustin Pop | if not self.rpc.call_node_has_ip_address(new_node.name, |
1779 | caad16e2 | Iustin Pop | new_node.secondary_ip): |
1780 | f4bc1f2c | Michael Hanselmann | raise errors.OpExecError("Node claims it doesn't have the secondary ip" |
1781 | f4bc1f2c | Michael Hanselmann | " you gave (%s). Please fix and re-run this"
|
1782 | f4bc1f2c | Michael Hanselmann | " command." % new_node.secondary_ip)
|
1783 | a8083063 | Iustin Pop | |
1784 | d6a02168 | Michael Hanselmann | node_verify_list = [self.cfg.GetMasterNode()]
|
1785 | 5c0527ed | Guido Trotter | node_verify_param = { |
1786 | 5c0527ed | Guido Trotter | 'nodelist': [node],
|
1787 | 5c0527ed | Guido Trotter | # TODO: do a node-net-test as well?
|
1788 | 5c0527ed | Guido Trotter | } |
1789 | 5c0527ed | Guido Trotter | |
1790 | 72737a7f | Iustin Pop | result = self.rpc.call_node_verify(node_verify_list, node_verify_param,
|
1791 | 72737a7f | Iustin Pop | self.cfg.GetClusterName())
|
1792 | 5c0527ed | Guido Trotter | for verifier in node_verify_list: |
1793 | 5c0527ed | Guido Trotter | if not result[verifier]: |
1794 | 5c0527ed | Guido Trotter | raise errors.OpExecError("Cannot communicate with %s's node daemon" |
1795 | 5c0527ed | Guido Trotter | " for remote verification" % verifier)
|
1796 | 5c0527ed | Guido Trotter | if result[verifier]['nodelist']: |
1797 | 5c0527ed | Guido Trotter | for failed in result[verifier]['nodelist']: |
1798 | 5c0527ed | Guido Trotter | feedback_fn("ssh/hostname verification failed %s -> %s" %
|
1799 | 5c0527ed | Guido Trotter | (verifier, result[verifier]['nodelist'][failed]))
|
1800 | 5c0527ed | Guido Trotter | raise errors.OpExecError("ssh/hostname verification failed.") |
1801 | ff98055b | Iustin Pop | |
1802 | a8083063 | Iustin Pop | # Distribute updated /etc/hosts and known_hosts to all nodes,
|
1803 | a8083063 | Iustin Pop | # including the node just added
|
1804 | d6a02168 | Michael Hanselmann | myself = self.cfg.GetNodeInfo(self.cfg.GetMasterNode()) |
1805 | 102b115b | Michael Hanselmann | dist_nodes = self.cfg.GetNodeList()
|
1806 | 102b115b | Michael Hanselmann | if not self.op.readd: |
1807 | 102b115b | Michael Hanselmann | dist_nodes.append(node) |
1808 | a8083063 | Iustin Pop | if myself.name in dist_nodes: |
1809 | a8083063 | Iustin Pop | dist_nodes.remove(myself.name) |
1810 | a8083063 | Iustin Pop | |
1811 | a8083063 | Iustin Pop | logger.Debug("Copying hosts and known_hosts to all nodes")
|
1812 | 107711b0 | Michael Hanselmann | for fname in (constants.ETC_HOSTS, constants.SSH_KNOWN_HOSTS_FILE): |
1813 | 72737a7f | Iustin Pop | result = self.rpc.call_upload_file(dist_nodes, fname)
|
1814 | a8083063 | Iustin Pop | for to_node in dist_nodes: |
1815 | a8083063 | Iustin Pop | if not result[to_node]: |
1816 | a8083063 | Iustin Pop | logger.Error("copy of file %s to node %s failed" %
|
1817 | a8083063 | Iustin Pop | (fname, to_node)) |
1818 | a8083063 | Iustin Pop | |
1819 | d6a02168 | Michael Hanselmann | to_copy = [] |
1820 | 00cd937c | Iustin Pop | if constants.HT_XEN_HVM in self.cfg.GetClusterInfo().enabled_hypervisors: |
1821 | 2a6469d5 | Alexander Schreiber | to_copy.append(constants.VNC_PASSWORD_FILE) |
1822 | a8083063 | Iustin Pop | for fname in to_copy: |
1823 | 72737a7f | Iustin Pop | result = self.rpc.call_upload_file([node], fname)
|
1824 | b5602d15 | Guido Trotter | if not result[node]: |
1825 | a8083063 | Iustin Pop | logger.Error("could not copy file %s to node %s" % (fname, node))
|
1826 | a8083063 | Iustin Pop | |
1827 | d8470559 | Michael Hanselmann | if self.op.readd: |
1828 | d8470559 | Michael Hanselmann | self.context.ReaddNode(new_node)
|
1829 | d8470559 | Michael Hanselmann | else:
|
1830 | d8470559 | Michael Hanselmann | self.context.AddNode(new_node)
|
1831 | a8083063 | Iustin Pop | |
1832 | a8083063 | Iustin Pop | |
1833 | a8083063 | Iustin Pop | class LUQueryClusterInfo(NoHooksLU): |
1834 | a8083063 | Iustin Pop | """Query cluster configuration.
|
1835 | a8083063 | Iustin Pop |
|
1836 | a8083063 | Iustin Pop | """
|
1837 | a8083063 | Iustin Pop | _OP_REQP = [] |
1838 | 59322403 | Iustin Pop | REQ_MASTER = False
|
1839 | 642339cf | Guido Trotter | REQ_BGL = False
|
1840 | 642339cf | Guido Trotter | |
1841 | 642339cf | Guido Trotter | def ExpandNames(self): |
1842 | 642339cf | Guido Trotter | self.needed_locks = {}
|
1843 | a8083063 | Iustin Pop | |
1844 | a8083063 | Iustin Pop | def CheckPrereq(self): |
1845 | a8083063 | Iustin Pop | """No prerequsites needed for this LU.
|
1846 | a8083063 | Iustin Pop |
|
1847 | a8083063 | Iustin Pop | """
|
1848 | a8083063 | Iustin Pop | pass
|
1849 | a8083063 | Iustin Pop | |
1850 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1851 | a8083063 | Iustin Pop | """Return cluster config.
|
1852 | a8083063 | Iustin Pop |
|
1853 | a8083063 | Iustin Pop | """
|
1854 | a8083063 | Iustin Pop | result = { |
1855 | d6a02168 | Michael Hanselmann | "name": self.cfg.GetClusterName(), |
1856 | a8083063 | Iustin Pop | "software_version": constants.RELEASE_VERSION,
|
1857 | a8083063 | Iustin Pop | "protocol_version": constants.PROTOCOL_VERSION,
|
1858 | a8083063 | Iustin Pop | "config_version": constants.CONFIG_VERSION,
|
1859 | a8083063 | Iustin Pop | "os_api_version": constants.OS_API_VERSION,
|
1860 | a8083063 | Iustin Pop | "export_version": constants.EXPORT_VERSION,
|
1861 | d6a02168 | Michael Hanselmann | "master": self.cfg.GetMasterNode(), |
1862 | a8083063 | Iustin Pop | "architecture": (platform.architecture()[0], platform.machine()), |
1863 | d6a02168 | Michael Hanselmann | "hypervisor_type": self.cfg.GetHypervisorType(), |
1864 | e69d05fd | Iustin Pop | "enabled_hypervisors": self.cfg.GetClusterInfo().enabled_hypervisors, |
1865 | a8083063 | Iustin Pop | } |
1866 | a8083063 | Iustin Pop | |
1867 | a8083063 | Iustin Pop | return result
|
1868 | a8083063 | Iustin Pop | |
1869 | a8083063 | Iustin Pop | |
1870 | ae5849b5 | Michael Hanselmann | class LUQueryConfigValues(NoHooksLU): |
1871 | ae5849b5 | Michael Hanselmann | """Return configuration values.
|
1872 | a8083063 | Iustin Pop |
|
1873 | a8083063 | Iustin Pop | """
|
1874 | a8083063 | Iustin Pop | _OP_REQP = [] |
1875 | 642339cf | Guido Trotter | REQ_BGL = False
|
1876 | 642339cf | Guido Trotter | |
1877 | 642339cf | Guido Trotter | def ExpandNames(self): |
1878 | 642339cf | Guido Trotter | self.needed_locks = {}
|
1879 | a8083063 | Iustin Pop | |
1880 | ae5849b5 | Michael Hanselmann | static_fields = ["cluster_name", "master_node"] |
1881 | ae5849b5 | Michael Hanselmann | _CheckOutputFields(static=static_fields, |
1882 | ae5849b5 | Michael Hanselmann | dynamic=[], |
1883 | ae5849b5 | Michael Hanselmann | selected=self.op.output_fields)
|
1884 | ae5849b5 | Michael Hanselmann | |
1885 | a8083063 | Iustin Pop | def CheckPrereq(self): |
1886 | a8083063 | Iustin Pop | """No prerequisites.
|
1887 | a8083063 | Iustin Pop |
|
1888 | a8083063 | Iustin Pop | """
|
1889 | a8083063 | Iustin Pop | pass
|
1890 | a8083063 | Iustin Pop | |
1891 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1892 | a8083063 | Iustin Pop | """Dump a representation of the cluster config to the standard output.
|
1893 | a8083063 | Iustin Pop |
|
1894 | a8083063 | Iustin Pop | """
|
1895 | ae5849b5 | Michael Hanselmann | values = [] |
1896 | ae5849b5 | Michael Hanselmann | for field in self.op.output_fields: |
1897 | ae5849b5 | Michael Hanselmann | if field == "cluster_name": |
1898 | ae5849b5 | Michael Hanselmann | values.append(self.cfg.GetClusterName())
|
1899 | ae5849b5 | Michael Hanselmann | elif field == "master_node": |
1900 | ae5849b5 | Michael Hanselmann | values.append(self.cfg.GetMasterNode())
|
1901 | ae5849b5 | Michael Hanselmann | else:
|
1902 | ae5849b5 | Michael Hanselmann | raise errors.ParameterError(field)
|
1903 | ae5849b5 | Michael Hanselmann | return values
|
1904 | a8083063 | Iustin Pop | |
1905 | a8083063 | Iustin Pop | |
1906 | a8083063 | Iustin Pop | class LUActivateInstanceDisks(NoHooksLU): |
1907 | a8083063 | Iustin Pop | """Bring up an instance's disks.
|
1908 | a8083063 | Iustin Pop |
|
1909 | a8083063 | Iustin Pop | """
|
1910 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name"]
|
1911 | f22a8ba3 | Guido Trotter | REQ_BGL = False
|
1912 | f22a8ba3 | Guido Trotter | |
1913 | f22a8ba3 | Guido Trotter | def ExpandNames(self): |
1914 | f22a8ba3 | Guido Trotter | self._ExpandAndLockInstance()
|
1915 | f22a8ba3 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
1916 | f22a8ba3 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
1917 | f22a8ba3 | Guido Trotter | |
1918 | f22a8ba3 | Guido Trotter | def DeclareLocks(self, level): |
1919 | f22a8ba3 | Guido Trotter | if level == locking.LEVEL_NODE:
|
1920 | f22a8ba3 | Guido Trotter | self._LockInstancesNodes()
|
1921 | a8083063 | Iustin Pop | |
1922 | a8083063 | Iustin Pop | def CheckPrereq(self): |
1923 | a8083063 | Iustin Pop | """Check prerequisites.
|
1924 | a8083063 | Iustin Pop |
|
1925 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
1926 | a8083063 | Iustin Pop |
|
1927 | a8083063 | Iustin Pop | """
|
1928 | f22a8ba3 | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
1929 | f22a8ba3 | Guido Trotter | assert self.instance is not None, \ |
1930 | f22a8ba3 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
1931 | a8083063 | Iustin Pop | |
1932 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
1933 | a8083063 | Iustin Pop | """Activate the disks.
|
1934 | a8083063 | Iustin Pop |
|
1935 | a8083063 | Iustin Pop | """
|
1936 | b9bddb6b | Iustin Pop | disks_ok, disks_info = _AssembleInstanceDisks(self, self.instance) |
1937 | a8083063 | Iustin Pop | if not disks_ok: |
1938 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Cannot activate block devices") |
1939 | a8083063 | Iustin Pop | |
1940 | a8083063 | Iustin Pop | return disks_info
|
1941 | a8083063 | Iustin Pop | |
1942 | a8083063 | Iustin Pop | |
1943 | b9bddb6b | Iustin Pop | def _AssembleInstanceDisks(lu, instance, ignore_secondaries=False): |
1944 | a8083063 | Iustin Pop | """Prepare the block devices for an instance.
|
1945 | a8083063 | Iustin Pop |
|
1946 | a8083063 | Iustin Pop | This sets up the block devices on all nodes.
|
1947 | a8083063 | Iustin Pop |
|
1948 | a8083063 | Iustin Pop | Args:
|
1949 | a8083063 | Iustin Pop | instance: a ganeti.objects.Instance object
|
1950 | a8083063 | Iustin Pop | ignore_secondaries: if true, errors on secondary nodes won't result
|
1951 | a8083063 | Iustin Pop | in an error return from the function
|
1952 | a8083063 | Iustin Pop |
|
1953 | a8083063 | Iustin Pop | Returns:
|
1954 | a8083063 | Iustin Pop | false if the operation failed
|
1955 | a8083063 | Iustin Pop | list of (host, instance_visible_name, node_visible_name) if the operation
|
1956 | a8083063 | Iustin Pop | suceeded with the mapping from node devices to instance devices
|
1957 | a8083063 | Iustin Pop | """
|
1958 | a8083063 | Iustin Pop | device_info = [] |
1959 | a8083063 | Iustin Pop | disks_ok = True
|
1960 | fdbd668d | Iustin Pop | iname = instance.name |
1961 | fdbd668d | Iustin Pop | # With the two passes mechanism we try to reduce the window of
|
1962 | fdbd668d | Iustin Pop | # opportunity for the race condition of switching DRBD to primary
|
1963 | fdbd668d | Iustin Pop | # before handshaking occured, but we do not eliminate it
|
1964 | fdbd668d | Iustin Pop | |
1965 | fdbd668d | Iustin Pop | # The proper fix would be to wait (with some limits) until the
|
1966 | fdbd668d | Iustin Pop | # connection has been made and drbd transitions from WFConnection
|
1967 | fdbd668d | Iustin Pop | # into any other network-connected state (Connected, SyncTarget,
|
1968 | fdbd668d | Iustin Pop | # SyncSource, etc.)
|
1969 | fdbd668d | Iustin Pop | |
1970 | fdbd668d | Iustin Pop | # 1st pass, assemble on all nodes in secondary mode
|
1971 | a8083063 | Iustin Pop | for inst_disk in instance.disks: |
1972 | a8083063 | Iustin Pop | for node, node_disk in inst_disk.ComputeNodeTree(instance.primary_node): |
1973 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(node_disk, node) |
1974 | 72737a7f | Iustin Pop | result = lu.rpc.call_blockdev_assemble(node, node_disk, iname, False)
|
1975 | a8083063 | Iustin Pop | if not result: |
1976 | f4bc1f2c | Michael Hanselmann | logger.Error("could not prepare block device %s on node %s"
|
1977 | fdbd668d | Iustin Pop | " (is_primary=False, pass=1)" % (inst_disk.iv_name, node))
|
1978 | fdbd668d | Iustin Pop | if not ignore_secondaries: |
1979 | a8083063 | Iustin Pop | disks_ok = False
|
1980 | fdbd668d | Iustin Pop | |
1981 | fdbd668d | Iustin Pop | # FIXME: race condition on drbd migration to primary
|
1982 | fdbd668d | Iustin Pop | |
1983 | fdbd668d | Iustin Pop | # 2nd pass, do only the primary node
|
1984 | fdbd668d | Iustin Pop | for inst_disk in instance.disks: |
1985 | fdbd668d | Iustin Pop | for node, node_disk in inst_disk.ComputeNodeTree(instance.primary_node): |
1986 | fdbd668d | Iustin Pop | if node != instance.primary_node:
|
1987 | fdbd668d | Iustin Pop | continue
|
1988 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(node_disk, node) |
1989 | 72737a7f | Iustin Pop | result = lu.rpc.call_blockdev_assemble(node, node_disk, iname, True)
|
1990 | fdbd668d | Iustin Pop | if not result: |
1991 | fdbd668d | Iustin Pop | logger.Error("could not prepare block device %s on node %s"
|
1992 | fdbd668d | Iustin Pop | " (is_primary=True, pass=2)" % (inst_disk.iv_name, node))
|
1993 | fdbd668d | Iustin Pop | disks_ok = False
|
1994 | fdbd668d | Iustin Pop | device_info.append((instance.primary_node, inst_disk.iv_name, result)) |
1995 | a8083063 | Iustin Pop | |
1996 | b352ab5b | Iustin Pop | # leave the disks configured for the primary node
|
1997 | b352ab5b | Iustin Pop | # this is a workaround that would be fixed better by
|
1998 | b352ab5b | Iustin Pop | # improving the logical/physical id handling
|
1999 | b352ab5b | Iustin Pop | for disk in instance.disks: |
2000 | b9bddb6b | Iustin Pop | lu.cfg.SetDiskID(disk, instance.primary_node) |
2001 | b352ab5b | Iustin Pop | |
2002 | a8083063 | Iustin Pop | return disks_ok, device_info
|
2003 | a8083063 | Iustin Pop | |
2004 | a8083063 | Iustin Pop | |
2005 | b9bddb6b | Iustin Pop | def _StartInstanceDisks(lu, instance, force): |
2006 | 3ecf6786 | Iustin Pop | """Start the disks of an instance.
|
2007 | 3ecf6786 | Iustin Pop |
|
2008 | 3ecf6786 | Iustin Pop | """
|
2009 | b9bddb6b | Iustin Pop | disks_ok, dummy = _AssembleInstanceDisks(lu, instance, |
2010 | fe7b0351 | Michael Hanselmann | ignore_secondaries=force) |
2011 | fe7b0351 | Michael Hanselmann | if not disks_ok: |
2012 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(lu, instance) |
2013 | fe7b0351 | Michael Hanselmann | if force is not None and not force: |
2014 | fe7b0351 | Michael Hanselmann | logger.Error("If the message above refers to a secondary node,"
|
2015 | fe7b0351 | Michael Hanselmann | " you can retry the operation using '--force'.")
|
2016 | 3ecf6786 | Iustin Pop | raise errors.OpExecError("Disk consistency error") |
2017 | fe7b0351 | Michael Hanselmann | |
2018 | fe7b0351 | Michael Hanselmann | |
2019 | a8083063 | Iustin Pop | class LUDeactivateInstanceDisks(NoHooksLU): |
2020 | a8083063 | Iustin Pop | """Shutdown an instance's disks.
|
2021 | a8083063 | Iustin Pop |
|
2022 | a8083063 | Iustin Pop | """
|
2023 | a8083063 | Iustin Pop | _OP_REQP = ["instance_name"]
|
2024 | f22a8ba3 | Guido Trotter | REQ_BGL = False
|
2025 | f22a8ba3 | Guido Trotter | |
2026 | f22a8ba3 | Guido Trotter | def ExpandNames(self): |
2027 | f22a8ba3 | Guido Trotter | self._ExpandAndLockInstance()
|
2028 | f22a8ba3 | Guido Trotter | self.needed_locks[locking.LEVEL_NODE] = []
|
2029 | f22a8ba3 | Guido Trotter | self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
|
2030 | f22a8ba3 | Guido Trotter | |
2031 | f22a8ba3 | Guido Trotter | def DeclareLocks(self, level): |
2032 | f22a8ba3 | Guido Trotter | if level == locking.LEVEL_NODE:
|
2033 | f22a8ba3 | Guido Trotter | self._LockInstancesNodes()
|
2034 | a8083063 | Iustin Pop | |
2035 | a8083063 | Iustin Pop | def CheckPrereq(self): |
2036 | a8083063 | Iustin Pop | """Check prerequisites.
|
2037 | a8083063 | Iustin Pop |
|
2038 | a8083063 | Iustin Pop | This checks that the instance is in the cluster.
|
2039 | a8083063 | Iustin Pop |
|
2040 | a8083063 | Iustin Pop | """
|
2041 | f22a8ba3 | Guido Trotter | self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
2042 | f22a8ba3 | Guido Trotter | assert self.instance is not None, \ |
2043 | f22a8ba3 | Guido Trotter | "Cannot retrieve locked instance %s" % self.op.instance_name |
2044 | a8083063 | Iustin Pop | |
2045 | a8083063 | Iustin Pop | def Exec(self, feedback_fn): |
2046 | a8083063 | Iustin Pop | """Deactivate the disks
|
2047 | a8083063 | Iustin Pop |
|
2048 | a8083063 | Iustin Pop | """
|
2049 | a8083063 | Iustin Pop | instance = self.instance
|
2050 | b9bddb6b | Iustin Pop | _SafeShutdownInstanceDisks(self, instance)
|
2051 | a8083063 | Iustin Pop | |
2052 | a8083063 | Iustin Pop | |
2053 | b9bddb6b | Iustin Pop | def _SafeShutdownInstanceDisks(lu, instance): |
2054 | 155d6c75 | Guido Trotter | """Shutdown block devices of an instance.
|
2055 | 155d6c75 | Guido Trotter |
|
2056 | 155d6c75 | Guido Trotter | This function checks if an instance is running, before calling
|
2057 | 155d6c75 | Guido Trotter | _ShutdownInstanceDisks.
|
2058 | 155d6c75 | Guido Trotter |
|
2059 | 155d6c75 | Guido Trotter | """
|
2060 | 72737a7f | Iustin Pop | ins_l = lu.rpc.call_instance_list([instance.primary_node], |
2061 | 72737a7f | Iustin Pop | [instance.hypervisor]) |
2062 | 155d6c75 | Guido Trotter | ins_l = ins_l[instance.primary_node] |
2063 | 155d6c75 | Guido Trotter | if not type(ins_l) is list: |
2064 | 155d6c75 | Guido Trotter | raise errors.OpExecError("Can't contact node '%s'" % |
2065 | 155d6c75 | Guido Trotter | instance.primary_node) |
2066 | 155d6c75 | Guido Trotter | |
2067 | 155d6c75 | Guido Trotter | if instance.name in ins_l: |
2068 | 155d6c75 | Guido Trotter | raise errors.OpExecError("Instance is running, can't shutdown" |
2069 | 155d6c75 | Guido Trotter | " block devices.")
|
2070 | 155d6c75 | Guido Trotter | |
2071 | b9bddb6b | Iustin Pop | _ShutdownInstanceDisks(lu, instance) |
2072 | a8083063 | Iustin Pop |