root / lib / cmdlib / cluster.py @ 9808764a
History | View | Annotate | Download (135.3 kB)
1 | 7352d33b | Thomas Thrainer | #
|
---|---|---|---|
2 | 7352d33b | Thomas Thrainer | #
|
3 | 7352d33b | Thomas Thrainer | |
4 | 8a5d326f | Jose A. Lopes | # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Google Inc.
|
5 | 7352d33b | Thomas Thrainer | #
|
6 | 7352d33b | Thomas Thrainer | # This program is free software; you can redistribute it and/or modify
|
7 | 7352d33b | Thomas Thrainer | # it under the terms of the GNU General Public License as published by
|
8 | 7352d33b | Thomas Thrainer | # the Free Software Foundation; either version 2 of the License, or
|
9 | 7352d33b | Thomas Thrainer | # (at your option) any later version.
|
10 | 7352d33b | Thomas Thrainer | #
|
11 | 7352d33b | Thomas Thrainer | # This program is distributed in the hope that it will be useful, but
|
12 | 7352d33b | Thomas Thrainer | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 7352d33b | Thomas Thrainer | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 7352d33b | Thomas Thrainer | # General Public License for more details.
|
15 | 7352d33b | Thomas Thrainer | #
|
16 | 7352d33b | Thomas Thrainer | # You should have received a copy of the GNU General Public License
|
17 | 7352d33b | Thomas Thrainer | # along with this program; if not, write to the Free Software
|
18 | 7352d33b | Thomas Thrainer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 7352d33b | Thomas Thrainer | # 02110-1301, USA.
|
20 | 7352d33b | Thomas Thrainer | |
21 | 7352d33b | Thomas Thrainer | |
22 | 7352d33b | Thomas Thrainer | """Logical units dealing with the cluster."""
|
23 | 7352d33b | Thomas Thrainer | |
24 | 7352d33b | Thomas Thrainer | import copy |
25 | 7352d33b | Thomas Thrainer | import itertools |
26 | 7352d33b | Thomas Thrainer | import logging |
27 | 7352d33b | Thomas Thrainer | import operator |
28 | 7352d33b | Thomas Thrainer | import os |
29 | 7352d33b | Thomas Thrainer | import re |
30 | 7352d33b | Thomas Thrainer | import time |
31 | 7352d33b | Thomas Thrainer | |
32 | 7352d33b | Thomas Thrainer | from ganeti import compat |
33 | 7352d33b | Thomas Thrainer | from ganeti import constants |
34 | 7352d33b | Thomas Thrainer | from ganeti import errors |
35 | 7352d33b | Thomas Thrainer | from ganeti import hypervisor |
36 | 7352d33b | Thomas Thrainer | from ganeti import locking |
37 | 7352d33b | Thomas Thrainer | from ganeti import masterd |
38 | 7352d33b | Thomas Thrainer | from ganeti import netutils |
39 | 7352d33b | Thomas Thrainer | from ganeti import objects |
40 | 7352d33b | Thomas Thrainer | from ganeti import opcodes |
41 | 7352d33b | Thomas Thrainer | from ganeti import pathutils |
42 | 7352d33b | Thomas Thrainer | from ganeti import query |
43 | 4869595d | Petr Pudlak | import ganeti.rpc.node as rpc |
44 | 7352d33b | Thomas Thrainer | from ganeti import runtime |
45 | 7352d33b | Thomas Thrainer | from ganeti import ssh |
46 | 7352d33b | Thomas Thrainer | from ganeti import uidpool |
47 | 7352d33b | Thomas Thrainer | from ganeti import utils |
48 | 7352d33b | Thomas Thrainer | from ganeti import vcluster |
49 | 7352d33b | Thomas Thrainer | |
50 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.base import NoHooksLU, QueryBase, LogicalUnit, \ |
51 | 7352d33b | Thomas Thrainer | ResultWithJobs
|
52 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.common import ShareAll, RunPostHook, \ |
53 | 5eacbcae | Thomas Thrainer | ComputeAncillaryFiles, RedistributeAncillaryFiles, UploadHelper, \ |
54 | 5eacbcae | Thomas Thrainer | GetWantedInstances, MergeAndVerifyHvState, MergeAndVerifyDiskState, \ |
55 | 5eacbcae | Thomas Thrainer | GetUpdatedIPolicy, ComputeNewInstanceViolations, GetUpdatedParams, \ |
56 | 5eacbcae | Thomas Thrainer | CheckOSParams, CheckHVParams, AdjustCandidatePool, CheckNodePVs, \ |
57 | 4e771a95 | Helga Velroyen | ComputeIPolicyInstanceViolation, AnnotateDiskParams, SupportsOob, \ |
58 | 294254b1 | Raffa Santi | CheckIpolicyVsDiskTemplates, CheckDiskAccessModeValidity, \ |
59 | 2ff6426b | Jose A. Lopes | CheckDiskAccessModeConsistency, CreateNewClientCert, \ |
60 | 4b75f8a4 | Jose A. Lopes | AddInstanceCommunicationNetworkOp, ConnectInstanceCommunicationNetworkOp |
61 | 7352d33b | Thomas Thrainer | |
62 | 7352d33b | Thomas Thrainer | import ganeti.masterd.instance |
63 | 7352d33b | Thomas Thrainer | |
64 | 7352d33b | Thomas Thrainer | |
65 | b3cc1646 | Helga Velroyen | def _UpdateMasterClientCert( |
66 | b3cc1646 | Helga Velroyen | lu, master_uuid, cluster, feedback_fn, |
67 | b3cc1646 | Helga Velroyen | client_cert=pathutils.NODED_CLIENT_CERT_FILE, |
68 | b3cc1646 | Helga Velroyen | client_cert_tmp=pathutils.NODED_CLIENT_CERT_FILE_TMP): |
69 | b3cc1646 | Helga Velroyen | """Renews the master's client certificate and propagates the config.
|
70 | b3cc1646 | Helga Velroyen |
|
71 | b3cc1646 | Helga Velroyen | @type lu: C{LogicalUnit}
|
72 | b3cc1646 | Helga Velroyen | @param lu: the logical unit holding the config
|
73 | b3cc1646 | Helga Velroyen | @type master_uuid: string
|
74 | b3cc1646 | Helga Velroyen | @param master_uuid: the master node's UUID
|
75 | b3cc1646 | Helga Velroyen | @type cluster: C{objects.Cluster}
|
76 | b3cc1646 | Helga Velroyen | @param cluster: the cluster's configuration
|
77 | b3cc1646 | Helga Velroyen | @type feedback_fn: function
|
78 | b3cc1646 | Helga Velroyen | @param feedback_fn: feedback functions for config updates
|
79 | b3cc1646 | Helga Velroyen | @type client_cert: string
|
80 | b3cc1646 | Helga Velroyen | @param client_cert: the path of the client certificate
|
81 | b3cc1646 | Helga Velroyen | @type client_cert_tmp: string
|
82 | b3cc1646 | Helga Velroyen | @param client_cert_tmp: the temporary path of the client certificate
|
83 | b3cc1646 | Helga Velroyen | @rtype: string
|
84 | b3cc1646 | Helga Velroyen | @return: the digest of the newly created client certificate
|
85 | b3cc1646 | Helga Velroyen |
|
86 | b3cc1646 | Helga Velroyen | """
|
87 | b3cc1646 | Helga Velroyen | client_digest = CreateNewClientCert(lu, master_uuid, filename=client_cert_tmp) |
88 | b3cc1646 | Helga Velroyen | utils.AddNodeToCandidateCerts(master_uuid, client_digest, |
89 | b3cc1646 | Helga Velroyen | cluster.candidate_certs) |
90 | b3cc1646 | Helga Velroyen | # This triggers an update of the config and distribution of it with the old
|
91 | b3cc1646 | Helga Velroyen | # SSL certificate
|
92 | b3cc1646 | Helga Velroyen | lu.cfg.Update(cluster, feedback_fn) |
93 | b3cc1646 | Helga Velroyen | |
94 | b3cc1646 | Helga Velroyen | utils.RemoveFile(client_cert) |
95 | b3cc1646 | Helga Velroyen | utils.RenameFile(client_cert_tmp, client_cert) |
96 | b3cc1646 | Helga Velroyen | return client_digest
|
97 | b3cc1646 | Helga Velroyen | |
98 | b3cc1646 | Helga Velroyen | |
99 | b3cc1646 | Helga Velroyen | class LUClusterRenewCrypto(NoHooksLU): |
100 | b3cc1646 | Helga Velroyen | """Renew the cluster's crypto tokens.
|
101 | b3cc1646 | Helga Velroyen |
|
102 | b3cc1646 | Helga Velroyen | Note that most of this operation is done in gnt_cluster.py, this LU only
|
103 | b3cc1646 | Helga Velroyen | takes care of the renewal of the client SSL certificates.
|
104 | b3cc1646 | Helga Velroyen |
|
105 | b3cc1646 | Helga Velroyen | """
|
106 | b3cc1646 | Helga Velroyen | def Exec(self, feedback_fn): |
107 | b3cc1646 | Helga Velroyen | master_uuid = self.cfg.GetMasterNode()
|
108 | b3cc1646 | Helga Velroyen | cluster = self.cfg.GetClusterInfo()
|
109 | b3cc1646 | Helga Velroyen | |
110 | b3cc1646 | Helga Velroyen | server_digest = utils.GetCertificateDigest( |
111 | b3cc1646 | Helga Velroyen | cert_filename=pathutils.NODED_CERT_FILE) |
112 | b3cc1646 | Helga Velroyen | utils.AddNodeToCandidateCerts("%s-SERVER" % master_uuid,
|
113 | b3cc1646 | Helga Velroyen | server_digest, |
114 | b3cc1646 | Helga Velroyen | cluster.candidate_certs) |
115 | b3cc1646 | Helga Velroyen | new_master_digest = _UpdateMasterClientCert(self, master_uuid, cluster,
|
116 | b3cc1646 | Helga Velroyen | feedback_fn) |
117 | b3cc1646 | Helga Velroyen | |
118 | b3cc1646 | Helga Velroyen | cluster.candidate_certs = {master_uuid: new_master_digest} |
119 | b3cc1646 | Helga Velroyen | nodes = self.cfg.GetAllNodesInfo()
|
120 | b3cc1646 | Helga Velroyen | for (node_uuid, node_info) in nodes.items(): |
121 | b3cc1646 | Helga Velroyen | if node_uuid != master_uuid:
|
122 | b3cc1646 | Helga Velroyen | new_digest = CreateNewClientCert(self, node_uuid)
|
123 | b3cc1646 | Helga Velroyen | if node_info.master_candidate:
|
124 | b3cc1646 | Helga Velroyen | cluster.candidate_certs[node_uuid] = new_digest |
125 | b3cc1646 | Helga Velroyen | # Trigger another update of the config now with the new master cert
|
126 | b3cc1646 | Helga Velroyen | self.cfg.Update(cluster, feedback_fn)
|
127 | b3cc1646 | Helga Velroyen | |
128 | b3cc1646 | Helga Velroyen | |
129 | 7352d33b | Thomas Thrainer | class LUClusterActivateMasterIp(NoHooksLU): |
130 | 7352d33b | Thomas Thrainer | """Activate the master IP on the master node.
|
131 | 7352d33b | Thomas Thrainer |
|
132 | 7352d33b | Thomas Thrainer | """
|
133 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
134 | 7352d33b | Thomas Thrainer | """Activate the master IP.
|
135 | 7352d33b | Thomas Thrainer |
|
136 | 7352d33b | Thomas Thrainer | """
|
137 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
138 | 7352d33b | Thomas Thrainer | ems = self.cfg.GetUseExternalMipScript()
|
139 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_activate_master_ip(master_params.uuid,
|
140 | 7352d33b | Thomas Thrainer | master_params, ems) |
141 | 7352d33b | Thomas Thrainer | result.Raise("Could not activate the master IP")
|
142 | 7352d33b | Thomas Thrainer | |
143 | 7352d33b | Thomas Thrainer | |
144 | 7352d33b | Thomas Thrainer | class LUClusterDeactivateMasterIp(NoHooksLU): |
145 | 7352d33b | Thomas Thrainer | """Deactivate the master IP on the master node.
|
146 | 7352d33b | Thomas Thrainer |
|
147 | 7352d33b | Thomas Thrainer | """
|
148 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
149 | 7352d33b | Thomas Thrainer | """Deactivate the master IP.
|
150 | 7352d33b | Thomas Thrainer |
|
151 | 7352d33b | Thomas Thrainer | """
|
152 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
153 | 7352d33b | Thomas Thrainer | ems = self.cfg.GetUseExternalMipScript()
|
154 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_deactivate_master_ip(master_params.uuid,
|
155 | 7352d33b | Thomas Thrainer | master_params, ems) |
156 | 7352d33b | Thomas Thrainer | result.Raise("Could not deactivate the master IP")
|
157 | 7352d33b | Thomas Thrainer | |
158 | 7352d33b | Thomas Thrainer | |
159 | 7352d33b | Thomas Thrainer | class LUClusterConfigQuery(NoHooksLU): |
160 | 7352d33b | Thomas Thrainer | """Return configuration values.
|
161 | 7352d33b | Thomas Thrainer |
|
162 | 7352d33b | Thomas Thrainer | """
|
163 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
164 | 7352d33b | Thomas Thrainer | |
165 | 7352d33b | Thomas Thrainer | def CheckArguments(self): |
166 | 5eacbcae | Thomas Thrainer | self.cq = ClusterQuery(None, self.op.output_fields, False) |
167 | 7352d33b | Thomas Thrainer | |
168 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
169 | 7352d33b | Thomas Thrainer | self.cq.ExpandNames(self) |
170 | 7352d33b | Thomas Thrainer | |
171 | 7352d33b | Thomas Thrainer | def DeclareLocks(self, level): |
172 | 7352d33b | Thomas Thrainer | self.cq.DeclareLocks(self, level) |
173 | 7352d33b | Thomas Thrainer | |
174 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
175 | 7352d33b | Thomas Thrainer | result = self.cq.OldStyleQuery(self) |
176 | 7352d33b | Thomas Thrainer | |
177 | 7352d33b | Thomas Thrainer | assert len(result) == 1 |
178 | 7352d33b | Thomas Thrainer | |
179 | 7352d33b | Thomas Thrainer | return result[0] |
180 | 7352d33b | Thomas Thrainer | |
181 | 7352d33b | Thomas Thrainer | |
182 | 7352d33b | Thomas Thrainer | class LUClusterDestroy(LogicalUnit): |
183 | 7352d33b | Thomas Thrainer | """Logical unit for destroying the cluster.
|
184 | 7352d33b | Thomas Thrainer |
|
185 | 7352d33b | Thomas Thrainer | """
|
186 | 7352d33b | Thomas Thrainer | HPATH = "cluster-destroy"
|
187 | 7352d33b | Thomas Thrainer | HTYPE = constants.HTYPE_CLUSTER |
188 | 7352d33b | Thomas Thrainer | |
189 | 7352d33b | Thomas Thrainer | def BuildHooksEnv(self): |
190 | 7352d33b | Thomas Thrainer | """Build hooks env.
|
191 | 7352d33b | Thomas Thrainer |
|
192 | 7352d33b | Thomas Thrainer | """
|
193 | 7352d33b | Thomas Thrainer | return {
|
194 | 7352d33b | Thomas Thrainer | "OP_TARGET": self.cfg.GetClusterName(), |
195 | 7352d33b | Thomas Thrainer | } |
196 | 7352d33b | Thomas Thrainer | |
197 | 7352d33b | Thomas Thrainer | def BuildHooksNodes(self): |
198 | 7352d33b | Thomas Thrainer | """Build hooks nodes.
|
199 | 7352d33b | Thomas Thrainer |
|
200 | 7352d33b | Thomas Thrainer | """
|
201 | 7352d33b | Thomas Thrainer | return ([], [])
|
202 | 7352d33b | Thomas Thrainer | |
203 | 7352d33b | Thomas Thrainer | def CheckPrereq(self): |
204 | 7352d33b | Thomas Thrainer | """Check prerequisites.
|
205 | 7352d33b | Thomas Thrainer |
|
206 | 7352d33b | Thomas Thrainer | This checks whether the cluster is empty.
|
207 | 7352d33b | Thomas Thrainer |
|
208 | 7352d33b | Thomas Thrainer | Any errors are signaled by raising errors.OpPrereqError.
|
209 | 7352d33b | Thomas Thrainer |
|
210 | 7352d33b | Thomas Thrainer | """
|
211 | 7352d33b | Thomas Thrainer | master = self.cfg.GetMasterNode()
|
212 | 7352d33b | Thomas Thrainer | |
213 | 7352d33b | Thomas Thrainer | nodelist = self.cfg.GetNodeList()
|
214 | 7352d33b | Thomas Thrainer | if len(nodelist) != 1 or nodelist[0] != master: |
215 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("There are still %d node(s) in" |
216 | 7352d33b | Thomas Thrainer | " this cluster." % (len(nodelist) - 1), |
217 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
218 | 7352d33b | Thomas Thrainer | instancelist = self.cfg.GetInstanceList()
|
219 | 7352d33b | Thomas Thrainer | if instancelist:
|
220 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("There are still %d instance(s) in" |
221 | 7352d33b | Thomas Thrainer | " this cluster." % len(instancelist), |
222 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
223 | 7352d33b | Thomas Thrainer | |
224 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
225 | 7352d33b | Thomas Thrainer | """Destroys the cluster.
|
226 | 7352d33b | Thomas Thrainer |
|
227 | 7352d33b | Thomas Thrainer | """
|
228 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
229 | 7352d33b | Thomas Thrainer | |
230 | 7352d33b | Thomas Thrainer | # Run post hooks on master node before it's removed
|
231 | 1c3231aa | Thomas Thrainer | RunPostHook(self, self.cfg.GetNodeName(master_params.uuid)) |
232 | 7352d33b | Thomas Thrainer | |
233 | 7352d33b | Thomas Thrainer | ems = self.cfg.GetUseExternalMipScript()
|
234 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_deactivate_master_ip(master_params.uuid,
|
235 | 7352d33b | Thomas Thrainer | master_params, ems) |
236 | c7dd65be | Klaus Aehlig | result.Warn("Error disabling the master IP address", self.LogWarning) |
237 | 1c3231aa | Thomas Thrainer | return master_params.uuid
|
238 | 7352d33b | Thomas Thrainer | |
239 | 7352d33b | Thomas Thrainer | |
240 | 7352d33b | Thomas Thrainer | class LUClusterPostInit(LogicalUnit): |
241 | 7352d33b | Thomas Thrainer | """Logical unit for running hooks after cluster initialization.
|
242 | 7352d33b | Thomas Thrainer |
|
243 | 7352d33b | Thomas Thrainer | """
|
244 | 7352d33b | Thomas Thrainer | HPATH = "cluster-init"
|
245 | 7352d33b | Thomas Thrainer | HTYPE = constants.HTYPE_CLUSTER |
246 | 7352d33b | Thomas Thrainer | |
247 | 25ea5b98 | Sebastian Gebhard | def CheckArguments(self): |
248 | 25ea5b98 | Sebastian Gebhard | self.master_uuid = self.cfg.GetMasterNode() |
249 | 25ea5b98 | Sebastian Gebhard | self.master_ndparams = self.cfg.GetNdParams(self.cfg.GetMasterNodeInfo()) |
250 | 25ea5b98 | Sebastian Gebhard | |
251 | 25ea5b98 | Sebastian Gebhard | # TODO: When Issue 584 is solved, and None is properly parsed when used
|
252 | 25ea5b98 | Sebastian Gebhard | # as a default value, ndparams.get(.., None) can be changed to
|
253 | 25ea5b98 | Sebastian Gebhard | # ndparams[..] to access the values directly
|
254 | 25ea5b98 | Sebastian Gebhard | |
255 | 25ea5b98 | Sebastian Gebhard | # OpenvSwitch: Warn user if link is missing
|
256 | 25ea5b98 | Sebastian Gebhard | if (self.master_ndparams[constants.ND_OVS] and not |
257 | 25ea5b98 | Sebastian Gebhard | self.master_ndparams.get(constants.ND_OVS_LINK, None)): |
258 | 25ea5b98 | Sebastian Gebhard | self.LogInfo("No physical interface for OpenvSwitch was given." |
259 | 25ea5b98 | Sebastian Gebhard | " OpenvSwitch will not have an outside connection. This"
|
260 | 25ea5b98 | Sebastian Gebhard | " might not be what you want.")
|
261 | 25ea5b98 | Sebastian Gebhard | |
262 | 7352d33b | Thomas Thrainer | def BuildHooksEnv(self): |
263 | 7352d33b | Thomas Thrainer | """Build hooks env.
|
264 | 7352d33b | Thomas Thrainer |
|
265 | 7352d33b | Thomas Thrainer | """
|
266 | 7352d33b | Thomas Thrainer | return {
|
267 | 7352d33b | Thomas Thrainer | "OP_TARGET": self.cfg.GetClusterName(), |
268 | 7352d33b | Thomas Thrainer | } |
269 | 7352d33b | Thomas Thrainer | |
270 | 7352d33b | Thomas Thrainer | def BuildHooksNodes(self): |
271 | 7352d33b | Thomas Thrainer | """Build hooks nodes.
|
272 | 7352d33b | Thomas Thrainer |
|
273 | 7352d33b | Thomas Thrainer | """
|
274 | 7352d33b | Thomas Thrainer | return ([], [self.cfg.GetMasterNode()]) |
275 | 7352d33b | Thomas Thrainer | |
276 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
277 | 25ea5b98 | Sebastian Gebhard | """Create and configure Open vSwitch
|
278 | 7352d33b | Thomas Thrainer |
|
279 | 7352d33b | Thomas Thrainer | """
|
280 | 25ea5b98 | Sebastian Gebhard | if self.master_ndparams[constants.ND_OVS]: |
281 | 25ea5b98 | Sebastian Gebhard | result = self.rpc.call_node_configure_ovs(
|
282 | 25ea5b98 | Sebastian Gebhard | self.master_uuid,
|
283 | 25ea5b98 | Sebastian Gebhard | self.master_ndparams[constants.ND_OVS_NAME],
|
284 | 25ea5b98 | Sebastian Gebhard | self.master_ndparams.get(constants.ND_OVS_LINK, None)) |
285 | 25ea5b98 | Sebastian Gebhard | result.Raise("Could not successully configure Open vSwitch")
|
286 | 5b6f9e35 | Helga Velroyen | |
287 | b3cc1646 | Helga Velroyen | cluster = self.cfg.GetClusterInfo()
|
288 | b3cc1646 | Helga Velroyen | _UpdateMasterClientCert(self, self.master_uuid, cluster, feedback_fn) |
289 | 5b6f9e35 | Helga Velroyen | |
290 | 7352d33b | Thomas Thrainer | return True |
291 | 7352d33b | Thomas Thrainer | |
292 | 7352d33b | Thomas Thrainer | |
293 | 5eacbcae | Thomas Thrainer | class ClusterQuery(QueryBase): |
294 | 7352d33b | Thomas Thrainer | FIELDS = query.CLUSTER_FIELDS |
295 | 7352d33b | Thomas Thrainer | |
296 | 7352d33b | Thomas Thrainer | #: Do not sort (there is only one item)
|
297 | 7352d33b | Thomas Thrainer | SORT_FIELD = None
|
298 | 7352d33b | Thomas Thrainer | |
299 | 7352d33b | Thomas Thrainer | def ExpandNames(self, lu): |
300 | 7352d33b | Thomas Thrainer | lu.needed_locks = {} |
301 | 7352d33b | Thomas Thrainer | |
302 | 7352d33b | Thomas Thrainer | # The following variables interact with _QueryBase._GetNames
|
303 | 7352d33b | Thomas Thrainer | self.wanted = locking.ALL_SET
|
304 | 7352d33b | Thomas Thrainer | self.do_locking = self.use_locking |
305 | 7352d33b | Thomas Thrainer | |
306 | 7352d33b | Thomas Thrainer | if self.do_locking: |
307 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Can not use locking for cluster queries", |
308 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
309 | 7352d33b | Thomas Thrainer | |
310 | 7352d33b | Thomas Thrainer | def DeclareLocks(self, lu, level): |
311 | 7352d33b | Thomas Thrainer | pass
|
312 | 7352d33b | Thomas Thrainer | |
313 | 7352d33b | Thomas Thrainer | def _GetQueryData(self, lu): |
314 | 7352d33b | Thomas Thrainer | """Computes the list of nodes and their attributes.
|
315 | 7352d33b | Thomas Thrainer |
|
316 | 7352d33b | Thomas Thrainer | """
|
317 | 7352d33b | Thomas Thrainer | # Locking is not used
|
318 | 7352d33b | Thomas Thrainer | assert not (compat.any(lu.glm.is_owned(level) |
319 | 7352d33b | Thomas Thrainer | for level in locking.LEVELS |
320 | 7352d33b | Thomas Thrainer | if level != locking.LEVEL_CLUSTER) or |
321 | 7352d33b | Thomas Thrainer | self.do_locking or self.use_locking) |
322 | 7352d33b | Thomas Thrainer | |
323 | 7352d33b | Thomas Thrainer | if query.CQ_CONFIG in self.requested_data: |
324 | 7352d33b | Thomas Thrainer | cluster = lu.cfg.GetClusterInfo() |
325 | 1c3231aa | Thomas Thrainer | nodes = lu.cfg.GetAllNodesInfo() |
326 | 7352d33b | Thomas Thrainer | else:
|
327 | 7352d33b | Thomas Thrainer | cluster = NotImplemented
|
328 | 1c3231aa | Thomas Thrainer | nodes = NotImplemented
|
329 | 7352d33b | Thomas Thrainer | |
330 | 7352d33b | Thomas Thrainer | if query.CQ_QUEUE_DRAINED in self.requested_data: |
331 | 7352d33b | Thomas Thrainer | drain_flag = os.path.exists(pathutils.JOB_QUEUE_DRAIN_FILE) |
332 | 7352d33b | Thomas Thrainer | else:
|
333 | 7352d33b | Thomas Thrainer | drain_flag = NotImplemented
|
334 | 7352d33b | Thomas Thrainer | |
335 | 7352d33b | Thomas Thrainer | if query.CQ_WATCHER_PAUSE in self.requested_data: |
336 | 1c3231aa | Thomas Thrainer | master_node_uuid = lu.cfg.GetMasterNode() |
337 | 7352d33b | Thomas Thrainer | |
338 | 1c3231aa | Thomas Thrainer | result = lu.rpc.call_get_watcher_pause(master_node_uuid) |
339 | 7352d33b | Thomas Thrainer | result.Raise("Can't retrieve watcher pause from master node '%s'" %
|
340 | 1c3231aa | Thomas Thrainer | lu.cfg.GetMasterNodeName()) |
341 | 7352d33b | Thomas Thrainer | |
342 | 7352d33b | Thomas Thrainer | watcher_pause = result.payload |
343 | 7352d33b | Thomas Thrainer | else:
|
344 | 7352d33b | Thomas Thrainer | watcher_pause = NotImplemented
|
345 | 7352d33b | Thomas Thrainer | |
346 | 1c3231aa | Thomas Thrainer | return query.ClusterQueryData(cluster, nodes, drain_flag, watcher_pause)
|
347 | 7352d33b | Thomas Thrainer | |
348 | 7352d33b | Thomas Thrainer | |
349 | 7352d33b | Thomas Thrainer | class LUClusterQuery(NoHooksLU): |
350 | 7352d33b | Thomas Thrainer | """Query cluster configuration.
|
351 | 7352d33b | Thomas Thrainer |
|
352 | 7352d33b | Thomas Thrainer | """
|
353 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
354 | 7352d33b | Thomas Thrainer | |
355 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
356 | 7352d33b | Thomas Thrainer | self.needed_locks = {}
|
357 | 7352d33b | Thomas Thrainer | |
358 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
359 | 7352d33b | Thomas Thrainer | """Return cluster config.
|
360 | 7352d33b | Thomas Thrainer |
|
361 | 7352d33b | Thomas Thrainer | """
|
362 | 7352d33b | Thomas Thrainer | cluster = self.cfg.GetClusterInfo()
|
363 | 7352d33b | Thomas Thrainer | os_hvp = {} |
364 | 7352d33b | Thomas Thrainer | |
365 | 7352d33b | Thomas Thrainer | # Filter just for enabled hypervisors
|
366 | 7352d33b | Thomas Thrainer | for os_name, hv_dict in cluster.os_hvp.items(): |
367 | 7352d33b | Thomas Thrainer | os_hvp[os_name] = {} |
368 | 7352d33b | Thomas Thrainer | for hv_name, hv_params in hv_dict.items(): |
369 | 7352d33b | Thomas Thrainer | if hv_name in cluster.enabled_hypervisors: |
370 | 7352d33b | Thomas Thrainer | os_hvp[os_name][hv_name] = hv_params |
371 | 7352d33b | Thomas Thrainer | |
372 | 7352d33b | Thomas Thrainer | # Convert ip_family to ip_version
|
373 | 7352d33b | Thomas Thrainer | primary_ip_version = constants.IP4_VERSION |
374 | 7352d33b | Thomas Thrainer | if cluster.primary_ip_family == netutils.IP6Address.family:
|
375 | 7352d33b | Thomas Thrainer | primary_ip_version = constants.IP6_VERSION |
376 | 7352d33b | Thomas Thrainer | |
377 | 7352d33b | Thomas Thrainer | result = { |
378 | 7352d33b | Thomas Thrainer | "software_version": constants.RELEASE_VERSION,
|
379 | 7352d33b | Thomas Thrainer | "protocol_version": constants.PROTOCOL_VERSION,
|
380 | 7352d33b | Thomas Thrainer | "config_version": constants.CONFIG_VERSION,
|
381 | 7352d33b | Thomas Thrainer | "os_api_version": max(constants.OS_API_VERSIONS), |
382 | 7352d33b | Thomas Thrainer | "export_version": constants.EXPORT_VERSION,
|
383 | 026f444f | Thomas Thrainer | "vcs_version": constants.VCS_VERSION,
|
384 | 7352d33b | Thomas Thrainer | "architecture": runtime.GetArchInfo(),
|
385 | 7352d33b | Thomas Thrainer | "name": cluster.cluster_name,
|
386 | 1c3231aa | Thomas Thrainer | "master": self.cfg.GetMasterNodeName(), |
387 | 7352d33b | Thomas Thrainer | "default_hypervisor": cluster.primary_hypervisor,
|
388 | 7352d33b | Thomas Thrainer | "enabled_hypervisors": cluster.enabled_hypervisors,
|
389 | 7352d33b | Thomas Thrainer | "hvparams": dict([(hypervisor_name, cluster.hvparams[hypervisor_name]) |
390 | 7352d33b | Thomas Thrainer | for hypervisor_name in cluster.enabled_hypervisors]), |
391 | 7352d33b | Thomas Thrainer | "os_hvp": os_hvp,
|
392 | 7352d33b | Thomas Thrainer | "beparams": cluster.beparams,
|
393 | 7352d33b | Thomas Thrainer | "osparams": cluster.osparams,
|
394 | 7352d33b | Thomas Thrainer | "ipolicy": cluster.ipolicy,
|
395 | 7352d33b | Thomas Thrainer | "nicparams": cluster.nicparams,
|
396 | 7352d33b | Thomas Thrainer | "ndparams": cluster.ndparams,
|
397 | 7352d33b | Thomas Thrainer | "diskparams": cluster.diskparams,
|
398 | 7352d33b | Thomas Thrainer | "candidate_pool_size": cluster.candidate_pool_size,
|
399 | 178ad717 | Klaus Aehlig | "max_running_jobs": cluster.max_running_jobs,
|
400 | 7352d33b | Thomas Thrainer | "master_netdev": cluster.master_netdev,
|
401 | 7352d33b | Thomas Thrainer | "master_netmask": cluster.master_netmask,
|
402 | 7352d33b | Thomas Thrainer | "use_external_mip_script": cluster.use_external_mip_script,
|
403 | 7352d33b | Thomas Thrainer | "volume_group_name": cluster.volume_group_name,
|
404 | 7352d33b | Thomas Thrainer | "drbd_usermode_helper": cluster.drbd_usermode_helper,
|
405 | 7352d33b | Thomas Thrainer | "file_storage_dir": cluster.file_storage_dir,
|
406 | 7352d33b | Thomas Thrainer | "shared_file_storage_dir": cluster.shared_file_storage_dir,
|
407 | 7352d33b | Thomas Thrainer | "maintain_node_health": cluster.maintain_node_health,
|
408 | 7352d33b | Thomas Thrainer | "ctime": cluster.ctime,
|
409 | 7352d33b | Thomas Thrainer | "mtime": cluster.mtime,
|
410 | 7352d33b | Thomas Thrainer | "uuid": cluster.uuid,
|
411 | 7352d33b | Thomas Thrainer | "tags": list(cluster.GetTags()), |
412 | 7352d33b | Thomas Thrainer | "uid_pool": cluster.uid_pool,
|
413 | 7352d33b | Thomas Thrainer | "default_iallocator": cluster.default_iallocator,
|
414 | 0359e5d0 | Spyros Trigazis | "default_iallocator_params": cluster.default_iallocator_params,
|
415 | 7352d33b | Thomas Thrainer | "reserved_lvs": cluster.reserved_lvs,
|
416 | 7352d33b | Thomas Thrainer | "primary_ip_version": primary_ip_version,
|
417 | 7352d33b | Thomas Thrainer | "prealloc_wipe_disks": cluster.prealloc_wipe_disks,
|
418 | 7352d33b | Thomas Thrainer | "hidden_os": cluster.hidden_os,
|
419 | 7352d33b | Thomas Thrainer | "blacklisted_os": cluster.blacklisted_os,
|
420 | fe782deb | Helga Velroyen | "enabled_disk_templates": cluster.enabled_disk_templates,
|
421 | 8a5d326f | Jose A. Lopes | "instance_communication_network": cluster.instance_communication_network,
|
422 | 7352d33b | Thomas Thrainer | } |
423 | 7352d33b | Thomas Thrainer | |
424 | 7352d33b | Thomas Thrainer | return result
|
425 | 7352d33b | Thomas Thrainer | |
426 | 7352d33b | Thomas Thrainer | |
427 | 7352d33b | Thomas Thrainer | class LUClusterRedistConf(NoHooksLU): |
428 | 7352d33b | Thomas Thrainer | """Force the redistribution of cluster configuration.
|
429 | 7352d33b | Thomas Thrainer |
|
430 | 7352d33b | Thomas Thrainer | This is a very simple LU.
|
431 | 7352d33b | Thomas Thrainer |
|
432 | 7352d33b | Thomas Thrainer | """
|
433 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
434 | 7352d33b | Thomas Thrainer | |
435 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
436 | 7352d33b | Thomas Thrainer | self.needed_locks = {
|
437 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE: locking.ALL_SET, |
438 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_ALLOC: locking.ALL_SET, |
439 | 7352d33b | Thomas Thrainer | } |
440 | 5eacbcae | Thomas Thrainer | self.share_locks = ShareAll()
|
441 | 7352d33b | Thomas Thrainer | |
442 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
443 | 7352d33b | Thomas Thrainer | """Redistribute the configuration.
|
444 | 7352d33b | Thomas Thrainer |
|
445 | 7352d33b | Thomas Thrainer | """
|
446 | 7352d33b | Thomas Thrainer | self.cfg.Update(self.cfg.GetClusterInfo(), feedback_fn) |
447 | 5eacbcae | Thomas Thrainer | RedistributeAncillaryFiles(self)
|
448 | 7352d33b | Thomas Thrainer | |
449 | 7352d33b | Thomas Thrainer | |
450 | 7352d33b | Thomas Thrainer | class LUClusterRename(LogicalUnit): |
451 | 7352d33b | Thomas Thrainer | """Rename the cluster.
|
452 | 7352d33b | Thomas Thrainer |
|
453 | 7352d33b | Thomas Thrainer | """
|
454 | 7352d33b | Thomas Thrainer | HPATH = "cluster-rename"
|
455 | 7352d33b | Thomas Thrainer | HTYPE = constants.HTYPE_CLUSTER |
456 | 7352d33b | Thomas Thrainer | |
457 | 7352d33b | Thomas Thrainer | def BuildHooksEnv(self): |
458 | 7352d33b | Thomas Thrainer | """Build hooks env.
|
459 | 7352d33b | Thomas Thrainer |
|
460 | 7352d33b | Thomas Thrainer | """
|
461 | 7352d33b | Thomas Thrainer | return {
|
462 | 7352d33b | Thomas Thrainer | "OP_TARGET": self.cfg.GetClusterName(), |
463 | 7352d33b | Thomas Thrainer | "NEW_NAME": self.op.name, |
464 | 7352d33b | Thomas Thrainer | } |
465 | 7352d33b | Thomas Thrainer | |
466 | 7352d33b | Thomas Thrainer | def BuildHooksNodes(self): |
467 | 7352d33b | Thomas Thrainer | """Build hooks nodes.
|
468 | 7352d33b | Thomas Thrainer |
|
469 | 7352d33b | Thomas Thrainer | """
|
470 | 7352d33b | Thomas Thrainer | return ([self.cfg.GetMasterNode()], self.cfg.GetNodeList()) |
471 | 7352d33b | Thomas Thrainer | |
472 | 7352d33b | Thomas Thrainer | def CheckPrereq(self): |
473 | 7352d33b | Thomas Thrainer | """Verify that the passed name is a valid one.
|
474 | 7352d33b | Thomas Thrainer |
|
475 | 7352d33b | Thomas Thrainer | """
|
476 | 7352d33b | Thomas Thrainer | hostname = netutils.GetHostname(name=self.op.name,
|
477 | 7352d33b | Thomas Thrainer | family=self.cfg.GetPrimaryIPFamily())
|
478 | 7352d33b | Thomas Thrainer | |
479 | 7352d33b | Thomas Thrainer | new_name = hostname.name |
480 | 7352d33b | Thomas Thrainer | self.ip = new_ip = hostname.ip
|
481 | 7352d33b | Thomas Thrainer | old_name = self.cfg.GetClusterName()
|
482 | 7352d33b | Thomas Thrainer | old_ip = self.cfg.GetMasterIP()
|
483 | 7352d33b | Thomas Thrainer | if new_name == old_name and new_ip == old_ip: |
484 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Neither the name nor the IP address of the" |
485 | 7352d33b | Thomas Thrainer | " cluster has changed",
|
486 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
487 | 7352d33b | Thomas Thrainer | if new_ip != old_ip:
|
488 | 7352d33b | Thomas Thrainer | if netutils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
|
489 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("The given cluster IP address (%s) is" |
490 | 7352d33b | Thomas Thrainer | " reachable on the network" %
|
491 | 7352d33b | Thomas Thrainer | new_ip, errors.ECODE_NOTUNIQUE) |
492 | 7352d33b | Thomas Thrainer | |
493 | 7352d33b | Thomas Thrainer | self.op.name = new_name
|
494 | 7352d33b | Thomas Thrainer | |
495 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
496 | 7352d33b | Thomas Thrainer | """Rename the cluster.
|
497 | 7352d33b | Thomas Thrainer |
|
498 | 7352d33b | Thomas Thrainer | """
|
499 | 7352d33b | Thomas Thrainer | clustername = self.op.name
|
500 | 7352d33b | Thomas Thrainer | new_ip = self.ip
|
501 | 7352d33b | Thomas Thrainer | |
502 | 7352d33b | Thomas Thrainer | # shutdown the master IP
|
503 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
504 | 7352d33b | Thomas Thrainer | ems = self.cfg.GetUseExternalMipScript()
|
505 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_deactivate_master_ip(master_params.uuid,
|
506 | 7352d33b | Thomas Thrainer | master_params, ems) |
507 | 7352d33b | Thomas Thrainer | result.Raise("Could not disable the master role")
|
508 | 7352d33b | Thomas Thrainer | |
509 | 7352d33b | Thomas Thrainer | try:
|
510 | 7352d33b | Thomas Thrainer | cluster = self.cfg.GetClusterInfo()
|
511 | 7352d33b | Thomas Thrainer | cluster.cluster_name = clustername |
512 | 7352d33b | Thomas Thrainer | cluster.master_ip = new_ip |
513 | 7352d33b | Thomas Thrainer | self.cfg.Update(cluster, feedback_fn)
|
514 | 7352d33b | Thomas Thrainer | |
515 | 7352d33b | Thomas Thrainer | # update the known hosts file
|
516 | 7352d33b | Thomas Thrainer | ssh.WriteKnownHostsFile(self.cfg, pathutils.SSH_KNOWN_HOSTS_FILE)
|
517 | 7352d33b | Thomas Thrainer | node_list = self.cfg.GetOnlineNodeList()
|
518 | 7352d33b | Thomas Thrainer | try:
|
519 | 1c3231aa | Thomas Thrainer | node_list.remove(master_params.uuid) |
520 | 7352d33b | Thomas Thrainer | except ValueError: |
521 | 7352d33b | Thomas Thrainer | pass
|
522 | 5eacbcae | Thomas Thrainer | UploadHelper(self, node_list, pathutils.SSH_KNOWN_HOSTS_FILE)
|
523 | 7352d33b | Thomas Thrainer | finally:
|
524 | 7352d33b | Thomas Thrainer | master_params.ip = new_ip |
525 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_activate_master_ip(master_params.uuid,
|
526 | 7352d33b | Thomas Thrainer | master_params, ems) |
527 | c7dd65be | Klaus Aehlig | result.Warn("Could not re-enable the master role on the master,"
|
528 | c7dd65be | Klaus Aehlig | " please restart manually", self.LogWarning) |
529 | 7352d33b | Thomas Thrainer | |
530 | 7352d33b | Thomas Thrainer | return clustername
|
531 | 7352d33b | Thomas Thrainer | |
532 | 7352d33b | Thomas Thrainer | |
533 | 7352d33b | Thomas Thrainer | class LUClusterRepairDiskSizes(NoHooksLU): |
534 | 7352d33b | Thomas Thrainer | """Verifies the cluster disks sizes.
|
535 | 7352d33b | Thomas Thrainer |
|
536 | 7352d33b | Thomas Thrainer | """
|
537 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
538 | 7352d33b | Thomas Thrainer | |
539 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
540 | 7352d33b | Thomas Thrainer | if self.op.instances: |
541 | da4a52a3 | Thomas Thrainer | (_, self.wanted_names) = GetWantedInstances(self, self.op.instances) |
542 | 7352d33b | Thomas Thrainer | # Not getting the node allocation lock as only a specific set of
|
543 | 7352d33b | Thomas Thrainer | # instances (and their nodes) is going to be acquired
|
544 | 7352d33b | Thomas Thrainer | self.needed_locks = {
|
545 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_RES: [], |
546 | 7352d33b | Thomas Thrainer | locking.LEVEL_INSTANCE: self.wanted_names,
|
547 | 7352d33b | Thomas Thrainer | } |
548 | 7352d33b | Thomas Thrainer | self.recalculate_locks[locking.LEVEL_NODE_RES] = constants.LOCKS_REPLACE
|
549 | 7352d33b | Thomas Thrainer | else:
|
550 | 7352d33b | Thomas Thrainer | self.wanted_names = None |
551 | 7352d33b | Thomas Thrainer | self.needed_locks = {
|
552 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_RES: locking.ALL_SET, |
553 | 7352d33b | Thomas Thrainer | locking.LEVEL_INSTANCE: locking.ALL_SET, |
554 | 7352d33b | Thomas Thrainer | |
555 | 7352d33b | Thomas Thrainer | # This opcode is acquires the node locks for all instances
|
556 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_ALLOC: locking.ALL_SET, |
557 | 7352d33b | Thomas Thrainer | } |
558 | 7352d33b | Thomas Thrainer | |
559 | 7352d33b | Thomas Thrainer | self.share_locks = {
|
560 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_RES: 1,
|
561 | 7352d33b | Thomas Thrainer | locking.LEVEL_INSTANCE: 0,
|
562 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_ALLOC: 1,
|
563 | 7352d33b | Thomas Thrainer | } |
564 | 7352d33b | Thomas Thrainer | |
565 | 7352d33b | Thomas Thrainer | def DeclareLocks(self, level): |
566 | 7352d33b | Thomas Thrainer | if level == locking.LEVEL_NODE_RES and self.wanted_names is not None: |
567 | 7352d33b | Thomas Thrainer | self._LockInstancesNodes(primary_only=True, level=level) |
568 | 7352d33b | Thomas Thrainer | |
569 | 7352d33b | Thomas Thrainer | def CheckPrereq(self): |
570 | 7352d33b | Thomas Thrainer | """Check prerequisites.
|
571 | 7352d33b | Thomas Thrainer |
|
572 | 7352d33b | Thomas Thrainer | This only checks the optional instance list against the existing names.
|
573 | 7352d33b | Thomas Thrainer |
|
574 | 7352d33b | Thomas Thrainer | """
|
575 | 7352d33b | Thomas Thrainer | if self.wanted_names is None: |
576 | 7352d33b | Thomas Thrainer | self.wanted_names = self.owned_locks(locking.LEVEL_INSTANCE) |
577 | 7352d33b | Thomas Thrainer | |
578 | 7352d33b | Thomas Thrainer | self.wanted_instances = \
|
579 | da4a52a3 | Thomas Thrainer | map(compat.snd, self.cfg.GetMultiInstanceInfoByName(self.wanted_names)) |
580 | 7352d33b | Thomas Thrainer | |
581 | 7352d33b | Thomas Thrainer | def _EnsureChildSizes(self, disk): |
582 | 7352d33b | Thomas Thrainer | """Ensure children of the disk have the needed disk size.
|
583 | 7352d33b | Thomas Thrainer |
|
584 | 7352d33b | Thomas Thrainer | This is valid mainly for DRBD8 and fixes an issue where the
|
585 | 7352d33b | Thomas Thrainer | children have smaller disk size.
|
586 | 7352d33b | Thomas Thrainer |
|
587 | 7352d33b | Thomas Thrainer | @param disk: an L{ganeti.objects.Disk} object
|
588 | 7352d33b | Thomas Thrainer |
|
589 | 7352d33b | Thomas Thrainer | """
|
590 | cd3b4ff4 | Helga Velroyen | if disk.dev_type == constants.DT_DRBD8:
|
591 | 7352d33b | Thomas Thrainer | assert disk.children, "Empty children for DRBD8?" |
592 | 7352d33b | Thomas Thrainer | fchild = disk.children[0]
|
593 | 7352d33b | Thomas Thrainer | mismatch = fchild.size < disk.size |
594 | 7352d33b | Thomas Thrainer | if mismatch:
|
595 | 7352d33b | Thomas Thrainer | self.LogInfo("Child disk has size %d, parent %d, fixing", |
596 | 7352d33b | Thomas Thrainer | fchild.size, disk.size) |
597 | 7352d33b | Thomas Thrainer | fchild.size = disk.size |
598 | 7352d33b | Thomas Thrainer | |
599 | 7352d33b | Thomas Thrainer | # and we recurse on this child only, not on the metadev
|
600 | 7352d33b | Thomas Thrainer | return self._EnsureChildSizes(fchild) or mismatch |
601 | 7352d33b | Thomas Thrainer | else:
|
602 | 7352d33b | Thomas Thrainer | return False |
603 | 7352d33b | Thomas Thrainer | |
604 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
605 | 7352d33b | Thomas Thrainer | """Verify the size of cluster disks.
|
606 | 7352d33b | Thomas Thrainer |
|
607 | 7352d33b | Thomas Thrainer | """
|
608 | 7352d33b | Thomas Thrainer | # TODO: check child disks too
|
609 | 7352d33b | Thomas Thrainer | # TODO: check differences in size between primary/secondary nodes
|
610 | 7352d33b | Thomas Thrainer | per_node_disks = {} |
611 | 7352d33b | Thomas Thrainer | for instance in self.wanted_instances: |
612 | 7352d33b | Thomas Thrainer | pnode = instance.primary_node |
613 | 7352d33b | Thomas Thrainer | if pnode not in per_node_disks: |
614 | 7352d33b | Thomas Thrainer | per_node_disks[pnode] = [] |
615 | 7352d33b | Thomas Thrainer | for idx, disk in enumerate(instance.disks): |
616 | 7352d33b | Thomas Thrainer | per_node_disks[pnode].append((instance, idx, disk)) |
617 | 7352d33b | Thomas Thrainer | |
618 | 7352d33b | Thomas Thrainer | assert not (frozenset(per_node_disks.keys()) - |
619 | 7352d33b | Thomas Thrainer | self.owned_locks(locking.LEVEL_NODE_RES)), \
|
620 | 7352d33b | Thomas Thrainer | "Not owning correct locks"
|
621 | 7352d33b | Thomas Thrainer | assert not self.owned_locks(locking.LEVEL_NODE) |
622 | 7352d33b | Thomas Thrainer | |
623 | 1c3231aa | Thomas Thrainer | es_flags = rpc.GetExclusiveStorageForNodes(self.cfg,
|
624 | 1c3231aa | Thomas Thrainer | per_node_disks.keys()) |
625 | 40d93e3b | Bernardo Dal Seno | |
626 | 7352d33b | Thomas Thrainer | changed = [] |
627 | 1c3231aa | Thomas Thrainer | for node_uuid, dskl in per_node_disks.items(): |
628 | 0c3d9c7c | Thomas Thrainer | if not dskl: |
629 | 0c3d9c7c | Thomas Thrainer | # no disks on the node
|
630 | 0c3d9c7c | Thomas Thrainer | continue
|
631 | 0c3d9c7c | Thomas Thrainer | |
632 | d66acf3d | Thomas Thrainer | newl = [([v[2].Copy()], v[0]) for v in dskl] |
633 | 1c3231aa | Thomas Thrainer | node_name = self.cfg.GetNodeName(node_uuid)
|
634 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_blockdev_getdimensions(node_uuid, newl)
|
635 | 7352d33b | Thomas Thrainer | if result.fail_msg:
|
636 | 6ef8077e | Bernardo Dal Seno | self.LogWarning("Failure in blockdev_getdimensions call to node" |
637 | 1c3231aa | Thomas Thrainer | " %s, ignoring", node_name)
|
638 | 7352d33b | Thomas Thrainer | continue
|
639 | 7352d33b | Thomas Thrainer | if len(result.payload) != len(dskl): |
640 | 7352d33b | Thomas Thrainer | logging.warning("Invalid result from node %s: len(dksl)=%d,"
|
641 | 1c3231aa | Thomas Thrainer | " result.payload=%s", node_name, len(dskl), |
642 | 1c3231aa | Thomas Thrainer | result.payload) |
643 | 7352d33b | Thomas Thrainer | self.LogWarning("Invalid result from node %s, ignoring node results", |
644 | 1c3231aa | Thomas Thrainer | node_name) |
645 | 7352d33b | Thomas Thrainer | continue
|
646 | 6ef8077e | Bernardo Dal Seno | for ((instance, idx, disk), dimensions) in zip(dskl, result.payload): |
647 | 6ef8077e | Bernardo Dal Seno | if dimensions is None: |
648 | 7352d33b | Thomas Thrainer | self.LogWarning("Disk %d of instance %s did not return size" |
649 | 7352d33b | Thomas Thrainer | " information, ignoring", idx, instance.name)
|
650 | 7352d33b | Thomas Thrainer | continue
|
651 | 6ef8077e | Bernardo Dal Seno | if not isinstance(dimensions, (tuple, list)): |
652 | 6ef8077e | Bernardo Dal Seno | self.LogWarning("Disk %d of instance %s did not return valid" |
653 | 6ef8077e | Bernardo Dal Seno | " dimension information, ignoring", idx,
|
654 | 6ef8077e | Bernardo Dal Seno | instance.name) |
655 | 6ef8077e | Bernardo Dal Seno | continue
|
656 | 40d93e3b | Bernardo Dal Seno | (size, spindles) = dimensions |
657 | 7352d33b | Thomas Thrainer | if not isinstance(size, (int, long)): |
658 | 7352d33b | Thomas Thrainer | self.LogWarning("Disk %d of instance %s did not return valid" |
659 | 7352d33b | Thomas Thrainer | " size information, ignoring", idx, instance.name)
|
660 | 7352d33b | Thomas Thrainer | continue
|
661 | 7352d33b | Thomas Thrainer | size = size >> 20
|
662 | 7352d33b | Thomas Thrainer | if size != disk.size:
|
663 | 7352d33b | Thomas Thrainer | self.LogInfo("Disk %d of instance %s has mismatched size," |
664 | 7352d33b | Thomas Thrainer | " correcting: recorded %d, actual %d", idx,
|
665 | 7352d33b | Thomas Thrainer | instance.name, disk.size, size) |
666 | 7352d33b | Thomas Thrainer | disk.size = size |
667 | 7352d33b | Thomas Thrainer | self.cfg.Update(instance, feedback_fn)
|
668 | 40d93e3b | Bernardo Dal Seno | changed.append((instance.name, idx, "size", size))
|
669 | 1c3231aa | Thomas Thrainer | if es_flags[node_uuid]:
|
670 | 40d93e3b | Bernardo Dal Seno | if spindles is None: |
671 | 40d93e3b | Bernardo Dal Seno | self.LogWarning("Disk %d of instance %s did not return valid" |
672 | 40d93e3b | Bernardo Dal Seno | " spindles information, ignoring", idx,
|
673 | 40d93e3b | Bernardo Dal Seno | instance.name) |
674 | 40d93e3b | Bernardo Dal Seno | elif disk.spindles is None or disk.spindles != spindles: |
675 | 40d93e3b | Bernardo Dal Seno | self.LogInfo("Disk %d of instance %s has mismatched spindles," |
676 | 40d93e3b | Bernardo Dal Seno | " correcting: recorded %s, actual %s",
|
677 | 40d93e3b | Bernardo Dal Seno | idx, instance.name, disk.spindles, spindles) |
678 | 40d93e3b | Bernardo Dal Seno | disk.spindles = spindles |
679 | 40d93e3b | Bernardo Dal Seno | self.cfg.Update(instance, feedback_fn)
|
680 | 40d93e3b | Bernardo Dal Seno | changed.append((instance.name, idx, "spindles", disk.spindles))
|
681 | 7352d33b | Thomas Thrainer | if self._EnsureChildSizes(disk): |
682 | 7352d33b | Thomas Thrainer | self.cfg.Update(instance, feedback_fn)
|
683 | 40d93e3b | Bernardo Dal Seno | changed.append((instance.name, idx, "size", disk.size))
|
684 | 7352d33b | Thomas Thrainer | return changed
|
685 | 7352d33b | Thomas Thrainer | |
686 | 7352d33b | Thomas Thrainer | |
687 | 7352d33b | Thomas Thrainer | def _ValidateNetmask(cfg, netmask): |
688 | 7352d33b | Thomas Thrainer | """Checks if a netmask is valid.
|
689 | 7352d33b | Thomas Thrainer |
|
690 | 7352d33b | Thomas Thrainer | @type cfg: L{config.ConfigWriter}
|
691 | 9808764a | Jose A. Lopes | @param cfg: cluster configuration
|
692 | 7352d33b | Thomas Thrainer | @type netmask: int
|
693 | 9808764a | Jose A. Lopes | @param netmask: netmask to be verified
|
694 | 7352d33b | Thomas Thrainer | @raise errors.OpPrereqError: if the validation fails
|
695 | 7352d33b | Thomas Thrainer |
|
696 | 7352d33b | Thomas Thrainer | """
|
697 | 7352d33b | Thomas Thrainer | ip_family = cfg.GetPrimaryIPFamily() |
698 | 7352d33b | Thomas Thrainer | try:
|
699 | 7352d33b | Thomas Thrainer | ipcls = netutils.IPAddress.GetClassFromIpFamily(ip_family) |
700 | 7352d33b | Thomas Thrainer | except errors.ProgrammerError:
|
701 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Invalid primary ip family: %s." % |
702 | 7352d33b | Thomas Thrainer | ip_family, errors.ECODE_INVAL) |
703 | 7352d33b | Thomas Thrainer | if not ipcls.ValidateNetmask(netmask): |
704 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("CIDR netmask (%s) not valid" % |
705 | 7352d33b | Thomas Thrainer | (netmask), errors.ECODE_INVAL) |
706 | 7352d33b | Thomas Thrainer | |
707 | 7352d33b | Thomas Thrainer | |
708 | e8b5640e | Helga Velroyen | def CheckFileBasedStoragePathVsEnabledDiskTemplates( |
709 | e8b5640e | Helga Velroyen | logging_warn_fn, file_storage_dir, enabled_disk_templates, |
710 | e8b5640e | Helga Velroyen | file_disk_template): |
711 | e8b5640e | Helga Velroyen | """Checks whether the given file-based storage directory is acceptable.
|
712 | e8b5640e | Helga Velroyen |
|
713 | e8b5640e | Helga Velroyen | Note: This function is public, because it is also used in bootstrap.py.
|
714 | 3039e2dc | Helga Velroyen |
|
715 | 3039e2dc | Helga Velroyen | @type logging_warn_fn: function
|
716 | 3039e2dc | Helga Velroyen | @param logging_warn_fn: function which accepts a string and logs it
|
717 | 3039e2dc | Helga Velroyen | @type file_storage_dir: string
|
718 | 3039e2dc | Helga Velroyen | @param file_storage_dir: the directory to be used for file-based instances
|
719 | 3039e2dc | Helga Velroyen | @type enabled_disk_templates: list of string
|
720 | 3039e2dc | Helga Velroyen | @param enabled_disk_templates: the list of enabled disk templates
|
721 | e8b5640e | Helga Velroyen | @type file_disk_template: string
|
722 | e8b5640e | Helga Velroyen | @param file_disk_template: the file-based disk template for which the
|
723 | e8b5640e | Helga Velroyen | path should be checked
|
724 | 3039e2dc | Helga Velroyen |
|
725 | 3039e2dc | Helga Velroyen | """
|
726 | 5a904197 | Santi Raffa | assert (file_disk_template in utils.storage.GetDiskTemplatesOfStorageTypes( |
727 | 5a904197 | Santi Raffa | constants.ST_FILE, constants.ST_SHARED_FILE |
728 | 5a904197 | Santi Raffa | )) |
729 | e8b5640e | Helga Velroyen | file_storage_enabled = file_disk_template in enabled_disk_templates
|
730 | 3039e2dc | Helga Velroyen | if file_storage_dir is not None: |
731 | 3039e2dc | Helga Velroyen | if file_storage_dir == "": |
732 | 3039e2dc | Helga Velroyen | if file_storage_enabled:
|
733 | e8b5640e | Helga Velroyen | raise errors.OpPrereqError(
|
734 | e8b5640e | Helga Velroyen | "Unsetting the '%s' storage directory while having '%s' storage"
|
735 | e8b5640e | Helga Velroyen | " enabled is not permitted." %
|
736 | e8b5640e | Helga Velroyen | (file_disk_template, file_disk_template)) |
737 | 3039e2dc | Helga Velroyen | else:
|
738 | 3039e2dc | Helga Velroyen | if not file_storage_enabled: |
739 | e8b5640e | Helga Velroyen | logging_warn_fn( |
740 | e8b5640e | Helga Velroyen | "Specified a %s storage directory, although %s storage is not"
|
741 | e8b5640e | Helga Velroyen | " enabled." % (file_disk_template, file_disk_template))
|
742 | 3039e2dc | Helga Velroyen | else:
|
743 | e8b5640e | Helga Velroyen | raise errors.ProgrammerError("Received %s storage dir with value" |
744 | e8b5640e | Helga Velroyen | " 'None'." % file_disk_template)
|
745 | e8b5640e | Helga Velroyen | |
746 | e8b5640e | Helga Velroyen | |
747 | e8b5640e | Helga Velroyen | def CheckFileStoragePathVsEnabledDiskTemplates( |
748 | e8b5640e | Helga Velroyen | logging_warn_fn, file_storage_dir, enabled_disk_templates): |
749 | e8b5640e | Helga Velroyen | """Checks whether the given file storage directory is acceptable.
|
750 | e8b5640e | Helga Velroyen |
|
751 | e8b5640e | Helga Velroyen | @see: C{CheckFileBasedStoragePathVsEnabledDiskTemplates}
|
752 | e8b5640e | Helga Velroyen |
|
753 | e8b5640e | Helga Velroyen | """
|
754 | e8b5640e | Helga Velroyen | CheckFileBasedStoragePathVsEnabledDiskTemplates( |
755 | e8b5640e | Helga Velroyen | logging_warn_fn, file_storage_dir, enabled_disk_templates, |
756 | e8b5640e | Helga Velroyen | constants.DT_FILE) |
757 | e8b5640e | Helga Velroyen | |
758 | e8b5640e | Helga Velroyen | |
759 | e8b5640e | Helga Velroyen | def CheckSharedFileStoragePathVsEnabledDiskTemplates( |
760 | e8b5640e | Helga Velroyen | logging_warn_fn, file_storage_dir, enabled_disk_templates): |
761 | e8b5640e | Helga Velroyen | """Checks whether the given shared file storage directory is acceptable.
|
762 | e8b5640e | Helga Velroyen |
|
763 | e8b5640e | Helga Velroyen | @see: C{CheckFileBasedStoragePathVsEnabledDiskTemplates}
|
764 | e8b5640e | Helga Velroyen |
|
765 | e8b5640e | Helga Velroyen | """
|
766 | e8b5640e | Helga Velroyen | CheckFileBasedStoragePathVsEnabledDiskTemplates( |
767 | e8b5640e | Helga Velroyen | logging_warn_fn, file_storage_dir, enabled_disk_templates, |
768 | e8b5640e | Helga Velroyen | constants.DT_SHARED_FILE) |
769 | 3039e2dc | Helga Velroyen | |
770 | 3039e2dc | Helga Velroyen | |
771 | 7352d33b | Thomas Thrainer | class LUClusterSetParams(LogicalUnit): |
772 | 7352d33b | Thomas Thrainer | """Change the parameters of the cluster.
|
773 | 7352d33b | Thomas Thrainer |
|
774 | 7352d33b | Thomas Thrainer | """
|
775 | 7352d33b | Thomas Thrainer | HPATH = "cluster-modify"
|
776 | 7352d33b | Thomas Thrainer | HTYPE = constants.HTYPE_CLUSTER |
777 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
778 | 7352d33b | Thomas Thrainer | |
779 | 7352d33b | Thomas Thrainer | def CheckArguments(self): |
780 | 7352d33b | Thomas Thrainer | """Check parameters
|
781 | 7352d33b | Thomas Thrainer |
|
782 | 7352d33b | Thomas Thrainer | """
|
783 | 7352d33b | Thomas Thrainer | if self.op.uid_pool: |
784 | 7352d33b | Thomas Thrainer | uidpool.CheckUidPool(self.op.uid_pool)
|
785 | 7352d33b | Thomas Thrainer | |
786 | 7352d33b | Thomas Thrainer | if self.op.add_uids: |
787 | 7352d33b | Thomas Thrainer | uidpool.CheckUidPool(self.op.add_uids)
|
788 | 7352d33b | Thomas Thrainer | |
789 | 7352d33b | Thomas Thrainer | if self.op.remove_uids: |
790 | 7352d33b | Thomas Thrainer | uidpool.CheckUidPool(self.op.remove_uids)
|
791 | 7352d33b | Thomas Thrainer | |
792 | 7352d33b | Thomas Thrainer | if self.op.master_netmask is not None: |
793 | 7352d33b | Thomas Thrainer | _ValidateNetmask(self.cfg, self.op.master_netmask) |
794 | 7352d33b | Thomas Thrainer | |
795 | 7352d33b | Thomas Thrainer | if self.op.diskparams: |
796 | 7352d33b | Thomas Thrainer | for dt_params in self.op.diskparams.values(): |
797 | 7352d33b | Thomas Thrainer | utils.ForceDictType(dt_params, constants.DISK_DT_TYPES) |
798 | 7352d33b | Thomas Thrainer | try:
|
799 | 7352d33b | Thomas Thrainer | utils.VerifyDictOptions(self.op.diskparams, constants.DISK_DT_DEFAULTS)
|
800 | 294254b1 | Raffa Santi | CheckDiskAccessModeValidity(self.op.diskparams)
|
801 | 7352d33b | Thomas Thrainer | except errors.OpPrereqError, err:
|
802 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("While verify diskparams options: %s" % err, |
803 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
804 | 7352d33b | Thomas Thrainer | |
805 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
806 | 7352d33b | Thomas Thrainer | # FIXME: in the future maybe other cluster params won't require checking on
|
807 | 7352d33b | Thomas Thrainer | # all nodes to be modified.
|
808 | 7352d33b | Thomas Thrainer | # FIXME: This opcode changes cluster-wide settings. Is acquiring all
|
809 | 7352d33b | Thomas Thrainer | # resource locks the right thing, shouldn't it be the BGL instead?
|
810 | 7352d33b | Thomas Thrainer | self.needed_locks = {
|
811 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE: locking.ALL_SET, |
812 | 7352d33b | Thomas Thrainer | locking.LEVEL_INSTANCE: locking.ALL_SET, |
813 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODEGROUP: locking.ALL_SET, |
814 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_ALLOC: locking.ALL_SET, |
815 | 7352d33b | Thomas Thrainer | } |
816 | 5eacbcae | Thomas Thrainer | self.share_locks = ShareAll()
|
817 | 7352d33b | Thomas Thrainer | |
818 | 7352d33b | Thomas Thrainer | def BuildHooksEnv(self): |
819 | 7352d33b | Thomas Thrainer | """Build hooks env.
|
820 | 7352d33b | Thomas Thrainer |
|
821 | 7352d33b | Thomas Thrainer | """
|
822 | 7352d33b | Thomas Thrainer | return {
|
823 | 7352d33b | Thomas Thrainer | "OP_TARGET": self.cfg.GetClusterName(), |
824 | 7352d33b | Thomas Thrainer | "NEW_VG_NAME": self.op.vg_name, |
825 | 7352d33b | Thomas Thrainer | } |
826 | 7352d33b | Thomas Thrainer | |
827 | 7352d33b | Thomas Thrainer | def BuildHooksNodes(self): |
828 | 7352d33b | Thomas Thrainer | """Build hooks nodes.
|
829 | 7352d33b | Thomas Thrainer |
|
830 | 7352d33b | Thomas Thrainer | """
|
831 | 7352d33b | Thomas Thrainer | mn = self.cfg.GetMasterNode()
|
832 | 7352d33b | Thomas Thrainer | return ([mn], [mn])
|
833 | 7352d33b | Thomas Thrainer | |
834 | 1c3231aa | Thomas Thrainer | def _CheckVgName(self, node_uuids, enabled_disk_templates, |
835 | 1bb99a33 | Bernardo Dal Seno | new_enabled_disk_templates): |
836 | 1bb99a33 | Bernardo Dal Seno | """Check the consistency of the vg name on all nodes and in case it gets
|
837 | 1bb99a33 | Bernardo Dal Seno | unset whether there are instances still using it.
|
838 | 7352d33b | Thomas Thrainer |
|
839 | 7352d33b | Thomas Thrainer | """
|
840 | c89eb67d | Helga Velroyen | lvm_is_enabled = utils.IsLvmEnabled(enabled_disk_templates) |
841 | c89eb67d | Helga Velroyen | lvm_gets_enabled = utils.LvmGetsEnabled(enabled_disk_templates, |
842 | c89eb67d | Helga Velroyen | new_enabled_disk_templates) |
843 | c89eb67d | Helga Velroyen | current_vg_name = self.cfg.GetVGName()
|
844 | c89eb67d | Helga Velroyen | |
845 | c89eb67d | Helga Velroyen | if self.op.vg_name == '': |
846 | c89eb67d | Helga Velroyen | if lvm_is_enabled:
|
847 | c89eb67d | Helga Velroyen | raise errors.OpPrereqError("Cannot unset volume group if lvm-based" |
848 | c89eb67d | Helga Velroyen | " disk templates are or get enabled.")
|
849 | c89eb67d | Helga Velroyen | |
850 | c89eb67d | Helga Velroyen | if self.op.vg_name is None: |
851 | c89eb67d | Helga Velroyen | if current_vg_name is None and lvm_is_enabled: |
852 | c89eb67d | Helga Velroyen | raise errors.OpPrereqError("Please specify a volume group when" |
853 | c89eb67d | Helga Velroyen | " enabling lvm-based disk-templates.")
|
854 | c89eb67d | Helga Velroyen | |
855 | 7352d33b | Thomas Thrainer | if self.op.vg_name is not None and not self.op.vg_name: |
856 | cd3b4ff4 | Helga Velroyen | if self.cfg.HasAnyDiskOfType(constants.DT_PLAIN): |
857 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Cannot disable lvm storage while lvm-based" |
858 | 7352d33b | Thomas Thrainer | " instances exist", errors.ECODE_INVAL)
|
859 | 7352d33b | Thomas Thrainer | |
860 | c89eb67d | Helga Velroyen | if (self.op.vg_name is not None and lvm_is_enabled) or \ |
861 | c89eb67d | Helga Velroyen | (self.cfg.GetVGName() is not None and lvm_gets_enabled): |
862 | 1c3231aa | Thomas Thrainer | self._CheckVgNameOnNodes(node_uuids)
|
863 | 1bb99a33 | Bernardo Dal Seno | |
864 | 1c3231aa | Thomas Thrainer | def _CheckVgNameOnNodes(self, node_uuids): |
865 | 1bb99a33 | Bernardo Dal Seno | """Check the status of the volume group on each node.
|
866 | 1bb99a33 | Bernardo Dal Seno |
|
867 | 1bb99a33 | Bernardo Dal Seno | """
|
868 | 1c3231aa | Thomas Thrainer | vglist = self.rpc.call_vg_list(node_uuids)
|
869 | 1c3231aa | Thomas Thrainer | for node_uuid in node_uuids: |
870 | 1c3231aa | Thomas Thrainer | msg = vglist[node_uuid].fail_msg |
871 | 1bb99a33 | Bernardo Dal Seno | if msg:
|
872 | 1bb99a33 | Bernardo Dal Seno | # ignoring down node
|
873 | 1bb99a33 | Bernardo Dal Seno | self.LogWarning("Error while gathering data on node %s" |
874 | 1c3231aa | Thomas Thrainer | " (ignoring node): %s",
|
875 | 1c3231aa | Thomas Thrainer | self.cfg.GetNodeName(node_uuid), msg)
|
876 | 1bb99a33 | Bernardo Dal Seno | continue
|
877 | 1c3231aa | Thomas Thrainer | vgstatus = utils.CheckVolumeGroupSize(vglist[node_uuid].payload, |
878 | 1bb99a33 | Bernardo Dal Seno | self.op.vg_name,
|
879 | 1bb99a33 | Bernardo Dal Seno | constants.MIN_VG_SIZE) |
880 | 1bb99a33 | Bernardo Dal Seno | if vgstatus:
|
881 | 1bb99a33 | Bernardo Dal Seno | raise errors.OpPrereqError("Error on node '%s': %s" % |
882 | 1c3231aa | Thomas Thrainer | (self.cfg.GetNodeName(node_uuid), vgstatus),
|
883 | 1c3231aa | Thomas Thrainer | errors.ECODE_ENVIRON) |
884 | 1bb99a33 | Bernardo Dal Seno | |
885 | c89eb67d | Helga Velroyen | @staticmethod
|
886 | 87e23f2d | Helga Velroyen | def _GetDiskTemplateSetsInner(op_enabled_disk_templates, |
887 | 87e23f2d | Helga Velroyen | old_enabled_disk_templates): |
888 | 6e513917 | Helga Velroyen | """Computes three sets of disk templates.
|
889 | 6e513917 | Helga Velroyen |
|
890 | 6e513917 | Helga Velroyen | @see: C{_GetDiskTemplateSets} for more details.
|
891 | 1bb99a33 | Bernardo Dal Seno |
|
892 | 1bb99a33 | Bernardo Dal Seno | """
|
893 | 1bb99a33 | Bernardo Dal Seno | enabled_disk_templates = None
|
894 | 1bb99a33 | Bernardo Dal Seno | new_enabled_disk_templates = [] |
895 | 6e513917 | Helga Velroyen | disabled_disk_templates = [] |
896 | c89eb67d | Helga Velroyen | if op_enabled_disk_templates:
|
897 | c89eb67d | Helga Velroyen | enabled_disk_templates = op_enabled_disk_templates |
898 | 1bb99a33 | Bernardo Dal Seno | new_enabled_disk_templates = \ |
899 | 5808df30 | Helga Velroyen | list(set(enabled_disk_templates) |
900 | 5808df30 | Helga Velroyen | - set(old_enabled_disk_templates))
|
901 | 6e513917 | Helga Velroyen | disabled_disk_templates = \ |
902 | 5808df30 | Helga Velroyen | list(set(old_enabled_disk_templates) |
903 | 5808df30 | Helga Velroyen | - set(enabled_disk_templates))
|
904 | 1bb99a33 | Bernardo Dal Seno | else:
|
905 | c89eb67d | Helga Velroyen | enabled_disk_templates = old_enabled_disk_templates |
906 | 6e513917 | Helga Velroyen | return (enabled_disk_templates, new_enabled_disk_templates,
|
907 | 6e513917 | Helga Velroyen | disabled_disk_templates) |
908 | 1bb99a33 | Bernardo Dal Seno | |
909 | 87e23f2d | Helga Velroyen | def _GetDiskTemplateSets(self, cluster): |
910 | 6e513917 | Helga Velroyen | """Computes three sets of disk templates.
|
911 | 6e513917 | Helga Velroyen |
|
912 | 6e513917 | Helga Velroyen | The three sets are:
|
913 | 6e513917 | Helga Velroyen | - disk templates that will be enabled after this operation (no matter if
|
914 | 6e513917 | Helga Velroyen | they were enabled before or not)
|
915 | 6e513917 | Helga Velroyen | - disk templates that get enabled by this operation (thus haven't been
|
916 | 6e513917 | Helga Velroyen | enabled before.)
|
917 | 6e513917 | Helga Velroyen | - disk templates that get disabled by this operation
|
918 | c89eb67d | Helga Velroyen |
|
919 | c89eb67d | Helga Velroyen | """
|
920 | 87e23f2d | Helga Velroyen | return self._GetDiskTemplateSetsInner(self.op.enabled_disk_templates, |
921 | 87e23f2d | Helga Velroyen | cluster.enabled_disk_templates) |
922 | c89eb67d | Helga Velroyen | |
923 | 33a6464e | Helga Velroyen | def _CheckIpolicy(self, cluster, enabled_disk_templates): |
924 | 1532b078 | Helga Velroyen | """Checks the ipolicy.
|
925 | 1532b078 | Helga Velroyen |
|
926 | 1532b078 | Helga Velroyen | @type cluster: C{objects.Cluster}
|
927 | 1532b078 | Helga Velroyen | @param cluster: the cluster's configuration
|
928 | 33a6464e | Helga Velroyen | @type enabled_disk_templates: list of string
|
929 | 33a6464e | Helga Velroyen | @param enabled_disk_templates: list of (possibly newly) enabled disk
|
930 | 33a6464e | Helga Velroyen | templates
|
931 | 1532b078 | Helga Velroyen |
|
932 | 1532b078 | Helga Velroyen | """
|
933 | 33a6464e | Helga Velroyen | # FIXME: write unit tests for this
|
934 | 1532b078 | Helga Velroyen | if self.op.ipolicy: |
935 | 1532b078 | Helga Velroyen | self.new_ipolicy = GetUpdatedIPolicy(cluster.ipolicy, self.op.ipolicy, |
936 | 1532b078 | Helga Velroyen | group_policy=False)
|
937 | 1532b078 | Helga Velroyen | |
938 | 4e771a95 | Helga Velroyen | CheckIpolicyVsDiskTemplates(self.new_ipolicy,
|
939 | 4e771a95 | Helga Velroyen | enabled_disk_templates) |
940 | 33a6464e | Helga Velroyen | |
941 | 1532b078 | Helga Velroyen | all_instances = self.cfg.GetAllInstancesInfo().values()
|
942 | 1532b078 | Helga Velroyen | violations = set()
|
943 | 1532b078 | Helga Velroyen | for group in self.cfg.GetAllNodeGroupsInfo().values(): |
944 | 1532b078 | Helga Velroyen | instances = frozenset([inst for inst in all_instances |
945 | 1532b078 | Helga Velroyen | if compat.any(nuuid in group.members |
946 | 1532b078 | Helga Velroyen | for nuuid in inst.all_nodes)]) |
947 | 1532b078 | Helga Velroyen | new_ipolicy = objects.FillIPolicy(self.new_ipolicy, group.ipolicy)
|
948 | 1532b078 | Helga Velroyen | ipol = masterd.instance.CalculateGroupIPolicy(cluster, group) |
949 | 1532b078 | Helga Velroyen | new = ComputeNewInstanceViolations(ipol, new_ipolicy, instances, |
950 | 1532b078 | Helga Velroyen | self.cfg)
|
951 | 1532b078 | Helga Velroyen | if new:
|
952 | 1532b078 | Helga Velroyen | violations.update(new) |
953 | 1532b078 | Helga Velroyen | |
954 | 1532b078 | Helga Velroyen | if violations:
|
955 | 1532b078 | Helga Velroyen | self.LogWarning("After the ipolicy change the following instances" |
956 | 1532b078 | Helga Velroyen | " violate them: %s",
|
957 | 1532b078 | Helga Velroyen | utils.CommaJoin(utils.NiceSort(violations))) |
958 | 33a6464e | Helga Velroyen | else:
|
959 | 4e771a95 | Helga Velroyen | CheckIpolicyVsDiskTemplates(cluster.ipolicy, |
960 | 4e771a95 | Helga Velroyen | enabled_disk_templates) |
961 | 1532b078 | Helga Velroyen | |
962 | 31ccfc0e | Helga Velroyen | def _CheckDrbdHelperOnNodes(self, drbd_helper, node_uuids): |
963 | 31ccfc0e | Helga Velroyen | """Checks whether the set DRBD helper actually exists on the nodes.
|
964 | 31ccfc0e | Helga Velroyen |
|
965 | 31ccfc0e | Helga Velroyen | @type drbd_helper: string
|
966 | 31ccfc0e | Helga Velroyen | @param drbd_helper: path of the drbd usermode helper binary
|
967 | 31ccfc0e | Helga Velroyen | @type node_uuids: list of strings
|
968 | 31ccfc0e | Helga Velroyen | @param node_uuids: list of node UUIDs to check for the helper
|
969 | 31ccfc0e | Helga Velroyen |
|
970 | 31ccfc0e | Helga Velroyen | """
|
971 | 31ccfc0e | Helga Velroyen | # checks given drbd helper on all nodes
|
972 | 31ccfc0e | Helga Velroyen | helpers = self.rpc.call_drbd_helper(node_uuids)
|
973 | 31ccfc0e | Helga Velroyen | for (_, ninfo) in self.cfg.GetMultiNodeInfo(node_uuids): |
974 | 31ccfc0e | Helga Velroyen | if ninfo.offline:
|
975 | 31ccfc0e | Helga Velroyen | self.LogInfo("Not checking drbd helper on offline node %s", |
976 | 31ccfc0e | Helga Velroyen | ninfo.name) |
977 | 31ccfc0e | Helga Velroyen | continue
|
978 | 31ccfc0e | Helga Velroyen | msg = helpers[ninfo.uuid].fail_msg |
979 | 31ccfc0e | Helga Velroyen | if msg:
|
980 | 31ccfc0e | Helga Velroyen | raise errors.OpPrereqError("Error checking drbd helper on node" |
981 | 31ccfc0e | Helga Velroyen | " '%s': %s" % (ninfo.name, msg),
|
982 | 31ccfc0e | Helga Velroyen | errors.ECODE_ENVIRON) |
983 | 31ccfc0e | Helga Velroyen | node_helper = helpers[ninfo.uuid].payload |
984 | 31ccfc0e | Helga Velroyen | if node_helper != drbd_helper:
|
985 | 31ccfc0e | Helga Velroyen | raise errors.OpPrereqError("Error on node '%s': drbd helper is %s" % |
986 | 31ccfc0e | Helga Velroyen | (ninfo.name, node_helper), |
987 | 31ccfc0e | Helga Velroyen | errors.ECODE_ENVIRON) |
988 | 31ccfc0e | Helga Velroyen | |
989 | 31ccfc0e | Helga Velroyen | def _CheckDrbdHelper(self, node_uuids, drbd_enabled, drbd_gets_enabled): |
990 | 7c577910 | Helga Velroyen | """Check the DRBD usermode helper.
|
991 | 1bb99a33 | Bernardo Dal Seno |
|
992 | 7c577910 | Helga Velroyen | @type node_uuids: list of strings
|
993 | 7c577910 | Helga Velroyen | @param node_uuids: a list of nodes' UUIDs
|
994 | 31ccfc0e | Helga Velroyen | @type drbd_enabled: boolean
|
995 | 31ccfc0e | Helga Velroyen | @param drbd_enabled: whether DRBD will be enabled after this operation
|
996 | 31ccfc0e | Helga Velroyen | (no matter if it was disabled before or not)
|
997 | 31ccfc0e | Helga Velroyen | @type drbd_gets_enabled: boolen
|
998 | 31ccfc0e | Helga Velroyen | @param drbd_gets_enabled: true if DRBD was disabled before this
|
999 | 31ccfc0e | Helga Velroyen | operation, but will be enabled afterwards
|
1000 | 1bb99a33 | Bernardo Dal Seno |
|
1001 | 1bb99a33 | Bernardo Dal Seno | """
|
1002 | 31ccfc0e | Helga Velroyen | if self.op.drbd_helper == '': |
1003 | 31ccfc0e | Helga Velroyen | if drbd_enabled:
|
1004 | 31ccfc0e | Helga Velroyen | raise errors.OpPrereqError("Cannot disable drbd helper while" |
1005 | 31ccfc0e | Helga Velroyen | " DRBD is enabled.")
|
1006 | cd3b4ff4 | Helga Velroyen | if self.cfg.HasAnyDiskOfType(constants.DT_DRBD8): |
1007 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Cannot disable drbd helper while" |
1008 | 7352d33b | Thomas Thrainer | " drbd-based instances exist",
|
1009 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
1010 | 7352d33b | Thomas Thrainer | |
1011 | 31ccfc0e | Helga Velroyen | else:
|
1012 | 31ccfc0e | Helga Velroyen | if self.op.drbd_helper is not None and drbd_enabled: |
1013 | 31ccfc0e | Helga Velroyen | self._CheckDrbdHelperOnNodes(self.op.drbd_helper, node_uuids) |
1014 | 31ccfc0e | Helga Velroyen | else:
|
1015 | 31ccfc0e | Helga Velroyen | if drbd_gets_enabled:
|
1016 | 31ccfc0e | Helga Velroyen | current_drbd_helper = self.cfg.GetClusterInfo().drbd_usermode_helper
|
1017 | 31ccfc0e | Helga Velroyen | if current_drbd_helper is not None: |
1018 | 31ccfc0e | Helga Velroyen | self._CheckDrbdHelperOnNodes(current_drbd_helper, node_uuids)
|
1019 | 31ccfc0e | Helga Velroyen | else:
|
1020 | 31ccfc0e | Helga Velroyen | raise errors.OpPrereqError("Cannot enable DRBD without a" |
1021 | 31ccfc0e | Helga Velroyen | " DRBD usermode helper set.")
|
1022 | 7c577910 | Helga Velroyen | |
1023 | c2e984e2 | Helga Velroyen | def _CheckInstancesOfDisabledDiskTemplates( |
1024 | c2e984e2 | Helga Velroyen | self, disabled_disk_templates):
|
1025 | 5808df30 | Helga Velroyen | """Check whether we try to disable a disk template that is in use.
|
1026 | c2e984e2 | Helga Velroyen |
|
1027 | c2e984e2 | Helga Velroyen | @type disabled_disk_templates: list of string
|
1028 | c2e984e2 | Helga Velroyen | @param disabled_disk_templates: list of disk templates that are going to
|
1029 | c2e984e2 | Helga Velroyen | be disabled by this operation
|
1030 | c2e984e2 | Helga Velroyen |
|
1031 | c2e984e2 | Helga Velroyen | """
|
1032 | c2e984e2 | Helga Velroyen | for disk_template in disabled_disk_templates: |
1033 | c2e984e2 | Helga Velroyen | if self.cfg.HasAnyDiskOfType(disk_template): |
1034 | c2e984e2 | Helga Velroyen | raise errors.OpPrereqError(
|
1035 | c2e984e2 | Helga Velroyen | "Cannot disable disk template '%s', because there is at least one"
|
1036 | c2e984e2 | Helga Velroyen | " instance using it." % disk_template)
|
1037 | c2e984e2 | Helga Velroyen | |
1038 | 11eeb1b9 | Jose A. Lopes | @staticmethod
|
1039 | 11eeb1b9 | Jose A. Lopes | def _CheckInstanceCommunicationNetwork(network, warning_fn): |
1040 | 11eeb1b9 | Jose A. Lopes | """Check whether an existing network is configured for instance
|
1041 | 11eeb1b9 | Jose A. Lopes | communication.
|
1042 | 11eeb1b9 | Jose A. Lopes |
|
1043 | 11eeb1b9 | Jose A. Lopes | Checks whether an existing network is configured with the
|
1044 | 11eeb1b9 | Jose A. Lopes | parameters that are advisable for instance communication, and
|
1045 | 11eeb1b9 | Jose A. Lopes | otherwise issue security warnings.
|
1046 | 11eeb1b9 | Jose A. Lopes |
|
1047 | 11eeb1b9 | Jose A. Lopes | @type network: L{ganeti.objects.Network}
|
1048 | 11eeb1b9 | Jose A. Lopes | @param network: L{ganeti.objects.Network} object whose
|
1049 | 11eeb1b9 | Jose A. Lopes | configuration is being checked
|
1050 | 11eeb1b9 | Jose A. Lopes | @type warning_fn: function
|
1051 | 11eeb1b9 | Jose A. Lopes | @param warning_fn: function used to print warnings
|
1052 | 11eeb1b9 | Jose A. Lopes | @rtype: None
|
1053 | 11eeb1b9 | Jose A. Lopes | @return: None
|
1054 | 11eeb1b9 | Jose A. Lopes |
|
1055 | 11eeb1b9 | Jose A. Lopes | """
|
1056 | 11eeb1b9 | Jose A. Lopes | def _MaybeWarn(err, val, default): |
1057 | 11eeb1b9 | Jose A. Lopes | if val != default:
|
1058 | 11eeb1b9 | Jose A. Lopes | warning_fn("Supplied instance communication network '%s' %s '%s',"
|
1059 | 11eeb1b9 | Jose A. Lopes | " this might pose a security risk (default is '%s').",
|
1060 | 11eeb1b9 | Jose A. Lopes | network.name, err, val, default) |
1061 | 11eeb1b9 | Jose A. Lopes | |
1062 | 11eeb1b9 | Jose A. Lopes | if network.network is None: |
1063 | 11eeb1b9 | Jose A. Lopes | raise errors.OpPrereqError("Supplied instance communication network '%s'" |
1064 | 11eeb1b9 | Jose A. Lopes | " must have an IPv4 network address.",
|
1065 | 11eeb1b9 | Jose A. Lopes | network.name) |
1066 | 11eeb1b9 | Jose A. Lopes | |
1067 | 11eeb1b9 | Jose A. Lopes | _MaybeWarn("has an IPv4 gateway", network.gateway, None) |
1068 | 11eeb1b9 | Jose A. Lopes | _MaybeWarn("has a non-standard IPv4 network address", network.network,
|
1069 | 11eeb1b9 | Jose A. Lopes | constants.INSTANCE_COMMUNICATION_NETWORK4) |
1070 | 11eeb1b9 | Jose A. Lopes | _MaybeWarn("has an IPv6 gateway", network.gateway6, None) |
1071 | 11eeb1b9 | Jose A. Lopes | _MaybeWarn("has a non-standard IPv6 network address", network.network6,
|
1072 | 11eeb1b9 | Jose A. Lopes | constants.INSTANCE_COMMUNICATION_NETWORK6) |
1073 | 11eeb1b9 | Jose A. Lopes | _MaybeWarn("has a non-standard MAC prefix", network.mac_prefix,
|
1074 | 11eeb1b9 | Jose A. Lopes | constants.INSTANCE_COMMUNICATION_MAC_PREFIX) |
1075 | 11eeb1b9 | Jose A. Lopes | |
1076 | 7c577910 | Helga Velroyen | def CheckPrereq(self): |
1077 | 7c577910 | Helga Velroyen | """Check prerequisites.
|
1078 | 7c577910 | Helga Velroyen |
|
1079 | 7c577910 | Helga Velroyen | This checks whether the given params don't conflict and
|
1080 | 7c577910 | Helga Velroyen | if the given volume group is valid.
|
1081 | 7c577910 | Helga Velroyen |
|
1082 | 7c577910 | Helga Velroyen | """
|
1083 | 1c3231aa | Thomas Thrainer | node_uuids = self.owned_locks(locking.LEVEL_NODE)
|
1084 | 1bb99a33 | Bernardo Dal Seno | self.cluster = cluster = self.cfg.GetClusterInfo() |
1085 | 7352d33b | Thomas Thrainer | |
1086 | 1c3231aa | Thomas Thrainer | vm_capable_node_uuids = [node.uuid |
1087 | 1c3231aa | Thomas Thrainer | for node in self.cfg.GetAllNodesInfo().values() |
1088 | 1c3231aa | Thomas Thrainer | if node.uuid in node_uuids and node.vm_capable] |
1089 | 7352d33b | Thomas Thrainer | |
1090 | 6e513917 | Helga Velroyen | (enabled_disk_templates, new_enabled_disk_templates, |
1091 | 5808df30 | Helga Velroyen | disabled_disk_templates) = self._GetDiskTemplateSets(cluster)
|
1092 | 6e513917 | Helga Velroyen | self._CheckInstancesOfDisabledDiskTemplates(disabled_disk_templates)
|
1093 | 1bb99a33 | Bernardo Dal Seno | |
1094 | 1c3231aa | Thomas Thrainer | self._CheckVgName(vm_capable_node_uuids, enabled_disk_templates,
|
1095 | 1bb99a33 | Bernardo Dal Seno | new_enabled_disk_templates) |
1096 | 7352d33b | Thomas Thrainer | |
1097 | 3039e2dc | Helga Velroyen | if self.op.file_storage_dir is not None: |
1098 | 3039e2dc | Helga Velroyen | CheckFileStoragePathVsEnabledDiskTemplates( |
1099 | 3039e2dc | Helga Velroyen | self.LogWarning, self.op.file_storage_dir, enabled_disk_templates) |
1100 | 3039e2dc | Helga Velroyen | |
1101 | 4e6cfd11 | Helga Velroyen | if self.op.shared_file_storage_dir is not None: |
1102 | 4e6cfd11 | Helga Velroyen | CheckSharedFileStoragePathVsEnabledDiskTemplates( |
1103 | 4e6cfd11 | Helga Velroyen | self.LogWarning, self.op.shared_file_storage_dir, |
1104 | 4e6cfd11 | Helga Velroyen | enabled_disk_templates) |
1105 | 4e6cfd11 | Helga Velroyen | |
1106 | 31ccfc0e | Helga Velroyen | drbd_enabled = constants.DT_DRBD8 in enabled_disk_templates
|
1107 | 31ccfc0e | Helga Velroyen | drbd_gets_enabled = constants.DT_DRBD8 in new_enabled_disk_templates
|
1108 | 31ccfc0e | Helga Velroyen | self._CheckDrbdHelper(node_uuids, drbd_enabled, drbd_gets_enabled)
|
1109 | 7352d33b | Thomas Thrainer | |
1110 | 7352d33b | Thomas Thrainer | # validate params changes
|
1111 | 7352d33b | Thomas Thrainer | if self.op.beparams: |
1112 | 7352d33b | Thomas Thrainer | objects.UpgradeBeParams(self.op.beparams)
|
1113 | 7352d33b | Thomas Thrainer | utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
|
1114 | 7352d33b | Thomas Thrainer | self.new_beparams = cluster.SimpleFillBE(self.op.beparams) |
1115 | 7352d33b | Thomas Thrainer | |
1116 | 7352d33b | Thomas Thrainer | if self.op.ndparams: |
1117 | 7352d33b | Thomas Thrainer | utils.ForceDictType(self.op.ndparams, constants.NDS_PARAMETER_TYPES)
|
1118 | 7352d33b | Thomas Thrainer | self.new_ndparams = cluster.SimpleFillND(self.op.ndparams) |
1119 | 7352d33b | Thomas Thrainer | |
1120 | 7352d33b | Thomas Thrainer | # TODO: we need a more general way to handle resetting
|
1121 | 7352d33b | Thomas Thrainer | # cluster-level parameters to default values
|
1122 | 7352d33b | Thomas Thrainer | if self.new_ndparams["oob_program"] == "": |
1123 | 7352d33b | Thomas Thrainer | self.new_ndparams["oob_program"] = \ |
1124 | 7352d33b | Thomas Thrainer | constants.NDC_DEFAULTS[constants.ND_OOB_PROGRAM] |
1125 | 7352d33b | Thomas Thrainer | |
1126 | 7352d33b | Thomas Thrainer | if self.op.hv_state: |
1127 | 5eacbcae | Thomas Thrainer | new_hv_state = MergeAndVerifyHvState(self.op.hv_state,
|
1128 | 5eacbcae | Thomas Thrainer | self.cluster.hv_state_static)
|
1129 | 7352d33b | Thomas Thrainer | self.new_hv_state = dict((hv, cluster.SimpleFillHvState(values)) |
1130 | 7352d33b | Thomas Thrainer | for hv, values in new_hv_state.items()) |
1131 | 7352d33b | Thomas Thrainer | |
1132 | 7352d33b | Thomas Thrainer | if self.op.disk_state: |
1133 | 5eacbcae | Thomas Thrainer | new_disk_state = MergeAndVerifyDiskState(self.op.disk_state,
|
1134 | 5eacbcae | Thomas Thrainer | self.cluster.disk_state_static)
|
1135 | 7352d33b | Thomas Thrainer | self.new_disk_state = \
|
1136 | 7352d33b | Thomas Thrainer | dict((storage, dict((name, cluster.SimpleFillDiskState(values)) |
1137 | 7352d33b | Thomas Thrainer | for name, values in svalues.items())) |
1138 | 7352d33b | Thomas Thrainer | for storage, svalues in new_disk_state.items()) |
1139 | 7352d33b | Thomas Thrainer | |
1140 | 33a6464e | Helga Velroyen | self._CheckIpolicy(cluster, enabled_disk_templates)
|
1141 | 7352d33b | Thomas Thrainer | |
1142 | 7352d33b | Thomas Thrainer | if self.op.nicparams: |
1143 | 7352d33b | Thomas Thrainer | utils.ForceDictType(self.op.nicparams, constants.NICS_PARAMETER_TYPES)
|
1144 | 7352d33b | Thomas Thrainer | self.new_nicparams = cluster.SimpleFillNIC(self.op.nicparams) |
1145 | 7352d33b | Thomas Thrainer | objects.NIC.CheckParameterSyntax(self.new_nicparams)
|
1146 | 7352d33b | Thomas Thrainer | nic_errors = [] |
1147 | 7352d33b | Thomas Thrainer | |
1148 | 7352d33b | Thomas Thrainer | # check all instances for consistency
|
1149 | 7352d33b | Thomas Thrainer | for instance in self.cfg.GetAllInstancesInfo().values(): |
1150 | 7352d33b | Thomas Thrainer | for nic_idx, nic in enumerate(instance.nics): |
1151 | 7352d33b | Thomas Thrainer | params_copy = copy.deepcopy(nic.nicparams) |
1152 | 7352d33b | Thomas Thrainer | params_filled = objects.FillDict(self.new_nicparams, params_copy)
|
1153 | 7352d33b | Thomas Thrainer | |
1154 | 7352d33b | Thomas Thrainer | # check parameter syntax
|
1155 | 7352d33b | Thomas Thrainer | try:
|
1156 | 7352d33b | Thomas Thrainer | objects.NIC.CheckParameterSyntax(params_filled) |
1157 | 7352d33b | Thomas Thrainer | except errors.ConfigurationError, err:
|
1158 | 7352d33b | Thomas Thrainer | nic_errors.append("Instance %s, nic/%d: %s" %
|
1159 | 7352d33b | Thomas Thrainer | (instance.name, nic_idx, err)) |
1160 | 7352d33b | Thomas Thrainer | |
1161 | 7352d33b | Thomas Thrainer | # if we're moving instances to routed, check that they have an ip
|
1162 | 7352d33b | Thomas Thrainer | target_mode = params_filled[constants.NIC_MODE] |
1163 | 7352d33b | Thomas Thrainer | if target_mode == constants.NIC_MODE_ROUTED and not nic.ip: |
1164 | 7352d33b | Thomas Thrainer | nic_errors.append("Instance %s, nic/%d: routed NIC with no ip"
|
1165 | 7352d33b | Thomas Thrainer | " address" % (instance.name, nic_idx))
|
1166 | 7352d33b | Thomas Thrainer | if nic_errors:
|
1167 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Cannot apply the change, errors:\n%s" % |
1168 | 7352d33b | Thomas Thrainer | "\n".join(nic_errors), errors.ECODE_INVAL)
|
1169 | 7352d33b | Thomas Thrainer | |
1170 | 7352d33b | Thomas Thrainer | # hypervisor list/parameters
|
1171 | 7352d33b | Thomas Thrainer | self.new_hvparams = new_hvp = objects.FillDict(cluster.hvparams, {})
|
1172 | 7352d33b | Thomas Thrainer | if self.op.hvparams: |
1173 | 7352d33b | Thomas Thrainer | for hv_name, hv_dict in self.op.hvparams.items(): |
1174 | 7352d33b | Thomas Thrainer | if hv_name not in self.new_hvparams: |
1175 | 7352d33b | Thomas Thrainer | self.new_hvparams[hv_name] = hv_dict
|
1176 | 7352d33b | Thomas Thrainer | else:
|
1177 | 7352d33b | Thomas Thrainer | self.new_hvparams[hv_name].update(hv_dict)
|
1178 | 7352d33b | Thomas Thrainer | |
1179 | 7352d33b | Thomas Thrainer | # disk template parameters
|
1180 | 7352d33b | Thomas Thrainer | self.new_diskparams = objects.FillDict(cluster.diskparams, {})
|
1181 | 7352d33b | Thomas Thrainer | if self.op.diskparams: |
1182 | 7352d33b | Thomas Thrainer | for dt_name, dt_params in self.op.diskparams.items(): |
1183 | f06af3ca | Thomas Thrainer | if dt_name not in self.new_diskparams: |
1184 | 7352d33b | Thomas Thrainer | self.new_diskparams[dt_name] = dt_params
|
1185 | 7352d33b | Thomas Thrainer | else:
|
1186 | 7352d33b | Thomas Thrainer | self.new_diskparams[dt_name].update(dt_params)
|
1187 | 294254b1 | Raffa Santi | CheckDiskAccessModeConsistency(self.op.diskparams, self.cfg) |
1188 | 7352d33b | Thomas Thrainer | |
1189 | 7352d33b | Thomas Thrainer | # os hypervisor parameters
|
1190 | 7352d33b | Thomas Thrainer | self.new_os_hvp = objects.FillDict(cluster.os_hvp, {})
|
1191 | 7352d33b | Thomas Thrainer | if self.op.os_hvp: |
1192 | 7352d33b | Thomas Thrainer | for os_name, hvs in self.op.os_hvp.items(): |
1193 | 7352d33b | Thomas Thrainer | if os_name not in self.new_os_hvp: |
1194 | 7352d33b | Thomas Thrainer | self.new_os_hvp[os_name] = hvs
|
1195 | 7352d33b | Thomas Thrainer | else:
|
1196 | 7352d33b | Thomas Thrainer | for hv_name, hv_dict in hvs.items(): |
1197 | 7352d33b | Thomas Thrainer | if hv_dict is None: |
1198 | 7352d33b | Thomas Thrainer | # Delete if it exists
|
1199 | 7352d33b | Thomas Thrainer | self.new_os_hvp[os_name].pop(hv_name, None) |
1200 | 7352d33b | Thomas Thrainer | elif hv_name not in self.new_os_hvp[os_name]: |
1201 | 7352d33b | Thomas Thrainer | self.new_os_hvp[os_name][hv_name] = hv_dict
|
1202 | 7352d33b | Thomas Thrainer | else:
|
1203 | 7352d33b | Thomas Thrainer | self.new_os_hvp[os_name][hv_name].update(hv_dict)
|
1204 | 7352d33b | Thomas Thrainer | |
1205 | 7352d33b | Thomas Thrainer | # os parameters
|
1206 | 07e3c124 | Santi Raffa | self._BuildOSParams(cluster)
|
1207 | 7352d33b | Thomas Thrainer | |
1208 | 7352d33b | Thomas Thrainer | # changes to the hypervisor list
|
1209 | 7352d33b | Thomas Thrainer | if self.op.enabled_hypervisors is not None: |
1210 | 7352d33b | Thomas Thrainer | self.hv_list = self.op.enabled_hypervisors |
1211 | 7352d33b | Thomas Thrainer | for hv in self.hv_list: |
1212 | 7352d33b | Thomas Thrainer | # if the hypervisor doesn't already exist in the cluster
|
1213 | 7352d33b | Thomas Thrainer | # hvparams, we initialize it to empty, and then (in both
|
1214 | 7352d33b | Thomas Thrainer | # cases) we make sure to fill the defaults, as we might not
|
1215 | 7352d33b | Thomas Thrainer | # have a complete defaults list if the hypervisor wasn't
|
1216 | 7352d33b | Thomas Thrainer | # enabled before
|
1217 | 7352d33b | Thomas Thrainer | if hv not in new_hvp: |
1218 | 7352d33b | Thomas Thrainer | new_hvp[hv] = {} |
1219 | 7352d33b | Thomas Thrainer | new_hvp[hv] = objects.FillDict(constants.HVC_DEFAULTS[hv], new_hvp[hv]) |
1220 | 7352d33b | Thomas Thrainer | utils.ForceDictType(new_hvp[hv], constants.HVS_PARAMETER_TYPES) |
1221 | 7352d33b | Thomas Thrainer | else:
|
1222 | 7352d33b | Thomas Thrainer | self.hv_list = cluster.enabled_hypervisors
|
1223 | 7352d33b | Thomas Thrainer | |
1224 | 7352d33b | Thomas Thrainer | if self.op.hvparams or self.op.enabled_hypervisors is not None: |
1225 | 7352d33b | Thomas Thrainer | # either the enabled list has changed, or the parameters have, validate
|
1226 | 7352d33b | Thomas Thrainer | for hv_name, hv_params in self.new_hvparams.items(): |
1227 | 7352d33b | Thomas Thrainer | if ((self.op.hvparams and hv_name in self.op.hvparams) or |
1228 | 7352d33b | Thomas Thrainer | (self.op.enabled_hypervisors and |
1229 | 7352d33b | Thomas Thrainer | hv_name in self.op.enabled_hypervisors)): |
1230 | 7352d33b | Thomas Thrainer | # either this is a new hypervisor, or its parameters have changed
|
1231 | 7352d33b | Thomas Thrainer | hv_class = hypervisor.GetHypervisorClass(hv_name) |
1232 | 7352d33b | Thomas Thrainer | utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES) |
1233 | 7352d33b | Thomas Thrainer | hv_class.CheckParameterSyntax(hv_params) |
1234 | 1c3231aa | Thomas Thrainer | CheckHVParams(self, node_uuids, hv_name, hv_params)
|
1235 | 7352d33b | Thomas Thrainer | |
1236 | 7352d33b | Thomas Thrainer | self._CheckDiskTemplateConsistency()
|
1237 | 7352d33b | Thomas Thrainer | |
1238 | 7352d33b | Thomas Thrainer | if self.op.os_hvp: |
1239 | 7352d33b | Thomas Thrainer | # no need to check any newly-enabled hypervisors, since the
|
1240 | 7352d33b | Thomas Thrainer | # defaults have already been checked in the above code-block
|
1241 | 7352d33b | Thomas Thrainer | for os_name, os_hvp in self.new_os_hvp.items(): |
1242 | 7352d33b | Thomas Thrainer | for hv_name, hv_params in os_hvp.items(): |
1243 | 7352d33b | Thomas Thrainer | utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES) |
1244 | 7352d33b | Thomas Thrainer | # we need to fill in the new os_hvp on top of the actual hv_p
|
1245 | 7352d33b | Thomas Thrainer | cluster_defaults = self.new_hvparams.get(hv_name, {})
|
1246 | 7352d33b | Thomas Thrainer | new_osp = objects.FillDict(cluster_defaults, hv_params) |
1247 | 7352d33b | Thomas Thrainer | hv_class = hypervisor.GetHypervisorClass(hv_name) |
1248 | 7352d33b | Thomas Thrainer | hv_class.CheckParameterSyntax(new_osp) |
1249 | 1c3231aa | Thomas Thrainer | CheckHVParams(self, node_uuids, hv_name, new_osp)
|
1250 | 7352d33b | Thomas Thrainer | |
1251 | 7352d33b | Thomas Thrainer | if self.op.default_iallocator: |
1252 | 7352d33b | Thomas Thrainer | alloc_script = utils.FindFile(self.op.default_iallocator,
|
1253 | 7352d33b | Thomas Thrainer | constants.IALLOCATOR_SEARCH_PATH, |
1254 | 7352d33b | Thomas Thrainer | os.path.isfile) |
1255 | 7352d33b | Thomas Thrainer | if alloc_script is None: |
1256 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Invalid default iallocator script '%s'" |
1257 | 7352d33b | Thomas Thrainer | " specified" % self.op.default_iallocator, |
1258 | 7352d33b | Thomas Thrainer | errors.ECODE_INVAL) |
1259 | 7352d33b | Thomas Thrainer | |
1260 | 11eeb1b9 | Jose A. Lopes | if self.op.instance_communication_network: |
1261 | 11eeb1b9 | Jose A. Lopes | network_name = self.op.instance_communication_network
|
1262 | 11eeb1b9 | Jose A. Lopes | |
1263 | 11eeb1b9 | Jose A. Lopes | try:
|
1264 | 11eeb1b9 | Jose A. Lopes | network_uuid = self.cfg.LookupNetwork(network_name)
|
1265 | 11eeb1b9 | Jose A. Lopes | except errors.OpPrereqError:
|
1266 | 11eeb1b9 | Jose A. Lopes | network_uuid = None
|
1267 | 11eeb1b9 | Jose A. Lopes | |
1268 | 11eeb1b9 | Jose A. Lopes | if network_uuid is not None: |
1269 | 11eeb1b9 | Jose A. Lopes | network = self.cfg.GetNetwork(network_uuid)
|
1270 | 11eeb1b9 | Jose A. Lopes | self._CheckInstanceCommunicationNetwork(network, self.LogWarning) |
1271 | 11eeb1b9 | Jose A. Lopes | |
1272 | 07e3c124 | Santi Raffa | def _BuildOSParams(self, cluster): |
1273 | 07e3c124 | Santi Raffa | "Calculate the new OS parameters for this operation."
|
1274 | 07e3c124 | Santi Raffa | |
1275 | 07e3c124 | Santi Raffa | def _GetNewParams(source, new_params): |
1276 | 07e3c124 | Santi Raffa | "Wrapper around GetUpdatedParams."
|
1277 | 07e3c124 | Santi Raffa | if new_params is None: |
1278 | 07e3c124 | Santi Raffa | return source
|
1279 | 07e3c124 | Santi Raffa | result = objects.FillDict(source, {}) # deep copy of source
|
1280 | 07e3c124 | Santi Raffa | for os_name in new_params: |
1281 | 07e3c124 | Santi Raffa | result[os_name] = GetUpdatedParams(result.get(os_name, {}), |
1282 | 07e3c124 | Santi Raffa | new_params[os_name], |
1283 | 07e3c124 | Santi Raffa | use_none=True)
|
1284 | 07e3c124 | Santi Raffa | if not result[os_name]: |
1285 | 07e3c124 | Santi Raffa | del result[os_name] # we removed all parameters |
1286 | 07e3c124 | Santi Raffa | return result
|
1287 | 07e3c124 | Santi Raffa | |
1288 | 07e3c124 | Santi Raffa | self.new_osp = _GetNewParams(cluster.osparams,
|
1289 | 07e3c124 | Santi Raffa | self.op.osparams)
|
1290 | 07e3c124 | Santi Raffa | self.new_osp_private = _GetNewParams(cluster.osparams_private_cluster,
|
1291 | 07e3c124 | Santi Raffa | self.op.osparams_private_cluster)
|
1292 | 07e3c124 | Santi Raffa | |
1293 | 07e3c124 | Santi Raffa | # Remove os validity check
|
1294 | 07e3c124 | Santi Raffa | changed_oses = (set(self.new_osp.keys()) | set(self.new_osp_private.keys())) |
1295 | 07e3c124 | Santi Raffa | for os_name in changed_oses: |
1296 | 07e3c124 | Santi Raffa | os_params = cluster.SimpleFillOS( |
1297 | 07e3c124 | Santi Raffa | os_name, |
1298 | 07e3c124 | Santi Raffa | self.new_osp.get(os_name, {}),
|
1299 | 07e3c124 | Santi Raffa | os_params_private=self.new_osp_private.get(os_name, {})
|
1300 | 07e3c124 | Santi Raffa | ) |
1301 | 07e3c124 | Santi Raffa | # check the parameter validity (remote check)
|
1302 | 07e3c124 | Santi Raffa | CheckOSParams(self, False, [self.cfg.GetMasterNode()], |
1303 | 07e3c124 | Santi Raffa | os_name, os_params) |
1304 | 07e3c124 | Santi Raffa | |
1305 | 7352d33b | Thomas Thrainer | def _CheckDiskTemplateConsistency(self): |
1306 | 7352d33b | Thomas Thrainer | """Check whether the disk templates that are going to be disabled
|
1307 | 7352d33b | Thomas Thrainer | are still in use by some instances.
|
1308 | 7352d33b | Thomas Thrainer |
|
1309 | 7352d33b | Thomas Thrainer | """
|
1310 | 7352d33b | Thomas Thrainer | if self.op.enabled_disk_templates: |
1311 | 7352d33b | Thomas Thrainer | cluster = self.cfg.GetClusterInfo()
|
1312 | 7352d33b | Thomas Thrainer | instances = self.cfg.GetAllInstancesInfo()
|
1313 | 7352d33b | Thomas Thrainer | |
1314 | 7352d33b | Thomas Thrainer | disk_templates_to_remove = set(cluster.enabled_disk_templates) \
|
1315 | 7352d33b | Thomas Thrainer | - set(self.op.enabled_disk_templates) |
1316 | 7352d33b | Thomas Thrainer | for instance in instances.itervalues(): |
1317 | 7352d33b | Thomas Thrainer | if instance.disk_template in disk_templates_to_remove: |
1318 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Cannot disable disk template '%s'," |
1319 | 7352d33b | Thomas Thrainer | " because instance '%s' is using it." %
|
1320 | 7352d33b | Thomas Thrainer | (instance.disk_template, instance.name)) |
1321 | 7352d33b | Thomas Thrainer | |
1322 | 1bb99a33 | Bernardo Dal Seno | def _SetVgName(self, feedback_fn): |
1323 | 1bb99a33 | Bernardo Dal Seno | """Determines and sets the new volume group name.
|
1324 | 7352d33b | Thomas Thrainer |
|
1325 | 7352d33b | Thomas Thrainer | """
|
1326 | 7352d33b | Thomas Thrainer | if self.op.vg_name is not None: |
1327 | 7352d33b | Thomas Thrainer | new_volume = self.op.vg_name
|
1328 | 7352d33b | Thomas Thrainer | if not new_volume: |
1329 | 7352d33b | Thomas Thrainer | new_volume = None
|
1330 | 7352d33b | Thomas Thrainer | if new_volume != self.cfg.GetVGName(): |
1331 | 7352d33b | Thomas Thrainer | self.cfg.SetVGName(new_volume)
|
1332 | 7352d33b | Thomas Thrainer | else:
|
1333 | 7352d33b | Thomas Thrainer | feedback_fn("Cluster LVM configuration already in desired"
|
1334 | 7352d33b | Thomas Thrainer | " state, not changing")
|
1335 | 1bb99a33 | Bernardo Dal Seno | |
1336 | 3039e2dc | Helga Velroyen | def _SetFileStorageDir(self, feedback_fn): |
1337 | 3039e2dc | Helga Velroyen | """Set the file storage directory.
|
1338 | 3039e2dc | Helga Velroyen |
|
1339 | 3039e2dc | Helga Velroyen | """
|
1340 | 3039e2dc | Helga Velroyen | if self.op.file_storage_dir is not None: |
1341 | 3039e2dc | Helga Velroyen | if self.cluster.file_storage_dir == self.op.file_storage_dir: |
1342 | 3039e2dc | Helga Velroyen | feedback_fn("Global file storage dir already set to value '%s'"
|
1343 | 3039e2dc | Helga Velroyen | % self.cluster.file_storage_dir)
|
1344 | 3039e2dc | Helga Velroyen | else:
|
1345 | 3039e2dc | Helga Velroyen | self.cluster.file_storage_dir = self.op.file_storage_dir |
1346 | 3039e2dc | Helga Velroyen | |
1347 | 7c577910 | Helga Velroyen | def _SetDrbdHelper(self, feedback_fn): |
1348 | 7c577910 | Helga Velroyen | """Set the DRBD usermode helper.
|
1349 | 1bb99a33 | Bernardo Dal Seno |
|
1350 | 1bb99a33 | Bernardo Dal Seno | """
|
1351 | 7352d33b | Thomas Thrainer | if self.op.drbd_helper is not None: |
1352 | 1bb99a33 | Bernardo Dal Seno | if not constants.DT_DRBD8 in self.cluster.enabled_disk_templates: |
1353 | a794b8d7 | Thomas Thrainer | feedback_fn("Note that you specified a drbd user helper, but did not"
|
1354 | a794b8d7 | Thomas Thrainer | " enable the drbd disk template.")
|
1355 | 7352d33b | Thomas Thrainer | new_helper = self.op.drbd_helper
|
1356 | 7352d33b | Thomas Thrainer | if not new_helper: |
1357 | 7352d33b | Thomas Thrainer | new_helper = None
|
1358 | 7352d33b | Thomas Thrainer | if new_helper != self.cfg.GetDRBDHelper(): |
1359 | 7352d33b | Thomas Thrainer | self.cfg.SetDRBDHelper(new_helper)
|
1360 | 7352d33b | Thomas Thrainer | else:
|
1361 | 7352d33b | Thomas Thrainer | feedback_fn("Cluster DRBD helper already in desired state,"
|
1362 | 7352d33b | Thomas Thrainer | " not changing")
|
1363 | 7c577910 | Helga Velroyen | |
1364 | d6a7518a | Jose A. Lopes | @staticmethod
|
1365 | d6a7518a | Jose A. Lopes | def _EnsureInstanceCommunicationNetwork(cfg, network_name): |
1366 | d6a7518a | Jose A. Lopes | """Ensure that the instance communication network exists and is
|
1367 | d6a7518a | Jose A. Lopes | connected to all groups.
|
1368 | d6a7518a | Jose A. Lopes |
|
1369 | d6a7518a | Jose A. Lopes | The instance communication network given by L{network_name} it is
|
1370 | d6a7518a | Jose A. Lopes | created, if necessary, via the opcode 'OpNetworkAdd'. Also, the
|
1371 | d6a7518a | Jose A. Lopes | instance communication network is connected to all existing node
|
1372 | d6a7518a | Jose A. Lopes | groups, if necessary, via the opcode 'OpNetworkConnect'.
|
1373 | d6a7518a | Jose A. Lopes |
|
1374 | 9808764a | Jose A. Lopes | @type cfg: L{config.ConfigWriter}
|
1375 | 9808764a | Jose A. Lopes | @param cfg: cluster configuration
|
1376 | d6a7518a | Jose A. Lopes |
|
1377 | d6a7518a | Jose A. Lopes | @type network_name: string
|
1378 | d6a7518a | Jose A. Lopes | @param network_name: instance communication network name
|
1379 | d6a7518a | Jose A. Lopes |
|
1380 | d6a7518a | Jose A. Lopes | @rtype: L{ganeti.cmdlib.ResultWithJobs} or L{None}
|
1381 | d6a7518a | Jose A. Lopes | @return: L{ganeti.cmdlib.ResultWithJobs} if the instance
|
1382 | d6a7518a | Jose A. Lopes | communication needs to be created or it needs to be
|
1383 | d6a7518a | Jose A. Lopes | connected to a group, otherwise L{None}
|
1384 | d6a7518a | Jose A. Lopes |
|
1385 | d6a7518a | Jose A. Lopes | """
|
1386 | d6a7518a | Jose A. Lopes | jobs = [] |
1387 | d6a7518a | Jose A. Lopes | |
1388 | d6a7518a | Jose A. Lopes | try:
|
1389 | d6a7518a | Jose A. Lopes | network_uuid = cfg.LookupNetwork(network_name) |
1390 | d6a7518a | Jose A. Lopes | network_exists = True
|
1391 | d6a7518a | Jose A. Lopes | except errors.OpPrereqError:
|
1392 | d6a7518a | Jose A. Lopes | network_exists = False
|
1393 | d6a7518a | Jose A. Lopes | |
1394 | d6a7518a | Jose A. Lopes | if not network_exists: |
1395 | 4b75f8a4 | Jose A. Lopes | jobs.append(AddInstanceCommunicationNetworkOp(network_name)) |
1396 | d6a7518a | Jose A. Lopes | |
1397 | d6a7518a | Jose A. Lopes | for group_uuid in cfg.GetNodeGroupList(): |
1398 | d6a7518a | Jose A. Lopes | group = cfg.GetNodeGroup(group_uuid) |
1399 | d6a7518a | Jose A. Lopes | |
1400 | d6a7518a | Jose A. Lopes | if network_exists:
|
1401 | d6a7518a | Jose A. Lopes | network_connected = network_uuid in group.networks
|
1402 | d6a7518a | Jose A. Lopes | else:
|
1403 | d6a7518a | Jose A. Lopes | # The network was created asynchronously by the previous
|
1404 | d6a7518a | Jose A. Lopes | # opcode and, therefore, we don't have access to its
|
1405 | d6a7518a | Jose A. Lopes | # network_uuid. As a result, we assume that the network is
|
1406 | d6a7518a | Jose A. Lopes | # not connected to any group yet.
|
1407 | d6a7518a | Jose A. Lopes | network_connected = False
|
1408 | d6a7518a | Jose A. Lopes | |
1409 | d6a7518a | Jose A. Lopes | if not network_connected: |
1410 | 4b75f8a4 | Jose A. Lopes | op = ConnectInstanceCommunicationNetworkOp(group_uuid, network_name) |
1411 | d6a7518a | Jose A. Lopes | jobs.append(op) |
1412 | d6a7518a | Jose A. Lopes | |
1413 | d6a7518a | Jose A. Lopes | if jobs:
|
1414 | d6a7518a | Jose A. Lopes | return ResultWithJobs([jobs])
|
1415 | d6a7518a | Jose A. Lopes | else:
|
1416 | d6a7518a | Jose A. Lopes | return None |
1417 | d6a7518a | Jose A. Lopes | |
1418 | d6a7518a | Jose A. Lopes | @staticmethod
|
1419 | d6a7518a | Jose A. Lopes | def _ModifyInstanceCommunicationNetwork(cfg, cluster, network_name, |
1420 | d6a7518a | Jose A. Lopes | feedback_fn): |
1421 | d6a7518a | Jose A. Lopes | """Update the instance communication network stored in the cluster
|
1422 | d6a7518a | Jose A. Lopes | configuration.
|
1423 | d6a7518a | Jose A. Lopes |
|
1424 | d6a7518a | Jose A. Lopes | Compares the user-supplied instance communication network against
|
1425 | d6a7518a | Jose A. Lopes | the one stored in the Ganeti cluster configuration. If there is a
|
1426 | d6a7518a | Jose A. Lopes | change, the instance communication network may be possibly created
|
1427 | d6a7518a | Jose A. Lopes | and connected to all groups (see
|
1428 | d6a7518a | Jose A. Lopes | L{LUClusterSetParams._EnsureInstanceCommunicationNetwork}).
|
1429 | d6a7518a | Jose A. Lopes |
|
1430 | 9808764a | Jose A. Lopes | @type cfg: L{config.ConfigWriter}
|
1431 | 9808764a | Jose A. Lopes | @param cfg: cluster configuration
|
1432 | d6a7518a | Jose A. Lopes |
|
1433 | d6a7518a | Jose A. Lopes | @type cluster: L{ganeti.objects.Cluster}
|
1434 | d6a7518a | Jose A. Lopes | @param cluster: Ganeti cluster
|
1435 | d6a7518a | Jose A. Lopes |
|
1436 | d6a7518a | Jose A. Lopes | @type network_name: string
|
1437 | d6a7518a | Jose A. Lopes | @param network_name: instance communication network name
|
1438 | d6a7518a | Jose A. Lopes |
|
1439 | d6a7518a | Jose A. Lopes | @type feedback_fn: function
|
1440 | d6a7518a | Jose A. Lopes | @param feedback_fn: see L{ganeti.cmdlist.base.LogicalUnit}
|
1441 | d6a7518a | Jose A. Lopes |
|
1442 | d6a7518a | Jose A. Lopes | @rtype: L{LUClusterSetParams._EnsureInstanceCommunicationNetwork} or L{None}
|
1443 | d6a7518a | Jose A. Lopes | @return: see L{LUClusterSetParams._EnsureInstanceCommunicationNetwork}
|
1444 | d6a7518a | Jose A. Lopes |
|
1445 | d6a7518a | Jose A. Lopes | """
|
1446 | d6a7518a | Jose A. Lopes | config_network_name = cfg.GetInstanceCommunicationNetwork() |
1447 | d6a7518a | Jose A. Lopes | |
1448 | d6a7518a | Jose A. Lopes | if network_name == config_network_name:
|
1449 | d6a7518a | Jose A. Lopes | feedback_fn("Instance communication network already is '%s', nothing to"
|
1450 | d6a7518a | Jose A. Lopes | " do." % network_name)
|
1451 | d6a7518a | Jose A. Lopes | else:
|
1452 | d6a7518a | Jose A. Lopes | try:
|
1453 | d6a7518a | Jose A. Lopes | cfg.LookupNetwork(config_network_name) |
1454 | d6a7518a | Jose A. Lopes | feedback_fn("Previous instance communication network '%s'"
|
1455 | d6a7518a | Jose A. Lopes | " should be removed manually." % config_network_name)
|
1456 | d6a7518a | Jose A. Lopes | except errors.OpPrereqError:
|
1457 | d6a7518a | Jose A. Lopes | pass
|
1458 | d6a7518a | Jose A. Lopes | |
1459 | d6a7518a | Jose A. Lopes | if network_name:
|
1460 | d6a7518a | Jose A. Lopes | feedback_fn("Changing instance communication network to '%s', only new"
|
1461 | d6a7518a | Jose A. Lopes | " instances will be affected."
|
1462 | d6a7518a | Jose A. Lopes | % network_name) |
1463 | d6a7518a | Jose A. Lopes | else:
|
1464 | d6a7518a | Jose A. Lopes | feedback_fn("Disabling instance communication network, only new"
|
1465 | d6a7518a | Jose A. Lopes | " instances will be affected.")
|
1466 | d6a7518a | Jose A. Lopes | |
1467 | d6a7518a | Jose A. Lopes | cluster.instance_communication_network = network_name |
1468 | d6a7518a | Jose A. Lopes | |
1469 | d6a7518a | Jose A. Lopes | if network_name:
|
1470 | d6a7518a | Jose A. Lopes | return LUClusterSetParams._EnsureInstanceCommunicationNetwork(
|
1471 | d6a7518a | Jose A. Lopes | cfg, |
1472 | d6a7518a | Jose A. Lopes | network_name) |
1473 | d6a7518a | Jose A. Lopes | else:
|
1474 | d6a7518a | Jose A. Lopes | return None |
1475 | d6a7518a | Jose A. Lopes | |
1476 | 7c577910 | Helga Velroyen | def Exec(self, feedback_fn): |
1477 | 7c577910 | Helga Velroyen | """Change the parameters of the cluster.
|
1478 | 7c577910 | Helga Velroyen |
|
1479 | 7c577910 | Helga Velroyen | """
|
1480 | 7c577910 | Helga Velroyen | if self.op.enabled_disk_templates: |
1481 | 7c577910 | Helga Velroyen | self.cluster.enabled_disk_templates = \
|
1482 | 8b95dfdc | Helga Velroyen | list(self.op.enabled_disk_templates) |
1483 | 7c577910 | Helga Velroyen | |
1484 | 7c577910 | Helga Velroyen | self._SetVgName(feedback_fn)
|
1485 | 7c577910 | Helga Velroyen | self._SetFileStorageDir(feedback_fn)
|
1486 | 7c577910 | Helga Velroyen | self._SetDrbdHelper(feedback_fn)
|
1487 | 7c577910 | Helga Velroyen | |
1488 | 7352d33b | Thomas Thrainer | if self.op.hvparams: |
1489 | 7352d33b | Thomas Thrainer | self.cluster.hvparams = self.new_hvparams |
1490 | 7352d33b | Thomas Thrainer | if self.op.os_hvp: |
1491 | 7352d33b | Thomas Thrainer | self.cluster.os_hvp = self.new_os_hvp |
1492 | 7352d33b | Thomas Thrainer | if self.op.enabled_hypervisors is not None: |
1493 | 7352d33b | Thomas Thrainer | self.cluster.hvparams = self.new_hvparams |
1494 | 7352d33b | Thomas Thrainer | self.cluster.enabled_hypervisors = self.op.enabled_hypervisors |
1495 | 7352d33b | Thomas Thrainer | if self.op.beparams: |
1496 | 7352d33b | Thomas Thrainer | self.cluster.beparams[constants.PP_DEFAULT] = self.new_beparams |
1497 | 7352d33b | Thomas Thrainer | if self.op.nicparams: |
1498 | 7352d33b | Thomas Thrainer | self.cluster.nicparams[constants.PP_DEFAULT] = self.new_nicparams |
1499 | 7352d33b | Thomas Thrainer | if self.op.ipolicy: |
1500 | 7352d33b | Thomas Thrainer | self.cluster.ipolicy = self.new_ipolicy |
1501 | 7352d33b | Thomas Thrainer | if self.op.osparams: |
1502 | 7352d33b | Thomas Thrainer | self.cluster.osparams = self.new_osp |
1503 | 07e3c124 | Santi Raffa | if self.op.osparams_private_cluster: |
1504 | 07e3c124 | Santi Raffa | self.cluster.osparams_private_cluster = self.new_osp_private |
1505 | 7352d33b | Thomas Thrainer | if self.op.ndparams: |
1506 | 7352d33b | Thomas Thrainer | self.cluster.ndparams = self.new_ndparams |
1507 | 7352d33b | Thomas Thrainer | if self.op.diskparams: |
1508 | 7352d33b | Thomas Thrainer | self.cluster.diskparams = self.new_diskparams |
1509 | 7352d33b | Thomas Thrainer | if self.op.hv_state: |
1510 | 7352d33b | Thomas Thrainer | self.cluster.hv_state_static = self.new_hv_state |
1511 | 7352d33b | Thomas Thrainer | if self.op.disk_state: |
1512 | 7352d33b | Thomas Thrainer | self.cluster.disk_state_static = self.new_disk_state |
1513 | 7352d33b | Thomas Thrainer | |
1514 | 7352d33b | Thomas Thrainer | if self.op.candidate_pool_size is not None: |
1515 | 7352d33b | Thomas Thrainer | self.cluster.candidate_pool_size = self.op.candidate_pool_size |
1516 | 7352d33b | Thomas Thrainer | # we need to update the pool size here, otherwise the save will fail
|
1517 | c1410048 | Helga Velroyen | AdjustCandidatePool(self, [], feedback_fn)
|
1518 | 7352d33b | Thomas Thrainer | |
1519 | ad756c77 | Klaus Aehlig | if self.op.max_running_jobs is not None: |
1520 | ad756c77 | Klaus Aehlig | self.cluster.max_running_jobs = self.op.max_running_jobs |
1521 | ad756c77 | Klaus Aehlig | |
1522 | 7352d33b | Thomas Thrainer | if self.op.maintain_node_health is not None: |
1523 | 7352d33b | Thomas Thrainer | if self.op.maintain_node_health and not constants.ENABLE_CONFD: |
1524 | 7352d33b | Thomas Thrainer | feedback_fn("Note: CONFD was disabled at build time, node health"
|
1525 | 7352d33b | Thomas Thrainer | " maintenance is not useful (still enabling it)")
|
1526 | 7352d33b | Thomas Thrainer | self.cluster.maintain_node_health = self.op.maintain_node_health |
1527 | 7352d33b | Thomas Thrainer | |
1528 | 75f2ff7d | Michele Tartara | if self.op.modify_etc_hosts is not None: |
1529 | 75f2ff7d | Michele Tartara | self.cluster.modify_etc_hosts = self.op.modify_etc_hosts |
1530 | 75f2ff7d | Michele Tartara | |
1531 | 7352d33b | Thomas Thrainer | if self.op.prealloc_wipe_disks is not None: |
1532 | 7352d33b | Thomas Thrainer | self.cluster.prealloc_wipe_disks = self.op.prealloc_wipe_disks |
1533 | 7352d33b | Thomas Thrainer | |
1534 | 7352d33b | Thomas Thrainer | if self.op.add_uids is not None: |
1535 | 7352d33b | Thomas Thrainer | uidpool.AddToUidPool(self.cluster.uid_pool, self.op.add_uids) |
1536 | 7352d33b | Thomas Thrainer | |
1537 | 7352d33b | Thomas Thrainer | if self.op.remove_uids is not None: |
1538 | 7352d33b | Thomas Thrainer | uidpool.RemoveFromUidPool(self.cluster.uid_pool, self.op.remove_uids) |
1539 | 7352d33b | Thomas Thrainer | |
1540 | 7352d33b | Thomas Thrainer | if self.op.uid_pool is not None: |
1541 | 7352d33b | Thomas Thrainer | self.cluster.uid_pool = self.op.uid_pool |
1542 | 7352d33b | Thomas Thrainer | |
1543 | 7352d33b | Thomas Thrainer | if self.op.default_iallocator is not None: |
1544 | 7352d33b | Thomas Thrainer | self.cluster.default_iallocator = self.op.default_iallocator |
1545 | 7352d33b | Thomas Thrainer | |
1546 | 0359e5d0 | Spyros Trigazis | if self.op.default_iallocator_params is not None: |
1547 | 0359e5d0 | Spyros Trigazis | self.cluster.default_iallocator_params = self.op.default_iallocator_params |
1548 | 0359e5d0 | Spyros Trigazis | |
1549 | 7352d33b | Thomas Thrainer | if self.op.reserved_lvs is not None: |
1550 | 7352d33b | Thomas Thrainer | self.cluster.reserved_lvs = self.op.reserved_lvs |
1551 | 7352d33b | Thomas Thrainer | |
1552 | 7352d33b | Thomas Thrainer | if self.op.use_external_mip_script is not None: |
1553 | 7352d33b | Thomas Thrainer | self.cluster.use_external_mip_script = self.op.use_external_mip_script |
1554 | 7352d33b | Thomas Thrainer | |
1555 | 7352d33b | Thomas Thrainer | def helper_os(aname, mods, desc): |
1556 | 7352d33b | Thomas Thrainer | desc += " OS list"
|
1557 | 7352d33b | Thomas Thrainer | lst = getattr(self.cluster, aname) |
1558 | 7352d33b | Thomas Thrainer | for key, val in mods: |
1559 | 7352d33b | Thomas Thrainer | if key == constants.DDM_ADD:
|
1560 | 7352d33b | Thomas Thrainer | if val in lst: |
1561 | 7352d33b | Thomas Thrainer | feedback_fn("OS %s already in %s, ignoring" % (val, desc))
|
1562 | 7352d33b | Thomas Thrainer | else:
|
1563 | 7352d33b | Thomas Thrainer | lst.append(val) |
1564 | 7352d33b | Thomas Thrainer | elif key == constants.DDM_REMOVE:
|
1565 | 7352d33b | Thomas Thrainer | if val in lst: |
1566 | 7352d33b | Thomas Thrainer | lst.remove(val) |
1567 | 7352d33b | Thomas Thrainer | else:
|
1568 | 7352d33b | Thomas Thrainer | feedback_fn("OS %s not found in %s, ignoring" % (val, desc))
|
1569 | 7352d33b | Thomas Thrainer | else:
|
1570 | 7352d33b | Thomas Thrainer | raise errors.ProgrammerError("Invalid modification '%s'" % key) |
1571 | 7352d33b | Thomas Thrainer | |
1572 | 7352d33b | Thomas Thrainer | if self.op.hidden_os: |
1573 | 7352d33b | Thomas Thrainer | helper_os("hidden_os", self.op.hidden_os, "hidden") |
1574 | 7352d33b | Thomas Thrainer | |
1575 | 7352d33b | Thomas Thrainer | if self.op.blacklisted_os: |
1576 | 7352d33b | Thomas Thrainer | helper_os("blacklisted_os", self.op.blacklisted_os, "blacklisted") |
1577 | 7352d33b | Thomas Thrainer | |
1578 | 7352d33b | Thomas Thrainer | if self.op.master_netdev: |
1579 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
1580 | 7352d33b | Thomas Thrainer | ems = self.cfg.GetUseExternalMipScript()
|
1581 | 7352d33b | Thomas Thrainer | feedback_fn("Shutting down master ip on the current netdev (%s)" %
|
1582 | 7352d33b | Thomas Thrainer | self.cluster.master_netdev)
|
1583 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_deactivate_master_ip(master_params.uuid,
|
1584 | 7352d33b | Thomas Thrainer | master_params, ems) |
1585 | e5c92cfb | Klaus Aehlig | if not self.op.force: |
1586 | e5c92cfb | Klaus Aehlig | result.Raise("Could not disable the master ip")
|
1587 | e5c92cfb | Klaus Aehlig | else:
|
1588 | e5c92cfb | Klaus Aehlig | if result.fail_msg:
|
1589 | e5c92cfb | Klaus Aehlig | msg = ("Could not disable the master ip (continuing anyway): %s" %
|
1590 | e5c92cfb | Klaus Aehlig | result.fail_msg) |
1591 | e5c92cfb | Klaus Aehlig | feedback_fn(msg) |
1592 | 7352d33b | Thomas Thrainer | feedback_fn("Changing master_netdev from %s to %s" %
|
1593 | 7352d33b | Thomas Thrainer | (master_params.netdev, self.op.master_netdev))
|
1594 | 7352d33b | Thomas Thrainer | self.cluster.master_netdev = self.op.master_netdev |
1595 | 7352d33b | Thomas Thrainer | |
1596 | 7352d33b | Thomas Thrainer | if self.op.master_netmask: |
1597 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
1598 | 7352d33b | Thomas Thrainer | feedback_fn("Changing master IP netmask to %s" % self.op.master_netmask) |
1599 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_change_master_netmask(
|
1600 | 1c3231aa | Thomas Thrainer | master_params.uuid, master_params.netmask, |
1601 | 1c3231aa | Thomas Thrainer | self.op.master_netmask, master_params.ip,
|
1602 | 1c3231aa | Thomas Thrainer | master_params.netdev) |
1603 | c7dd65be | Klaus Aehlig | result.Warn("Could not change the master IP netmask", feedback_fn)
|
1604 | 7352d33b | Thomas Thrainer | self.cluster.master_netmask = self.op.master_netmask |
1605 | 7352d33b | Thomas Thrainer | |
1606 | 7352d33b | Thomas Thrainer | self.cfg.Update(self.cluster, feedback_fn) |
1607 | 7352d33b | Thomas Thrainer | |
1608 | 7352d33b | Thomas Thrainer | if self.op.master_netdev: |
1609 | 7352d33b | Thomas Thrainer | master_params = self.cfg.GetMasterNetworkParameters()
|
1610 | 7352d33b | Thomas Thrainer | feedback_fn("Starting the master ip on the new master netdev (%s)" %
|
1611 | 7352d33b | Thomas Thrainer | self.op.master_netdev)
|
1612 | 7352d33b | Thomas Thrainer | ems = self.cfg.GetUseExternalMipScript()
|
1613 | 1c3231aa | Thomas Thrainer | result = self.rpc.call_node_activate_master_ip(master_params.uuid,
|
1614 | 7352d33b | Thomas Thrainer | master_params, ems) |
1615 | c7dd65be | Klaus Aehlig | result.Warn("Could not re-enable the master ip on the master,"
|
1616 | c7dd65be | Klaus Aehlig | " please restart manually", self.LogWarning) |
1617 | 7352d33b | Thomas Thrainer | |
1618 | d6a7518a | Jose A. Lopes | network_name = self.op.instance_communication_network
|
1619 | d6a7518a | Jose A. Lopes | if network_name is not None: |
1620 | d6a7518a | Jose A. Lopes | return self._ModifyInstanceCommunicationNetwork(self.cfg, self.cluster, |
1621 | d6a7518a | Jose A. Lopes | network_name, feedback_fn) |
1622 | d6a7518a | Jose A. Lopes | else:
|
1623 | d6a7518a | Jose A. Lopes | return None |
1624 | d6a7518a | Jose A. Lopes | |
1625 | 7352d33b | Thomas Thrainer | |
1626 | 7352d33b | Thomas Thrainer | class LUClusterVerify(NoHooksLU): |
1627 | 7352d33b | Thomas Thrainer | """Submits all jobs necessary to verify the cluster.
|
1628 | 7352d33b | Thomas Thrainer |
|
1629 | 7352d33b | Thomas Thrainer | """
|
1630 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
1631 | 7352d33b | Thomas Thrainer | |
1632 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
1633 | 7352d33b | Thomas Thrainer | self.needed_locks = {}
|
1634 | 7352d33b | Thomas Thrainer | |
1635 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
1636 | 7352d33b | Thomas Thrainer | jobs = [] |
1637 | 7352d33b | Thomas Thrainer | |
1638 | 7352d33b | Thomas Thrainer | if self.op.group_name: |
1639 | 7352d33b | Thomas Thrainer | groups = [self.op.group_name]
|
1640 | 7352d33b | Thomas Thrainer | depends_fn = lambda: None |
1641 | 7352d33b | Thomas Thrainer | else:
|
1642 | 7352d33b | Thomas Thrainer | groups = self.cfg.GetNodeGroupList()
|
1643 | 7352d33b | Thomas Thrainer | |
1644 | 7352d33b | Thomas Thrainer | # Verify global configuration
|
1645 | 7352d33b | Thomas Thrainer | jobs.append([ |
1646 | 7352d33b | Thomas Thrainer | opcodes.OpClusterVerifyConfig(ignore_errors=self.op.ignore_errors),
|
1647 | 7352d33b | Thomas Thrainer | ]) |
1648 | 7352d33b | Thomas Thrainer | |
1649 | 7352d33b | Thomas Thrainer | # Always depend on global verification
|
1650 | 7352d33b | Thomas Thrainer | depends_fn = lambda: [(-len(jobs), [])] |
1651 | 7352d33b | Thomas Thrainer | |
1652 | 7352d33b | Thomas Thrainer | jobs.extend( |
1653 | 7352d33b | Thomas Thrainer | [opcodes.OpClusterVerifyGroup(group_name=group, |
1654 | 7352d33b | Thomas Thrainer | ignore_errors=self.op.ignore_errors,
|
1655 | 7352d33b | Thomas Thrainer | depends=depends_fn())] |
1656 | 7352d33b | Thomas Thrainer | for group in groups) |
1657 | 7352d33b | Thomas Thrainer | |
1658 | 7352d33b | Thomas Thrainer | # Fix up all parameters
|
1659 | 7352d33b | Thomas Thrainer | for op in itertools.chain(*jobs): # pylint: disable=W0142 |
1660 | 7352d33b | Thomas Thrainer | op.debug_simulate_errors = self.op.debug_simulate_errors
|
1661 | 7352d33b | Thomas Thrainer | op.verbose = self.op.verbose
|
1662 | 7352d33b | Thomas Thrainer | op.error_codes = self.op.error_codes
|
1663 | 7352d33b | Thomas Thrainer | try:
|
1664 | 7352d33b | Thomas Thrainer | op.skip_checks = self.op.skip_checks
|
1665 | 7352d33b | Thomas Thrainer | except AttributeError: |
1666 | 7352d33b | Thomas Thrainer | assert not isinstance(op, opcodes.OpClusterVerifyGroup) |
1667 | 7352d33b | Thomas Thrainer | |
1668 | 7352d33b | Thomas Thrainer | return ResultWithJobs(jobs)
|
1669 | 7352d33b | Thomas Thrainer | |
1670 | 7352d33b | Thomas Thrainer | |
1671 | 7352d33b | Thomas Thrainer | class _VerifyErrors(object): |
1672 | 7352d33b | Thomas Thrainer | """Mix-in for cluster/group verify LUs.
|
1673 | 7352d33b | Thomas Thrainer |
|
1674 | 7352d33b | Thomas Thrainer | It provides _Error and _ErrorIf, and updates the self.bad boolean. (Expects
|
1675 | 7352d33b | Thomas Thrainer | self.op and self._feedback_fn to be available.)
|
1676 | 7352d33b | Thomas Thrainer |
|
1677 | 7352d33b | Thomas Thrainer | """
|
1678 | 7352d33b | Thomas Thrainer | |
1679 | 7352d33b | Thomas Thrainer | ETYPE_FIELD = "code"
|
1680 | a6c43c02 | Helga Velroyen | ETYPE_ERROR = constants.CV_ERROR |
1681 | a6c43c02 | Helga Velroyen | ETYPE_WARNING = constants.CV_WARNING |
1682 | 7352d33b | Thomas Thrainer | |
1683 | 7352d33b | Thomas Thrainer | def _Error(self, ecode, item, msg, *args, **kwargs): |
1684 | 7352d33b | Thomas Thrainer | """Format an error message.
|
1685 | 7352d33b | Thomas Thrainer |
|
1686 | 7352d33b | Thomas Thrainer | Based on the opcode's error_codes parameter, either format a
|
1687 | 7352d33b | Thomas Thrainer | parseable error code, or a simpler error string.
|
1688 | 7352d33b | Thomas Thrainer |
|
1689 | 7352d33b | Thomas Thrainer | This must be called only from Exec and functions called from Exec.
|
1690 | 7352d33b | Thomas Thrainer |
|
1691 | 7352d33b | Thomas Thrainer | """
|
1692 | 7352d33b | Thomas Thrainer | ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) |
1693 | 7352d33b | Thomas Thrainer | itype, etxt, _ = ecode |
1694 | 7352d33b | Thomas Thrainer | # If the error code is in the list of ignored errors, demote the error to a
|
1695 | 7352d33b | Thomas Thrainer | # warning
|
1696 | 7352d33b | Thomas Thrainer | if etxt in self.op.ignore_errors: # pylint: disable=E1101 |
1697 | 7352d33b | Thomas Thrainer | ltype = self.ETYPE_WARNING
|
1698 | 7352d33b | Thomas Thrainer | # first complete the msg
|
1699 | 7352d33b | Thomas Thrainer | if args:
|
1700 | 7352d33b | Thomas Thrainer | msg = msg % args |
1701 | 7352d33b | Thomas Thrainer | # then format the whole message
|
1702 | 7352d33b | Thomas Thrainer | if self.op.error_codes: # This is a mix-in. pylint: disable=E1101 |
1703 | 7352d33b | Thomas Thrainer | msg = "%s:%s:%s:%s:%s" % (ltype, etxt, itype, item, msg)
|
1704 | 7352d33b | Thomas Thrainer | else:
|
1705 | 7352d33b | Thomas Thrainer | if item:
|
1706 | 7352d33b | Thomas Thrainer | item = " " + item
|
1707 | 7352d33b | Thomas Thrainer | else:
|
1708 | 7352d33b | Thomas Thrainer | item = ""
|
1709 | 7352d33b | Thomas Thrainer | msg = "%s: %s%s: %s" % (ltype, itype, item, msg)
|
1710 | 7352d33b | Thomas Thrainer | # and finally report it via the feedback_fn
|
1711 | 7352d33b | Thomas Thrainer | self._feedback_fn(" - %s" % msg) # Mix-in. pylint: disable=E1101 |
1712 | 7352d33b | Thomas Thrainer | # do not mark the operation as failed for WARN cases only
|
1713 | 7352d33b | Thomas Thrainer | if ltype == self.ETYPE_ERROR: |
1714 | 7352d33b | Thomas Thrainer | self.bad = True |
1715 | 7352d33b | Thomas Thrainer | |
1716 | 7352d33b | Thomas Thrainer | def _ErrorIf(self, cond, *args, **kwargs): |
1717 | 7352d33b | Thomas Thrainer | """Log an error message if the passed condition is True.
|
1718 | 7352d33b | Thomas Thrainer |
|
1719 | 7352d33b | Thomas Thrainer | """
|
1720 | 7352d33b | Thomas Thrainer | if (bool(cond) |
1721 | 7352d33b | Thomas Thrainer | or self.op.debug_simulate_errors): # pylint: disable=E1101 |
1722 | 7352d33b | Thomas Thrainer | self._Error(*args, **kwargs)
|
1723 | 7352d33b | Thomas Thrainer | |
1724 | 7352d33b | Thomas Thrainer | |
1725 | 7352d33b | Thomas Thrainer | def _GetAllHypervisorParameters(cluster, instances): |
1726 | 7352d33b | Thomas Thrainer | """Compute the set of all hypervisor parameters.
|
1727 | 7352d33b | Thomas Thrainer |
|
1728 | 7352d33b | Thomas Thrainer | @type cluster: L{objects.Cluster}
|
1729 | 7352d33b | Thomas Thrainer | @param cluster: the cluster object
|
1730 | 7352d33b | Thomas Thrainer | @param instances: list of L{objects.Instance}
|
1731 | 7352d33b | Thomas Thrainer | @param instances: additional instances from which to obtain parameters
|
1732 | 7352d33b | Thomas Thrainer | @rtype: list of (origin, hypervisor, parameters)
|
1733 | 7352d33b | Thomas Thrainer | @return: a list with all parameters found, indicating the hypervisor they
|
1734 | 7352d33b | Thomas Thrainer | apply to, and the origin (can be "cluster", "os X", or "instance Y")
|
1735 | 7352d33b | Thomas Thrainer |
|
1736 | 7352d33b | Thomas Thrainer | """
|
1737 | 7352d33b | Thomas Thrainer | hvp_data = [] |
1738 | 7352d33b | Thomas Thrainer | |
1739 | 7352d33b | Thomas Thrainer | for hv_name in cluster.enabled_hypervisors: |
1740 | 7352d33b | Thomas Thrainer | hvp_data.append(("cluster", hv_name, cluster.GetHVDefaults(hv_name)))
|
1741 | 7352d33b | Thomas Thrainer | |
1742 | 7352d33b | Thomas Thrainer | for os_name, os_hvp in cluster.os_hvp.items(): |
1743 | 7352d33b | Thomas Thrainer | for hv_name, hv_params in os_hvp.items(): |
1744 | 7352d33b | Thomas Thrainer | if hv_params:
|
1745 | 7352d33b | Thomas Thrainer | full_params = cluster.GetHVDefaults(hv_name, os_name=os_name) |
1746 | 7352d33b | Thomas Thrainer | hvp_data.append(("os %s" % os_name, hv_name, full_params))
|
1747 | 7352d33b | Thomas Thrainer | |
1748 | 7352d33b | Thomas Thrainer | # TODO: collapse identical parameter values in a single one
|
1749 | 7352d33b | Thomas Thrainer | for instance in instances: |
1750 | 7352d33b | Thomas Thrainer | if instance.hvparams:
|
1751 | 7352d33b | Thomas Thrainer | hvp_data.append(("instance %s" % instance.name, instance.hypervisor,
|
1752 | 7352d33b | Thomas Thrainer | cluster.FillHV(instance))) |
1753 | 7352d33b | Thomas Thrainer | |
1754 | 7352d33b | Thomas Thrainer | return hvp_data
|
1755 | 7352d33b | Thomas Thrainer | |
1756 | 7352d33b | Thomas Thrainer | |
1757 | 7352d33b | Thomas Thrainer | class LUClusterVerifyConfig(NoHooksLU, _VerifyErrors): |
1758 | 7352d33b | Thomas Thrainer | """Verifies the cluster config.
|
1759 | 7352d33b | Thomas Thrainer |
|
1760 | 7352d33b | Thomas Thrainer | """
|
1761 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
1762 | 7352d33b | Thomas Thrainer | |
1763 | 7352d33b | Thomas Thrainer | def _VerifyHVP(self, hvp_data): |
1764 | 7352d33b | Thomas Thrainer | """Verifies locally the syntax of the hypervisor parameters.
|
1765 | 7352d33b | Thomas Thrainer |
|
1766 | 7352d33b | Thomas Thrainer | """
|
1767 | 7352d33b | Thomas Thrainer | for item, hv_name, hv_params in hvp_data: |
1768 | 7352d33b | Thomas Thrainer | msg = ("hypervisor %s parameters syntax check (source %s): %%s" %
|
1769 | 7352d33b | Thomas Thrainer | (item, hv_name)) |
1770 | 7352d33b | Thomas Thrainer | try:
|
1771 | 7352d33b | Thomas Thrainer | hv_class = hypervisor.GetHypervisorClass(hv_name) |
1772 | 7352d33b | Thomas Thrainer | utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES) |
1773 | 7352d33b | Thomas Thrainer | hv_class.CheckParameterSyntax(hv_params) |
1774 | 7352d33b | Thomas Thrainer | except errors.GenericError, err:
|
1775 | 7352d33b | Thomas Thrainer | self._ErrorIf(True, constants.CV_ECLUSTERCFG, None, msg % str(err)) |
1776 | 7352d33b | Thomas Thrainer | |
1777 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
1778 | 7352d33b | Thomas Thrainer | self.needed_locks = dict.fromkeys(locking.LEVELS, locking.ALL_SET) |
1779 | 5eacbcae | Thomas Thrainer | self.share_locks = ShareAll()
|
1780 | 7352d33b | Thomas Thrainer | |
1781 | 7352d33b | Thomas Thrainer | def CheckPrereq(self): |
1782 | 7352d33b | Thomas Thrainer | """Check prerequisites.
|
1783 | 7352d33b | Thomas Thrainer |
|
1784 | 7352d33b | Thomas Thrainer | """
|
1785 | 7352d33b | Thomas Thrainer | # Retrieve all information
|
1786 | 7352d33b | Thomas Thrainer | self.all_group_info = self.cfg.GetAllNodeGroupsInfo() |
1787 | 7352d33b | Thomas Thrainer | self.all_node_info = self.cfg.GetAllNodesInfo() |
1788 | 7352d33b | Thomas Thrainer | self.all_inst_info = self.cfg.GetAllInstancesInfo() |
1789 | 7352d33b | Thomas Thrainer | |
1790 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
1791 | 7352d33b | Thomas Thrainer | """Verify integrity of cluster, performing various test on nodes.
|
1792 | 7352d33b | Thomas Thrainer |
|
1793 | 7352d33b | Thomas Thrainer | """
|
1794 | 7352d33b | Thomas Thrainer | self.bad = False |
1795 | 7352d33b | Thomas Thrainer | self._feedback_fn = feedback_fn
|
1796 | 7352d33b | Thomas Thrainer | |
1797 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying cluster config")
|
1798 | 7352d33b | Thomas Thrainer | |
1799 | 7352d33b | Thomas Thrainer | for msg in self.cfg.VerifyConfig(): |
1800 | 7352d33b | Thomas Thrainer | self._ErrorIf(True, constants.CV_ECLUSTERCFG, None, msg) |
1801 | 7352d33b | Thomas Thrainer | |
1802 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying cluster certificate files")
|
1803 | 7352d33b | Thomas Thrainer | |
1804 | 7352d33b | Thomas Thrainer | for cert_filename in pathutils.ALL_CERT_FILES: |
1805 | a6c43c02 | Helga Velroyen | (errcode, msg) = utils.VerifyCertificate(cert_filename) |
1806 | 7352d33b | Thomas Thrainer | self._ErrorIf(errcode, constants.CV_ECLUSTERCERT, None, msg, code=errcode) |
1807 | 7352d33b | Thomas Thrainer | |
1808 | a5b9e2f2 | Thomas Thrainer | self._ErrorIf(not utils.CanRead(constants.LUXID_USER, |
1809 | 69ac3b74 | Michele Tartara | pathutils.NODED_CERT_FILE), |
1810 | 69ac3b74 | Michele Tartara | constants.CV_ECLUSTERCERT, |
1811 | 69ac3b74 | Michele Tartara | None,
|
1812 | 69ac3b74 | Michele Tartara | pathutils.NODED_CERT_FILE + " must be accessible by the " +
|
1813 | a5b9e2f2 | Thomas Thrainer | constants.LUXID_USER + " user")
|
1814 | 69ac3b74 | Michele Tartara | |
1815 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying hypervisor parameters")
|
1816 | 7352d33b | Thomas Thrainer | |
1817 | 7352d33b | Thomas Thrainer | self._VerifyHVP(_GetAllHypervisorParameters(self.cfg.GetClusterInfo(), |
1818 | 7352d33b | Thomas Thrainer | self.all_inst_info.values()))
|
1819 | 7352d33b | Thomas Thrainer | |
1820 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying all nodes belong to an existing group")
|
1821 | 7352d33b | Thomas Thrainer | |
1822 | 7352d33b | Thomas Thrainer | # We do this verification here because, should this bogus circumstance
|
1823 | 7352d33b | Thomas Thrainer | # occur, it would never be caught by VerifyGroup, which only acts on
|
1824 | 7352d33b | Thomas Thrainer | # nodes/instances reachable from existing node groups.
|
1825 | 7352d33b | Thomas Thrainer | |
1826 | 1c3231aa | Thomas Thrainer | dangling_nodes = set(node for node in self.all_node_info.values() |
1827 | 7352d33b | Thomas Thrainer | if node.group not in self.all_group_info) |
1828 | 7352d33b | Thomas Thrainer | |
1829 | 7352d33b | Thomas Thrainer | dangling_instances = {} |
1830 | 7352d33b | Thomas Thrainer | no_node_instances = [] |
1831 | 7352d33b | Thomas Thrainer | |
1832 | 7352d33b | Thomas Thrainer | for inst in self.all_inst_info.values(): |
1833 | 1c3231aa | Thomas Thrainer | if inst.primary_node in [node.uuid for node in dangling_nodes]: |
1834 | da4a52a3 | Thomas Thrainer | dangling_instances.setdefault(inst.primary_node, []).append(inst) |
1835 | 7352d33b | Thomas Thrainer | elif inst.primary_node not in self.all_node_info: |
1836 | da4a52a3 | Thomas Thrainer | no_node_instances.append(inst) |
1837 | 7352d33b | Thomas Thrainer | |
1838 | 7352d33b | Thomas Thrainer | pretty_dangling = [ |
1839 | 7352d33b | Thomas Thrainer | "%s (%s)" %
|
1840 | 7352d33b | Thomas Thrainer | (node.name, |
1841 | 24e96ef6 | Thomas Thrainer | utils.CommaJoin(inst.name for
|
1842 | 24e96ef6 | Thomas Thrainer | inst in dangling_instances.get(node.uuid, [])))
|
1843 | 7352d33b | Thomas Thrainer | for node in dangling_nodes] |
1844 | 7352d33b | Thomas Thrainer | |
1845 | 7352d33b | Thomas Thrainer | self._ErrorIf(bool(dangling_nodes), constants.CV_ECLUSTERDANGLINGNODES, |
1846 | 7352d33b | Thomas Thrainer | None,
|
1847 | 7352d33b | Thomas Thrainer | "the following nodes (and their instances) belong to a non"
|
1848 | 7352d33b | Thomas Thrainer | " existing group: %s", utils.CommaJoin(pretty_dangling))
|
1849 | 7352d33b | Thomas Thrainer | |
1850 | 7352d33b | Thomas Thrainer | self._ErrorIf(bool(no_node_instances), constants.CV_ECLUSTERDANGLINGINST, |
1851 | 7352d33b | Thomas Thrainer | None,
|
1852 | 7352d33b | Thomas Thrainer | "the following instances have a non-existing primary-node:"
|
1853 | 24e96ef6 | Thomas Thrainer | " %s", utils.CommaJoin(inst.name for |
1854 | 24e96ef6 | Thomas Thrainer | inst in no_node_instances))
|
1855 | 7352d33b | Thomas Thrainer | |
1856 | 7352d33b | Thomas Thrainer | return not self.bad |
1857 | 7352d33b | Thomas Thrainer | |
1858 | 7352d33b | Thomas Thrainer | |
1859 | 7352d33b | Thomas Thrainer | class LUClusterVerifyGroup(LogicalUnit, _VerifyErrors): |
1860 | 7352d33b | Thomas Thrainer | """Verifies the status of a node group.
|
1861 | 7352d33b | Thomas Thrainer |
|
1862 | 7352d33b | Thomas Thrainer | """
|
1863 | 7352d33b | Thomas Thrainer | HPATH = "cluster-verify"
|
1864 | 7352d33b | Thomas Thrainer | HTYPE = constants.HTYPE_CLUSTER |
1865 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
1866 | 7352d33b | Thomas Thrainer | |
1867 | 7352d33b | Thomas Thrainer | _HOOKS_INDENT_RE = re.compile("^", re.M)
|
1868 | 7352d33b | Thomas Thrainer | |
1869 | 7352d33b | Thomas Thrainer | class NodeImage(object): |
1870 | 7352d33b | Thomas Thrainer | """A class representing the logical and physical status of a node.
|
1871 | 7352d33b | Thomas Thrainer |
|
1872 | 1c3231aa | Thomas Thrainer | @type uuid: string
|
1873 | 1c3231aa | Thomas Thrainer | @ivar uuid: the node UUID to which this object refers
|
1874 | 7352d33b | Thomas Thrainer | @ivar volumes: a structure as returned from
|
1875 | 7352d33b | Thomas Thrainer | L{ganeti.backend.GetVolumeList} (runtime)
|
1876 | 7352d33b | Thomas Thrainer | @ivar instances: a list of running instances (runtime)
|
1877 | 7352d33b | Thomas Thrainer | @ivar pinst: list of configured primary instances (config)
|
1878 | 7352d33b | Thomas Thrainer | @ivar sinst: list of configured secondary instances (config)
|
1879 | 7352d33b | Thomas Thrainer | @ivar sbp: dictionary of {primary-node: list of instances} for all
|
1880 | 7352d33b | Thomas Thrainer | instances for which this node is secondary (config)
|
1881 | 7352d33b | Thomas Thrainer | @ivar mfree: free memory, as reported by hypervisor (runtime)
|
1882 | 7352d33b | Thomas Thrainer | @ivar dfree: free disk, as reported by the node (runtime)
|
1883 | 7352d33b | Thomas Thrainer | @ivar offline: the offline status (config)
|
1884 | 7352d33b | Thomas Thrainer | @type rpc_fail: boolean
|
1885 | 7352d33b | Thomas Thrainer | @ivar rpc_fail: whether the RPC verify call was successfull (overall,
|
1886 | 7352d33b | Thomas Thrainer | not whether the individual keys were correct) (runtime)
|
1887 | 7352d33b | Thomas Thrainer | @type lvm_fail: boolean
|
1888 | 7352d33b | Thomas Thrainer | @ivar lvm_fail: whether the RPC call didn't return valid LVM data
|
1889 | 7352d33b | Thomas Thrainer | @type hyp_fail: boolean
|
1890 | 7352d33b | Thomas Thrainer | @ivar hyp_fail: whether the RPC call didn't return the instance list
|
1891 | 7352d33b | Thomas Thrainer | @type ghost: boolean
|
1892 | 7352d33b | Thomas Thrainer | @ivar ghost: whether this is a known node or not (config)
|
1893 | 7352d33b | Thomas Thrainer | @type os_fail: boolean
|
1894 | 7352d33b | Thomas Thrainer | @ivar os_fail: whether the RPC call didn't return valid OS data
|
1895 | 7352d33b | Thomas Thrainer | @type oslist: list
|
1896 | 7352d33b | Thomas Thrainer | @ivar oslist: list of OSes as diagnosed by DiagnoseOS
|
1897 | 7352d33b | Thomas Thrainer | @type vm_capable: boolean
|
1898 | 7352d33b | Thomas Thrainer | @ivar vm_capable: whether the node can host instances
|
1899 | 7352d33b | Thomas Thrainer | @type pv_min: float
|
1900 | 7352d33b | Thomas Thrainer | @ivar pv_min: size in MiB of the smallest PVs
|
1901 | 7352d33b | Thomas Thrainer | @type pv_max: float
|
1902 | 7352d33b | Thomas Thrainer | @ivar pv_max: size in MiB of the biggest PVs
|
1903 | 7352d33b | Thomas Thrainer |
|
1904 | 7352d33b | Thomas Thrainer | """
|
1905 | 1c3231aa | Thomas Thrainer | def __init__(self, offline=False, uuid=None, vm_capable=True): |
1906 | 1c3231aa | Thomas Thrainer | self.uuid = uuid
|
1907 | 7352d33b | Thomas Thrainer | self.volumes = {}
|
1908 | 7352d33b | Thomas Thrainer | self.instances = []
|
1909 | 7352d33b | Thomas Thrainer | self.pinst = []
|
1910 | 7352d33b | Thomas Thrainer | self.sinst = []
|
1911 | 7352d33b | Thomas Thrainer | self.sbp = {}
|
1912 | 7352d33b | Thomas Thrainer | self.mfree = 0 |
1913 | 7352d33b | Thomas Thrainer | self.dfree = 0 |
1914 | 7352d33b | Thomas Thrainer | self.offline = offline
|
1915 | 7352d33b | Thomas Thrainer | self.vm_capable = vm_capable
|
1916 | 7352d33b | Thomas Thrainer | self.rpc_fail = False |
1917 | 7352d33b | Thomas Thrainer | self.lvm_fail = False |
1918 | 7352d33b | Thomas Thrainer | self.hyp_fail = False |
1919 | 7352d33b | Thomas Thrainer | self.ghost = False |
1920 | 7352d33b | Thomas Thrainer | self.os_fail = False |
1921 | 7352d33b | Thomas Thrainer | self.oslist = {}
|
1922 | 7352d33b | Thomas Thrainer | self.pv_min = None |
1923 | 7352d33b | Thomas Thrainer | self.pv_max = None |
1924 | 7352d33b | Thomas Thrainer | |
1925 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
1926 | 7352d33b | Thomas Thrainer | # This raises errors.OpPrereqError on its own:
|
1927 | 7352d33b | Thomas Thrainer | self.group_uuid = self.cfg.LookupNodeGroup(self.op.group_name) |
1928 | 7352d33b | Thomas Thrainer | |
1929 | 7352d33b | Thomas Thrainer | # Get instances in node group; this is unsafe and needs verification later
|
1930 | da4a52a3 | Thomas Thrainer | inst_uuids = \ |
1931 | 7352d33b | Thomas Thrainer | self.cfg.GetNodeGroupInstances(self.group_uuid, primary_only=True) |
1932 | 7352d33b | Thomas Thrainer | |
1933 | 7352d33b | Thomas Thrainer | self.needed_locks = {
|
1934 | da4a52a3 | Thomas Thrainer | locking.LEVEL_INSTANCE: self.cfg.GetInstanceNames(inst_uuids),
|
1935 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODEGROUP: [self.group_uuid],
|
1936 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE: [], |
1937 | 7352d33b | Thomas Thrainer | |
1938 | 7352d33b | Thomas Thrainer | # This opcode is run by watcher every five minutes and acquires all nodes
|
1939 | 7352d33b | Thomas Thrainer | # for a group. It doesn't run for a long time, so it's better to acquire
|
1940 | 7352d33b | Thomas Thrainer | # the node allocation lock as well.
|
1941 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODE_ALLOC: locking.ALL_SET, |
1942 | 7352d33b | Thomas Thrainer | } |
1943 | 7352d33b | Thomas Thrainer | |
1944 | 5eacbcae | Thomas Thrainer | self.share_locks = ShareAll()
|
1945 | 7352d33b | Thomas Thrainer | |
1946 | 7352d33b | Thomas Thrainer | def DeclareLocks(self, level): |
1947 | 7352d33b | Thomas Thrainer | if level == locking.LEVEL_NODE:
|
1948 | 7352d33b | Thomas Thrainer | # Get members of node group; this is unsafe and needs verification later
|
1949 | 7352d33b | Thomas Thrainer | nodes = set(self.cfg.GetNodeGroup(self.group_uuid).members) |
1950 | 7352d33b | Thomas Thrainer | |
1951 | 7352d33b | Thomas Thrainer | # In Exec(), we warn about mirrored instances that have primary and
|
1952 | 7352d33b | Thomas Thrainer | # secondary living in separate node groups. To fully verify that
|
1953 | 7352d33b | Thomas Thrainer | # volumes for these instances are healthy, we will need to do an
|
1954 | 7352d33b | Thomas Thrainer | # extra call to their secondaries. We ensure here those nodes will
|
1955 | 7352d33b | Thomas Thrainer | # be locked.
|
1956 | da4a52a3 | Thomas Thrainer | for inst_name in self.owned_locks(locking.LEVEL_INSTANCE): |
1957 | 7352d33b | Thomas Thrainer | # Important: access only the instances whose lock is owned
|
1958 | da4a52a3 | Thomas Thrainer | instance = self.cfg.GetInstanceInfoByName(inst_name)
|
1959 | da4a52a3 | Thomas Thrainer | if instance.disk_template in constants.DTS_INT_MIRROR: |
1960 | da4a52a3 | Thomas Thrainer | nodes.update(instance.secondary_nodes) |
1961 | 7352d33b | Thomas Thrainer | |
1962 | 7352d33b | Thomas Thrainer | self.needed_locks[locking.LEVEL_NODE] = nodes
|
1963 | 7352d33b | Thomas Thrainer | |
1964 | 7352d33b | Thomas Thrainer | def CheckPrereq(self): |
1965 | 7352d33b | Thomas Thrainer | assert self.group_uuid in self.owned_locks(locking.LEVEL_NODEGROUP) |
1966 | 7352d33b | Thomas Thrainer | self.group_info = self.cfg.GetNodeGroup(self.group_uuid) |
1967 | 7352d33b | Thomas Thrainer | |
1968 | 1c3231aa | Thomas Thrainer | group_node_uuids = set(self.group_info.members) |
1969 | da4a52a3 | Thomas Thrainer | group_inst_uuids = \ |
1970 | 7352d33b | Thomas Thrainer | self.cfg.GetNodeGroupInstances(self.group_uuid, primary_only=True) |
1971 | 7352d33b | Thomas Thrainer | |
1972 | 1c3231aa | Thomas Thrainer | unlocked_node_uuids = \ |
1973 | 1c3231aa | Thomas Thrainer | group_node_uuids.difference(self.owned_locks(locking.LEVEL_NODE))
|
1974 | 7352d33b | Thomas Thrainer | |
1975 | da4a52a3 | Thomas Thrainer | unlocked_inst_uuids = \ |
1976 | da4a52a3 | Thomas Thrainer | group_inst_uuids.difference( |
1977 | da4a52a3 | Thomas Thrainer | [self.cfg.GetInstanceInfoByName(name).uuid
|
1978 | da4a52a3 | Thomas Thrainer | for name in self.owned_locks(locking.LEVEL_INSTANCE)]) |
1979 | 7352d33b | Thomas Thrainer | |
1980 | 1c3231aa | Thomas Thrainer | if unlocked_node_uuids:
|
1981 | 1c3231aa | Thomas Thrainer | raise errors.OpPrereqError(
|
1982 | 1c3231aa | Thomas Thrainer | "Missing lock for nodes: %s" %
|
1983 | 1c3231aa | Thomas Thrainer | utils.CommaJoin(self.cfg.GetNodeNames(unlocked_node_uuids)),
|
1984 | 1c3231aa | Thomas Thrainer | errors.ECODE_STATE) |
1985 | 7352d33b | Thomas Thrainer | |
1986 | da4a52a3 | Thomas Thrainer | if unlocked_inst_uuids:
|
1987 | da4a52a3 | Thomas Thrainer | raise errors.OpPrereqError(
|
1988 | da4a52a3 | Thomas Thrainer | "Missing lock for instances: %s" %
|
1989 | da4a52a3 | Thomas Thrainer | utils.CommaJoin(self.cfg.GetInstanceNames(unlocked_inst_uuids)),
|
1990 | da4a52a3 | Thomas Thrainer | errors.ECODE_STATE) |
1991 | 7352d33b | Thomas Thrainer | |
1992 | 7352d33b | Thomas Thrainer | self.all_node_info = self.cfg.GetAllNodesInfo() |
1993 | 7352d33b | Thomas Thrainer | self.all_inst_info = self.cfg.GetAllInstancesInfo() |
1994 | 7352d33b | Thomas Thrainer | |
1995 | 1c3231aa | Thomas Thrainer | self.my_node_uuids = group_node_uuids
|
1996 | 1c3231aa | Thomas Thrainer | self.my_node_info = dict((node_uuid, self.all_node_info[node_uuid]) |
1997 | 1c3231aa | Thomas Thrainer | for node_uuid in group_node_uuids) |
1998 | 7352d33b | Thomas Thrainer | |
1999 | da4a52a3 | Thomas Thrainer | self.my_inst_uuids = group_inst_uuids
|
2000 | da4a52a3 | Thomas Thrainer | self.my_inst_info = dict((inst_uuid, self.all_inst_info[inst_uuid]) |
2001 | da4a52a3 | Thomas Thrainer | for inst_uuid in group_inst_uuids) |
2002 | 7352d33b | Thomas Thrainer | |
2003 | 7352d33b | Thomas Thrainer | # We detect here the nodes that will need the extra RPC calls for verifying
|
2004 | 7352d33b | Thomas Thrainer | # split LV volumes; they should be locked.
|
2005 | 7352d33b | Thomas Thrainer | extra_lv_nodes = set()
|
2006 | 7352d33b | Thomas Thrainer | |
2007 | 7352d33b | Thomas Thrainer | for inst in self.my_inst_info.values(): |
2008 | 7352d33b | Thomas Thrainer | if inst.disk_template in constants.DTS_INT_MIRROR: |
2009 | 1c3231aa | Thomas Thrainer | for nuuid in inst.all_nodes: |
2010 | 1c3231aa | Thomas Thrainer | if self.all_node_info[nuuid].group != self.group_uuid: |
2011 | 1c3231aa | Thomas Thrainer | extra_lv_nodes.add(nuuid) |
2012 | 7352d33b | Thomas Thrainer | |
2013 | 7352d33b | Thomas Thrainer | unlocked_lv_nodes = \ |
2014 | 7352d33b | Thomas Thrainer | extra_lv_nodes.difference(self.owned_locks(locking.LEVEL_NODE))
|
2015 | 7352d33b | Thomas Thrainer | |
2016 | 7352d33b | Thomas Thrainer | if unlocked_lv_nodes:
|
2017 | 7352d33b | Thomas Thrainer | raise errors.OpPrereqError("Missing node locks for LV check: %s" % |
2018 | 7352d33b | Thomas Thrainer | utils.CommaJoin(unlocked_lv_nodes), |
2019 | 7352d33b | Thomas Thrainer | errors.ECODE_STATE) |
2020 | 7352d33b | Thomas Thrainer | self.extra_lv_nodes = list(extra_lv_nodes) |
2021 | 7352d33b | Thomas Thrainer | |
2022 | 7352d33b | Thomas Thrainer | def _VerifyNode(self, ninfo, nresult): |
2023 | 7352d33b | Thomas Thrainer | """Perform some basic validation on data returned from a node.
|
2024 | 7352d33b | Thomas Thrainer |
|
2025 | 7352d33b | Thomas Thrainer | - check the result data structure is well formed and has all the
|
2026 | 7352d33b | Thomas Thrainer | mandatory fields
|
2027 | 7352d33b | Thomas Thrainer | - check ganeti version
|
2028 | 7352d33b | Thomas Thrainer |
|
2029 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2030 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2031 | 7352d33b | Thomas Thrainer | @param nresult: the results from the node
|
2032 | 7352d33b | Thomas Thrainer | @rtype: boolean
|
2033 | 7352d33b | Thomas Thrainer | @return: whether overall this call was successful (and we can expect
|
2034 | 7352d33b | Thomas Thrainer | reasonable values in the respose)
|
2035 | 7352d33b | Thomas Thrainer |
|
2036 | 7352d33b | Thomas Thrainer | """
|
2037 | 7352d33b | Thomas Thrainer | # main result, nresult should be a non-empty dict
|
2038 | 7352d33b | Thomas Thrainer | test = not nresult or not isinstance(nresult, dict) |
2039 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODERPC, ninfo.name,
|
2040 | 7352d33b | Thomas Thrainer | "unable to verify node: no data returned")
|
2041 | 7352d33b | Thomas Thrainer | if test:
|
2042 | 7352d33b | Thomas Thrainer | return False |
2043 | 7352d33b | Thomas Thrainer | |
2044 | 7352d33b | Thomas Thrainer | # compares ganeti version
|
2045 | 7352d33b | Thomas Thrainer | local_version = constants.PROTOCOL_VERSION |
2046 | 7352d33b | Thomas Thrainer | remote_version = nresult.get("version", None) |
2047 | 7352d33b | Thomas Thrainer | test = not (remote_version and |
2048 | 7352d33b | Thomas Thrainer | isinstance(remote_version, (list, tuple)) and |
2049 | 7352d33b | Thomas Thrainer | len(remote_version) == 2) |
2050 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODERPC, ninfo.name,
|
2051 | d0d7d7cf | Thomas Thrainer | "connection to node returned invalid data")
|
2052 | 7352d33b | Thomas Thrainer | if test:
|
2053 | 7352d33b | Thomas Thrainer | return False |
2054 | 7352d33b | Thomas Thrainer | |
2055 | 7352d33b | Thomas Thrainer | test = local_version != remote_version[0]
|
2056 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEVERSION, ninfo.name,
|
2057 | d0d7d7cf | Thomas Thrainer | "incompatible protocol versions: master %s,"
|
2058 | d0d7d7cf | Thomas Thrainer | " node %s", local_version, remote_version[0]) |
2059 | 7352d33b | Thomas Thrainer | if test:
|
2060 | 7352d33b | Thomas Thrainer | return False |
2061 | 7352d33b | Thomas Thrainer | |
2062 | 7352d33b | Thomas Thrainer | # node seems compatible, we can actually try to look into its results
|
2063 | 7352d33b | Thomas Thrainer | |
2064 | 7352d33b | Thomas Thrainer | # full package version
|
2065 | 7352d33b | Thomas Thrainer | self._ErrorIf(constants.RELEASE_VERSION != remote_version[1], |
2066 | d0d7d7cf | Thomas Thrainer | constants.CV_ENODEVERSION, ninfo.name, |
2067 | 7352d33b | Thomas Thrainer | "software version mismatch: master %s, node %s",
|
2068 | 7352d33b | Thomas Thrainer | constants.RELEASE_VERSION, remote_version[1],
|
2069 | 7352d33b | Thomas Thrainer | code=self.ETYPE_WARNING)
|
2070 | 7352d33b | Thomas Thrainer | |
2071 | 7352d33b | Thomas Thrainer | hyp_result = nresult.get(constants.NV_HYPERVISOR, None)
|
2072 | 7352d33b | Thomas Thrainer | if ninfo.vm_capable and isinstance(hyp_result, dict): |
2073 | 7352d33b | Thomas Thrainer | for hv_name, hv_result in hyp_result.iteritems(): |
2074 | 7352d33b | Thomas Thrainer | test = hv_result is not None |
2075 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEHV, ninfo.name,
|
2076 | d0d7d7cf | Thomas Thrainer | "hypervisor %s verify failure: '%s'", hv_name, hv_result)
|
2077 | 7352d33b | Thomas Thrainer | |
2078 | 7352d33b | Thomas Thrainer | hvp_result = nresult.get(constants.NV_HVPARAMS, None)
|
2079 | 7352d33b | Thomas Thrainer | if ninfo.vm_capable and isinstance(hvp_result, list): |
2080 | 7352d33b | Thomas Thrainer | for item, hv_name, hv_result in hvp_result: |
2081 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODEHV, ninfo.name, |
2082 | d0d7d7cf | Thomas Thrainer | "hypervisor %s parameter verify failure (source %s): %s",
|
2083 | d0d7d7cf | Thomas Thrainer | hv_name, item, hv_result) |
2084 | 7352d33b | Thomas Thrainer | |
2085 | 7352d33b | Thomas Thrainer | test = nresult.get(constants.NV_NODESETUP, |
2086 | 7352d33b | Thomas Thrainer | ["Missing NODESETUP results"])
|
2087 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODESETUP, ninfo.name,
|
2088 | d0d7d7cf | Thomas Thrainer | "node setup error: %s", "; ".join(test)) |
2089 | 7352d33b | Thomas Thrainer | |
2090 | 7352d33b | Thomas Thrainer | return True |
2091 | 7352d33b | Thomas Thrainer | |
2092 | 7352d33b | Thomas Thrainer | def _VerifyNodeTime(self, ninfo, nresult, |
2093 | 7352d33b | Thomas Thrainer | nvinfo_starttime, nvinfo_endtime): |
2094 | 7352d33b | Thomas Thrainer | """Check the node time.
|
2095 | 7352d33b | Thomas Thrainer |
|
2096 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2097 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2098 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2099 | 7352d33b | Thomas Thrainer | @param nvinfo_starttime: the start time of the RPC call
|
2100 | 7352d33b | Thomas Thrainer | @param nvinfo_endtime: the end time of the RPC call
|
2101 | 7352d33b | Thomas Thrainer |
|
2102 | 7352d33b | Thomas Thrainer | """
|
2103 | 7352d33b | Thomas Thrainer | ntime = nresult.get(constants.NV_TIME, None)
|
2104 | 7352d33b | Thomas Thrainer | try:
|
2105 | 7352d33b | Thomas Thrainer | ntime_merged = utils.MergeTime(ntime) |
2106 | 7352d33b | Thomas Thrainer | except (ValueError, TypeError): |
2107 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODETIME, ninfo.name, |
2108 | d0d7d7cf | Thomas Thrainer | "Node returned invalid time")
|
2109 | 7352d33b | Thomas Thrainer | return
|
2110 | 7352d33b | Thomas Thrainer | |
2111 | 7352d33b | Thomas Thrainer | if ntime_merged < (nvinfo_starttime - constants.NODE_MAX_CLOCK_SKEW):
|
2112 | 7352d33b | Thomas Thrainer | ntime_diff = "%.01fs" % abs(nvinfo_starttime - ntime_merged) |
2113 | 7352d33b | Thomas Thrainer | elif ntime_merged > (nvinfo_endtime + constants.NODE_MAX_CLOCK_SKEW):
|
2114 | 7352d33b | Thomas Thrainer | ntime_diff = "%.01fs" % abs(ntime_merged - nvinfo_endtime) |
2115 | 7352d33b | Thomas Thrainer | else:
|
2116 | 7352d33b | Thomas Thrainer | ntime_diff = None
|
2117 | 7352d33b | Thomas Thrainer | |
2118 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(ntime_diff is not None, constants.CV_ENODETIME, ninfo.name, |
2119 | d0d7d7cf | Thomas Thrainer | "Node time diverges by at least %s from master node time",
|
2120 | d0d7d7cf | Thomas Thrainer | ntime_diff) |
2121 | 7352d33b | Thomas Thrainer | |
2122 | 7352d33b | Thomas Thrainer | def _UpdateVerifyNodeLVM(self, ninfo, nresult, vg_name, nimg): |
2123 | 7352d33b | Thomas Thrainer | """Check the node LVM results and update info for cross-node checks.
|
2124 | 7352d33b | Thomas Thrainer |
|
2125 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2126 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2127 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2128 | 7352d33b | Thomas Thrainer | @param vg_name: the configured VG name
|
2129 | 7352d33b | Thomas Thrainer | @type nimg: L{NodeImage}
|
2130 | 7352d33b | Thomas Thrainer | @param nimg: node image
|
2131 | 7352d33b | Thomas Thrainer |
|
2132 | 7352d33b | Thomas Thrainer | """
|
2133 | 7352d33b | Thomas Thrainer | if vg_name is None: |
2134 | 7352d33b | Thomas Thrainer | return
|
2135 | 7352d33b | Thomas Thrainer | |
2136 | 7352d33b | Thomas Thrainer | # checks vg existence and size > 20G
|
2137 | 7352d33b | Thomas Thrainer | vglist = nresult.get(constants.NV_VGLIST, None)
|
2138 | 7352d33b | Thomas Thrainer | test = not vglist
|
2139 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODELVM, ninfo.name,
|
2140 | d0d7d7cf | Thomas Thrainer | "unable to check volume groups")
|
2141 | 7352d33b | Thomas Thrainer | if not test: |
2142 | 7352d33b | Thomas Thrainer | vgstatus = utils.CheckVolumeGroupSize(vglist, vg_name, |
2143 | 7352d33b | Thomas Thrainer | constants.MIN_VG_SIZE) |
2144 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(vgstatus, constants.CV_ENODELVM, ninfo.name, vgstatus)
|
2145 | 7352d33b | Thomas Thrainer | |
2146 | 7352d33b | Thomas Thrainer | # Check PVs
|
2147 | 5eacbcae | Thomas Thrainer | (errmsgs, pvminmax) = CheckNodePVs(nresult, self._exclusive_storage)
|
2148 | 7352d33b | Thomas Thrainer | for em in errmsgs: |
2149 | d0d7d7cf | Thomas Thrainer | self._Error(constants.CV_ENODELVM, ninfo.name, em)
|
2150 | 7352d33b | Thomas Thrainer | if pvminmax is not None: |
2151 | 7352d33b | Thomas Thrainer | (nimg.pv_min, nimg.pv_max) = pvminmax |
2152 | 7352d33b | Thomas Thrainer | |
2153 | 1bb99a33 | Bernardo Dal Seno | def _VerifyGroupDRBDVersion(self, node_verify_infos): |
2154 | 1bb99a33 | Bernardo Dal Seno | """Check cross-node DRBD version consistency.
|
2155 | 1bb99a33 | Bernardo Dal Seno |
|
2156 | 1bb99a33 | Bernardo Dal Seno | @type node_verify_infos: dict
|
2157 | 1bb99a33 | Bernardo Dal Seno | @param node_verify_infos: infos about nodes as returned from the
|
2158 | 1bb99a33 | Bernardo Dal Seno | node_verify call.
|
2159 | 1bb99a33 | Bernardo Dal Seno |
|
2160 | 1bb99a33 | Bernardo Dal Seno | """
|
2161 | 1bb99a33 | Bernardo Dal Seno | node_versions = {} |
2162 | 1c3231aa | Thomas Thrainer | for node_uuid, ndata in node_verify_infos.items(): |
2163 | 1bb99a33 | Bernardo Dal Seno | nresult = ndata.payload |
2164 | fb62843c | Klaus Aehlig | if nresult:
|
2165 | fb62843c | Klaus Aehlig | version = nresult.get(constants.NV_DRBDVERSION, "Missing DRBD version")
|
2166 | fb62843c | Klaus Aehlig | node_versions[node_uuid] = version |
2167 | 1bb99a33 | Bernardo Dal Seno | |
2168 | 1bb99a33 | Bernardo Dal Seno | if len(set(node_versions.values())) > 1: |
2169 | 1c3231aa | Thomas Thrainer | for node_uuid, version in sorted(node_versions.items()): |
2170 | 1bb99a33 | Bernardo Dal Seno | msg = "DRBD version mismatch: %s" % version
|
2171 | 1c3231aa | Thomas Thrainer | self._Error(constants.CV_ENODEDRBDHELPER, node_uuid, msg,
|
2172 | 1bb99a33 | Bernardo Dal Seno | code=self.ETYPE_WARNING)
|
2173 | 1bb99a33 | Bernardo Dal Seno | |
2174 | 7352d33b | Thomas Thrainer | def _VerifyGroupLVM(self, node_image, vg_name): |
2175 | 7352d33b | Thomas Thrainer | """Check cross-node consistency in LVM.
|
2176 | 7352d33b | Thomas Thrainer |
|
2177 | 7352d33b | Thomas Thrainer | @type node_image: dict
|
2178 | 7352d33b | Thomas Thrainer | @param node_image: info about nodes, mapping from node to names to
|
2179 | 7352d33b | Thomas Thrainer | L{NodeImage} objects
|
2180 | 7352d33b | Thomas Thrainer | @param vg_name: the configured VG name
|
2181 | 7352d33b | Thomas Thrainer |
|
2182 | 7352d33b | Thomas Thrainer | """
|
2183 | 7352d33b | Thomas Thrainer | if vg_name is None: |
2184 | 7352d33b | Thomas Thrainer | return
|
2185 | 7352d33b | Thomas Thrainer | |
2186 | bb935d8d | Thomas Thrainer | # Only exclusive storage needs this kind of checks
|
2187 | 7352d33b | Thomas Thrainer | if not self._exclusive_storage: |
2188 | 7352d33b | Thomas Thrainer | return
|
2189 | 7352d33b | Thomas Thrainer | |
2190 | 7352d33b | Thomas Thrainer | # exclusive_storage wants all PVs to have the same size (approximately),
|
2191 | 7352d33b | Thomas Thrainer | # if the smallest and the biggest ones are okay, everything is fine.
|
2192 | 7352d33b | Thomas Thrainer | # pv_min is None iff pv_max is None
|
2193 | 7352d33b | Thomas Thrainer | vals = filter((lambda ni: ni.pv_min is not None), node_image.values()) |
2194 | 7352d33b | Thomas Thrainer | if not vals: |
2195 | 7352d33b | Thomas Thrainer | return
|
2196 | bb935d8d | Thomas Thrainer | (pvmin, minnode_uuid) = min((ni.pv_min, ni.uuid) for ni in vals) |
2197 | bb935d8d | Thomas Thrainer | (pvmax, maxnode_uuid) = max((ni.pv_max, ni.uuid) for ni in vals) |
2198 | 7352d33b | Thomas Thrainer | bad = utils.LvmExclusiveTestBadPvSizes(pvmin, pvmax) |
2199 | 7352d33b | Thomas Thrainer | self._ErrorIf(bad, constants.CV_EGROUPDIFFERENTPVSIZE, self.group_info.name, |
2200 | 7352d33b | Thomas Thrainer | "PV sizes differ too much in the group; smallest (%s MB) is"
|
2201 | 7352d33b | Thomas Thrainer | " on %s, biggest (%s MB) is on %s",
|
2202 | bb935d8d | Thomas Thrainer | pvmin, self.cfg.GetNodeName(minnode_uuid),
|
2203 | bb935d8d | Thomas Thrainer | pvmax, self.cfg.GetNodeName(maxnode_uuid))
|
2204 | 7352d33b | Thomas Thrainer | |
2205 | 7352d33b | Thomas Thrainer | def _VerifyNodeBridges(self, ninfo, nresult, bridges): |
2206 | 7352d33b | Thomas Thrainer | """Check the node bridges.
|
2207 | 7352d33b | Thomas Thrainer |
|
2208 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2209 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2210 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2211 | 7352d33b | Thomas Thrainer | @param bridges: the expected list of bridges
|
2212 | 7352d33b | Thomas Thrainer |
|
2213 | 7352d33b | Thomas Thrainer | """
|
2214 | 7352d33b | Thomas Thrainer | if not bridges: |
2215 | 7352d33b | Thomas Thrainer | return
|
2216 | 7352d33b | Thomas Thrainer | |
2217 | 7352d33b | Thomas Thrainer | missing = nresult.get(constants.NV_BRIDGES, None)
|
2218 | 7352d33b | Thomas Thrainer | test = not isinstance(missing, list) |
2219 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODENET, ninfo.name,
|
2220 | d0d7d7cf | Thomas Thrainer | "did not return valid bridge information")
|
2221 | 7352d33b | Thomas Thrainer | if not test: |
2222 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(bool(missing), constants.CV_ENODENET, ninfo.name, |
2223 | d0d7d7cf | Thomas Thrainer | "missing bridges: %s" % utils.CommaJoin(sorted(missing))) |
2224 | 7352d33b | Thomas Thrainer | |
2225 | 7352d33b | Thomas Thrainer | def _VerifyNodeUserScripts(self, ninfo, nresult): |
2226 | 7352d33b | Thomas Thrainer | """Check the results of user scripts presence and executability on the node
|
2227 | 7352d33b | Thomas Thrainer |
|
2228 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2229 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2230 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2231 | 7352d33b | Thomas Thrainer |
|
2232 | 7352d33b | Thomas Thrainer | """
|
2233 | 7352d33b | Thomas Thrainer | test = not constants.NV_USERSCRIPTS in nresult |
2234 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEUSERSCRIPTS, ninfo.name,
|
2235 | 7352d33b | Thomas Thrainer | "did not return user scripts information")
|
2236 | 7352d33b | Thomas Thrainer | |
2237 | 7352d33b | Thomas Thrainer | broken_scripts = nresult.get(constants.NV_USERSCRIPTS, None)
|
2238 | 7352d33b | Thomas Thrainer | if not test: |
2239 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(broken_scripts, constants.CV_ENODEUSERSCRIPTS, ninfo.name,
|
2240 | 7352d33b | Thomas Thrainer | "user scripts not present or not executable: %s" %
|
2241 | 7352d33b | Thomas Thrainer | utils.CommaJoin(sorted(broken_scripts)))
|
2242 | 7352d33b | Thomas Thrainer | |
2243 | 7352d33b | Thomas Thrainer | def _VerifyNodeNetwork(self, ninfo, nresult): |
2244 | 7352d33b | Thomas Thrainer | """Check the node network connectivity results.
|
2245 | 7352d33b | Thomas Thrainer |
|
2246 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2247 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2248 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2249 | 7352d33b | Thomas Thrainer |
|
2250 | 7352d33b | Thomas Thrainer | """
|
2251 | 7352d33b | Thomas Thrainer | test = constants.NV_NODELIST not in nresult |
2252 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODESSH, ninfo.name,
|
2253 | d0d7d7cf | Thomas Thrainer | "node hasn't returned node ssh connectivity data")
|
2254 | 7352d33b | Thomas Thrainer | if not test: |
2255 | 7352d33b | Thomas Thrainer | if nresult[constants.NV_NODELIST]:
|
2256 | 7352d33b | Thomas Thrainer | for a_node, a_msg in nresult[constants.NV_NODELIST].items(): |
2257 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODESSH, ninfo.name, |
2258 | d0d7d7cf | Thomas Thrainer | "ssh communication with node '%s': %s", a_node, a_msg)
|
2259 | 7352d33b | Thomas Thrainer | |
2260 | 7352d33b | Thomas Thrainer | test = constants.NV_NODENETTEST not in nresult |
2261 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODENET, ninfo.name,
|
2262 | d0d7d7cf | Thomas Thrainer | "node hasn't returned node tcp connectivity data")
|
2263 | 7352d33b | Thomas Thrainer | if not test: |
2264 | 7352d33b | Thomas Thrainer | if nresult[constants.NV_NODENETTEST]:
|
2265 | 7352d33b | Thomas Thrainer | nlist = utils.NiceSort(nresult[constants.NV_NODENETTEST].keys()) |
2266 | 7352d33b | Thomas Thrainer | for anode in nlist: |
2267 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODENET, ninfo.name, |
2268 | d0d7d7cf | Thomas Thrainer | "tcp communication with node '%s': %s",
|
2269 | d0d7d7cf | Thomas Thrainer | anode, nresult[constants.NV_NODENETTEST][anode]) |
2270 | 7352d33b | Thomas Thrainer | |
2271 | 7352d33b | Thomas Thrainer | test = constants.NV_MASTERIP not in nresult |
2272 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODENET, ninfo.name,
|
2273 | d0d7d7cf | Thomas Thrainer | "node hasn't returned node master IP reachability data")
|
2274 | 7352d33b | Thomas Thrainer | if not test: |
2275 | 7352d33b | Thomas Thrainer | if not nresult[constants.NV_MASTERIP]: |
2276 | 1c3231aa | Thomas Thrainer | if ninfo.uuid == self.master_node: |
2277 | 7352d33b | Thomas Thrainer | msg = "the master node cannot reach the master IP (not configured?)"
|
2278 | 7352d33b | Thomas Thrainer | else:
|
2279 | 7352d33b | Thomas Thrainer | msg = "cannot reach the master IP"
|
2280 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODENET, ninfo.name, msg) |
2281 | 7352d33b | Thomas Thrainer | |
2282 | da4a52a3 | Thomas Thrainer | def _VerifyInstance(self, instance, node_image, diskstatus): |
2283 | 7352d33b | Thomas Thrainer | """Verify an instance.
|
2284 | 7352d33b | Thomas Thrainer |
|
2285 | 7352d33b | Thomas Thrainer | This function checks to see if the required block devices are
|
2286 | 7352d33b | Thomas Thrainer | available on the instance's node, and that the nodes are in the correct
|
2287 | 7352d33b | Thomas Thrainer | state.
|
2288 | 7352d33b | Thomas Thrainer |
|
2289 | 7352d33b | Thomas Thrainer | """
|
2290 | da4a52a3 | Thomas Thrainer | pnode_uuid = instance.primary_node |
2291 | da4a52a3 | Thomas Thrainer | pnode_img = node_image[pnode_uuid] |
2292 | 7352d33b | Thomas Thrainer | groupinfo = self.cfg.GetAllNodeGroupsInfo()
|
2293 | 7352d33b | Thomas Thrainer | |
2294 | 7352d33b | Thomas Thrainer | node_vol_should = {} |
2295 | da4a52a3 | Thomas Thrainer | instance.MapLVsByNode(node_vol_should) |
2296 | 7352d33b | Thomas Thrainer | |
2297 | 7352d33b | Thomas Thrainer | cluster = self.cfg.GetClusterInfo()
|
2298 | 7352d33b | Thomas Thrainer | ipolicy = ganeti.masterd.instance.CalculateGroupIPolicy(cluster, |
2299 | 7352d33b | Thomas Thrainer | self.group_info)
|
2300 | da4a52a3 | Thomas Thrainer | err = ComputeIPolicyInstanceViolation(ipolicy, instance, self.cfg)
|
2301 | da4a52a3 | Thomas Thrainer | self._ErrorIf(err, constants.CV_EINSTANCEPOLICY, instance.name,
|
2302 | d0d7d7cf | Thomas Thrainer | utils.CommaJoin(err), code=self.ETYPE_WARNING)
|
2303 | 7352d33b | Thomas Thrainer | |
2304 | da4a52a3 | Thomas Thrainer | for node_uuid in node_vol_should: |
2305 | da4a52a3 | Thomas Thrainer | n_img = node_image[node_uuid] |
2306 | 7352d33b | Thomas Thrainer | if n_img.offline or n_img.rpc_fail or n_img.lvm_fail: |
2307 | 7352d33b | Thomas Thrainer | # ignore missing volumes on offline or broken nodes
|
2308 | 7352d33b | Thomas Thrainer | continue
|
2309 | da4a52a3 | Thomas Thrainer | for volume in node_vol_should[node_uuid]: |
2310 | 7352d33b | Thomas Thrainer | test = volume not in n_img.volumes |
2311 | da4a52a3 | Thomas Thrainer | self._ErrorIf(test, constants.CV_EINSTANCEMISSINGDISK, instance.name,
|
2312 | d0d7d7cf | Thomas Thrainer | "volume %s missing on node %s", volume,
|
2313 | da4a52a3 | Thomas Thrainer | self.cfg.GetNodeName(node_uuid))
|
2314 | 7352d33b | Thomas Thrainer | |
2315 | da4a52a3 | Thomas Thrainer | if instance.admin_state == constants.ADMINST_UP:
|
2316 | da4a52a3 | Thomas Thrainer | test = instance.uuid not in pnode_img.instances and not pnode_img.offline |
2317 | da4a52a3 | Thomas Thrainer | self._ErrorIf(test, constants.CV_EINSTANCEDOWN, instance.name,
|
2318 | d0d7d7cf | Thomas Thrainer | "instance not running on its primary node %s",
|
2319 | da4a52a3 | Thomas Thrainer | self.cfg.GetNodeName(pnode_uuid))
|
2320 | da4a52a3 | Thomas Thrainer | self._ErrorIf(pnode_img.offline, constants.CV_EINSTANCEBADNODE,
|
2321 | da4a52a3 | Thomas Thrainer | instance.name, "instance is marked as running and lives on"
|
2322 | da4a52a3 | Thomas Thrainer | " offline node %s", self.cfg.GetNodeName(pnode_uuid)) |
2323 | 7352d33b | Thomas Thrainer | |
2324 | 7352d33b | Thomas Thrainer | diskdata = [(nname, success, status, idx) |
2325 | 7352d33b | Thomas Thrainer | for (nname, disks) in diskstatus.items() |
2326 | 7352d33b | Thomas Thrainer | for idx, (success, status) in enumerate(disks)] |
2327 | 7352d33b | Thomas Thrainer | |
2328 | 7352d33b | Thomas Thrainer | for nname, success, bdev_status, idx in diskdata: |
2329 | 7352d33b | Thomas Thrainer | # the 'ghost node' construction in Exec() ensures that we have a
|
2330 | 7352d33b | Thomas Thrainer | # node here
|
2331 | 7352d33b | Thomas Thrainer | snode = node_image[nname] |
2332 | 7352d33b | Thomas Thrainer | bad_snode = snode.ghost or snode.offline
|
2333 | da4a52a3 | Thomas Thrainer | self._ErrorIf(instance.disks_active and |
2334 | d0d7d7cf | Thomas Thrainer | not success and not bad_snode, |
2335 | da4a52a3 | Thomas Thrainer | constants.CV_EINSTANCEFAULTYDISK, instance.name, |
2336 | d0d7d7cf | Thomas Thrainer | "couldn't retrieve status for disk/%s on %s: %s",
|
2337 | d0d7d7cf | Thomas Thrainer | idx, self.cfg.GetNodeName(nname), bdev_status)
|
2338 | 9b0e86e2 | Thomas Thrainer | |
2339 | da4a52a3 | Thomas Thrainer | if instance.disks_active and success and \ |
2340 | 9b0e86e2 | Thomas Thrainer | (bdev_status.is_degraded or
|
2341 | 9b0e86e2 | Thomas Thrainer | bdev_status.ldisk_status != constants.LDS_OKAY): |
2342 | 9b0e86e2 | Thomas Thrainer | msg = "disk/%s on %s" % (idx, self.cfg.GetNodeName(nname)) |
2343 | 9b0e86e2 | Thomas Thrainer | if bdev_status.is_degraded:
|
2344 | 9b0e86e2 | Thomas Thrainer | msg += " is degraded"
|
2345 | 9b0e86e2 | Thomas Thrainer | if bdev_status.ldisk_status != constants.LDS_OKAY:
|
2346 | 9b0e86e2 | Thomas Thrainer | msg += "; state is '%s'" % \
|
2347 | 9b0e86e2 | Thomas Thrainer | constants.LDS_NAMES[bdev_status.ldisk_status] |
2348 | 9b0e86e2 | Thomas Thrainer | |
2349 | da4a52a3 | Thomas Thrainer | self._Error(constants.CV_EINSTANCEFAULTYDISK, instance.name, msg)
|
2350 | d0d7d7cf | Thomas Thrainer | |
2351 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(pnode_img.rpc_fail and not pnode_img.offline, |
2352 | da4a52a3 | Thomas Thrainer | constants.CV_ENODERPC, self.cfg.GetNodeName(pnode_uuid),
|
2353 | da4a52a3 | Thomas Thrainer | "instance %s, connection to primary node failed",
|
2354 | da4a52a3 | Thomas Thrainer | instance.name) |
2355 | da4a52a3 | Thomas Thrainer | |
2356 | da4a52a3 | Thomas Thrainer | self._ErrorIf(len(instance.secondary_nodes) > 1, |
2357 | da4a52a3 | Thomas Thrainer | constants.CV_EINSTANCELAYOUT, instance.name, |
2358 | da4a52a3 | Thomas Thrainer | "instance has multiple secondary nodes: %s",
|
2359 | da4a52a3 | Thomas Thrainer | utils.CommaJoin(instance.secondary_nodes), |
2360 | d0d7d7cf | Thomas Thrainer | code=self.ETYPE_WARNING)
|
2361 | 7352d33b | Thomas Thrainer | |
2362 | da4a52a3 | Thomas Thrainer | es_flags = rpc.GetExclusiveStorageForNodes(self.cfg, instance.all_nodes)
|
2363 | c69b147d | Bernardo Dal Seno | if any(es_flags.values()): |
2364 | da4a52a3 | Thomas Thrainer | if instance.disk_template not in constants.DTS_EXCL_STORAGE: |
2365 | c69b147d | Bernardo Dal Seno | # Disk template not compatible with exclusive_storage: no instance
|
2366 | c69b147d | Bernardo Dal Seno | # node should have the flag set
|
2367 | c69b147d | Bernardo Dal Seno | es_nodes = [n |
2368 | c69b147d | Bernardo Dal Seno | for (n, es) in es_flags.items() |
2369 | c69b147d | Bernardo Dal Seno | if es]
|
2370 | da4a52a3 | Thomas Thrainer | self._Error(constants.CV_EINSTANCEUNSUITABLENODE, instance.name,
|
2371 | c69b147d | Bernardo Dal Seno | "instance has template %s, which is not supported on nodes"
|
2372 | c69b147d | Bernardo Dal Seno | " that have exclusive storage set: %s",
|
2373 | da4a52a3 | Thomas Thrainer | instance.disk_template, |
2374 | 1c3231aa | Thomas Thrainer | utils.CommaJoin(self.cfg.GetNodeNames(es_nodes)))
|
2375 | da4a52a3 | Thomas Thrainer | for (idx, disk) in enumerate(instance.disks): |
2376 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(disk.spindles is None, |
2377 | da4a52a3 | Thomas Thrainer | constants.CV_EINSTANCEMISSINGCFGPARAMETER, instance.name, |
2378 | d0d7d7cf | Thomas Thrainer | "number of spindles not configured for disk %s while"
|
2379 | d0d7d7cf | Thomas Thrainer | " exclusive storage is enabled, try running"
|
2380 | d0d7d7cf | Thomas Thrainer | " gnt-cluster repair-disk-sizes", idx)
|
2381 | 7352d33b | Thomas Thrainer | |
2382 | da4a52a3 | Thomas Thrainer | if instance.disk_template in constants.DTS_INT_MIRROR: |
2383 | da4a52a3 | Thomas Thrainer | instance_nodes = utils.NiceSort(instance.all_nodes) |
2384 | 7352d33b | Thomas Thrainer | instance_groups = {} |
2385 | 7352d33b | Thomas Thrainer | |
2386 | da4a52a3 | Thomas Thrainer | for node_uuid in instance_nodes: |
2387 | da4a52a3 | Thomas Thrainer | instance_groups.setdefault(self.all_node_info[node_uuid].group,
|
2388 | da4a52a3 | Thomas Thrainer | []).append(node_uuid) |
2389 | 7352d33b | Thomas Thrainer | |
2390 | 7352d33b | Thomas Thrainer | pretty_list = [ |
2391 | 1c3231aa | Thomas Thrainer | "%s (group %s)" % (utils.CommaJoin(self.cfg.GetNodeNames(nodes)), |
2392 | 1c3231aa | Thomas Thrainer | groupinfo[group].name) |
2393 | 7352d33b | Thomas Thrainer | # Sort so that we always list the primary node first.
|
2394 | 7352d33b | Thomas Thrainer | for group, nodes in sorted(instance_groups.items(), |
2395 | da4a52a3 | Thomas Thrainer | key=lambda (_, nodes): pnode_uuid in nodes, |
2396 | 7352d33b | Thomas Thrainer | reverse=True)]
|
2397 | 7352d33b | Thomas Thrainer | |
2398 | 7352d33b | Thomas Thrainer | self._ErrorIf(len(instance_groups) > 1, |
2399 | 7352d33b | Thomas Thrainer | constants.CV_EINSTANCESPLITGROUPS, |
2400 | da4a52a3 | Thomas Thrainer | instance.name, "instance has primary and secondary nodes in"
|
2401 | 7352d33b | Thomas Thrainer | " different groups: %s", utils.CommaJoin(pretty_list),
|
2402 | 7352d33b | Thomas Thrainer | code=self.ETYPE_WARNING)
|
2403 | 7352d33b | Thomas Thrainer | |
2404 | 7352d33b | Thomas Thrainer | inst_nodes_offline = [] |
2405 | da4a52a3 | Thomas Thrainer | for snode in instance.secondary_nodes: |
2406 | 7352d33b | Thomas Thrainer | s_img = node_image[snode] |
2407 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(s_img.rpc_fail and not s_img.offline, constants.CV_ENODERPC, |
2408 | da4a52a3 | Thomas Thrainer | self.cfg.GetNodeName(snode),
|
2409 | da4a52a3 | Thomas Thrainer | "instance %s, connection to secondary node failed",
|
2410 | da4a52a3 | Thomas Thrainer | instance.name) |
2411 | 7352d33b | Thomas Thrainer | |
2412 | 7352d33b | Thomas Thrainer | if s_img.offline:
|
2413 | 7352d33b | Thomas Thrainer | inst_nodes_offline.append(snode) |
2414 | 7352d33b | Thomas Thrainer | |
2415 | 7352d33b | Thomas Thrainer | # warn that the instance lives on offline nodes
|
2416 | da4a52a3 | Thomas Thrainer | self._ErrorIf(inst_nodes_offline, constants.CV_EINSTANCEBADNODE,
|
2417 | da4a52a3 | Thomas Thrainer | instance.name, "instance has offline secondary node(s) %s",
|
2418 | d0d7d7cf | Thomas Thrainer | utils.CommaJoin(self.cfg.GetNodeNames(inst_nodes_offline)))
|
2419 | 7352d33b | Thomas Thrainer | # ... or ghost/non-vm_capable nodes
|
2420 | da4a52a3 | Thomas Thrainer | for node_uuid in instance.all_nodes: |
2421 | da4a52a3 | Thomas Thrainer | self._ErrorIf(node_image[node_uuid].ghost, constants.CV_EINSTANCEBADNODE,
|
2422 | da4a52a3 | Thomas Thrainer | instance.name, "instance lives on ghost node %s",
|
2423 | da4a52a3 | Thomas Thrainer | self.cfg.GetNodeName(node_uuid))
|
2424 | da4a52a3 | Thomas Thrainer | self._ErrorIf(not node_image[node_uuid].vm_capable, |
2425 | da4a52a3 | Thomas Thrainer | constants.CV_EINSTANCEBADNODE, instance.name, |
2426 | d0d7d7cf | Thomas Thrainer | "instance lives on non-vm_capable node %s",
|
2427 | da4a52a3 | Thomas Thrainer | self.cfg.GetNodeName(node_uuid))
|
2428 | 7352d33b | Thomas Thrainer | |
2429 | 7352d33b | Thomas Thrainer | def _VerifyOrphanVolumes(self, node_vol_should, node_image, reserved): |
2430 | 7352d33b | Thomas Thrainer | """Verify if there are any unknown volumes in the cluster.
|
2431 | 7352d33b | Thomas Thrainer |
|
2432 | 7352d33b | Thomas Thrainer | The .os, .swap and backup volumes are ignored. All other volumes are
|
2433 | 7352d33b | Thomas Thrainer | reported as unknown.
|
2434 | 7352d33b | Thomas Thrainer |
|
2435 | 7352d33b | Thomas Thrainer | @type reserved: L{ganeti.utils.FieldSet}
|
2436 | 7352d33b | Thomas Thrainer | @param reserved: a FieldSet of reserved volume names
|
2437 | 7352d33b | Thomas Thrainer |
|
2438 | 7352d33b | Thomas Thrainer | """
|
2439 | 1c3231aa | Thomas Thrainer | for node_uuid, n_img in node_image.items(): |
2440 | 7352d33b | Thomas Thrainer | if (n_img.offline or n_img.rpc_fail or n_img.lvm_fail or |
2441 | 1c3231aa | Thomas Thrainer | self.all_node_info[node_uuid].group != self.group_uuid): |
2442 | 7352d33b | Thomas Thrainer | # skip non-healthy nodes
|
2443 | 7352d33b | Thomas Thrainer | continue
|
2444 | 7352d33b | Thomas Thrainer | for volume in n_img.volumes: |
2445 | 1c3231aa | Thomas Thrainer | test = ((node_uuid not in node_vol_should or |
2446 | 1c3231aa | Thomas Thrainer | volume not in node_vol_should[node_uuid]) and |
2447 | 7352d33b | Thomas Thrainer | not reserved.Matches(volume))
|
2448 | 1c3231aa | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEORPHANLV,
|
2449 | 1c3231aa | Thomas Thrainer | self.cfg.GetNodeName(node_uuid),
|
2450 | b0e8ed3f | Santi Raffa | "volume %s is unknown", volume,
|
2451 | b0e8ed3f | Santi Raffa | code=_VerifyErrors.ETYPE_WARNING) |
2452 | 7352d33b | Thomas Thrainer | |
2453 | da4a52a3 | Thomas Thrainer | def _VerifyNPlusOneMemory(self, node_image, all_insts): |
2454 | 7352d33b | Thomas Thrainer | """Verify N+1 Memory Resilience.
|
2455 | 7352d33b | Thomas Thrainer |
|
2456 | 7352d33b | Thomas Thrainer | Check that if one single node dies we can still start all the
|
2457 | 7352d33b | Thomas Thrainer | instances it was primary for.
|
2458 | 7352d33b | Thomas Thrainer |
|
2459 | 7352d33b | Thomas Thrainer | """
|
2460 | 7352d33b | Thomas Thrainer | cluster_info = self.cfg.GetClusterInfo()
|
2461 | 1c3231aa | Thomas Thrainer | for node_uuid, n_img in node_image.items(): |
2462 | 7352d33b | Thomas Thrainer | # This code checks that every node which is now listed as
|
2463 | 7352d33b | Thomas Thrainer | # secondary has enough memory to host all instances it is
|
2464 | 7352d33b | Thomas Thrainer | # supposed to should a single other node in the cluster fail.
|
2465 | 7352d33b | Thomas Thrainer | # FIXME: not ready for failover to an arbitrary node
|
2466 | 7352d33b | Thomas Thrainer | # FIXME: does not support file-backed instances
|
2467 | 7352d33b | Thomas Thrainer | # WARNING: we currently take into account down instances as well
|
2468 | 7352d33b | Thomas Thrainer | # as up ones, considering that even if they're down someone
|
2469 | 7352d33b | Thomas Thrainer | # might want to start them even in the event of a node failure.
|
2470 | 1c3231aa | Thomas Thrainer | if n_img.offline or \ |
2471 | 1c3231aa | Thomas Thrainer | self.all_node_info[node_uuid].group != self.group_uuid: |
2472 | 7352d33b | Thomas Thrainer | # we're skipping nodes marked offline and nodes in other groups from
|
2473 | 7352d33b | Thomas Thrainer | # the N+1 warning, since most likely we don't have good memory
|
2474 | 9fdb10be | Thomas Thrainer | # information from them; we already list instances living on such
|
2475 | 7352d33b | Thomas Thrainer | # nodes, and that's enough warning
|
2476 | 7352d33b | Thomas Thrainer | continue
|
2477 | 7352d33b | Thomas Thrainer | #TODO(dynmem): also consider ballooning out other instances
|
2478 | da4a52a3 | Thomas Thrainer | for prinode, inst_uuids in n_img.sbp.items(): |
2479 | 7352d33b | Thomas Thrainer | needed_mem = 0
|
2480 | da4a52a3 | Thomas Thrainer | for inst_uuid in inst_uuids: |
2481 | da4a52a3 | Thomas Thrainer | bep = cluster_info.FillBE(all_insts[inst_uuid]) |
2482 | 7352d33b | Thomas Thrainer | if bep[constants.BE_AUTO_BALANCE]:
|
2483 | 7352d33b | Thomas Thrainer | needed_mem += bep[constants.BE_MINMEM] |
2484 | 7352d33b | Thomas Thrainer | test = n_img.mfree < needed_mem |
2485 | 1c3231aa | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEN1,
|
2486 | 1c3231aa | Thomas Thrainer | self.cfg.GetNodeName(node_uuid),
|
2487 | 7352d33b | Thomas Thrainer | "not enough memory to accomodate instance failovers"
|
2488 | 7352d33b | Thomas Thrainer | " should node %s fail (%dMiB needed, %dMiB available)",
|
2489 | 1c3231aa | Thomas Thrainer | self.cfg.GetNodeName(prinode), needed_mem, n_img.mfree)
|
2490 | 7352d33b | Thomas Thrainer | |
2491 | a6c43c02 | Helga Velroyen | def _VerifyClientCertificates(self, nodes, all_nvinfo): |
2492 | a6c43c02 | Helga Velroyen | """Verifies the consistency of the client certificates.
|
2493 | a6c43c02 | Helga Velroyen |
|
2494 | a6c43c02 | Helga Velroyen | This includes several aspects:
|
2495 | a6c43c02 | Helga Velroyen | - the individual validation of all nodes' certificates
|
2496 | a6c43c02 | Helga Velroyen | - the consistency of the master candidate certificate map
|
2497 | a6c43c02 | Helga Velroyen | - the consistency of the master candidate certificate map with the
|
2498 | a6c43c02 | Helga Velroyen | certificates that the master candidates are actually using.
|
2499 | a6c43c02 | Helga Velroyen |
|
2500 | a6c43c02 | Helga Velroyen | @param nodes: the list of nodes to consider in this verification
|
2501 | a6c43c02 | Helga Velroyen | @param all_nvinfo: the map of results of the verify_node call to
|
2502 | a6c43c02 | Helga Velroyen | all nodes
|
2503 | a6c43c02 | Helga Velroyen |
|
2504 | a6c43c02 | Helga Velroyen | """
|
2505 | a6c43c02 | Helga Velroyen | candidate_certs = self.cfg.GetClusterInfo().candidate_certs
|
2506 | a6c43c02 | Helga Velroyen | if candidate_certs is None or len(candidate_certs) == 0: |
2507 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2508 | a6c43c02 | Helga Velroyen | True, constants.CV_ECLUSTERCLIENTCERT, None, |
2509 | a6c43c02 | Helga Velroyen | "The cluster's list of master candidate certificates is empty."
|
2510 | a6c43c02 | Helga Velroyen | "If you just updated the cluster, please run"
|
2511 | a6c43c02 | Helga Velroyen | " 'gnt-cluster renew-crypto --new-node-certificates'.")
|
2512 | a6c43c02 | Helga Velroyen | return
|
2513 | a6c43c02 | Helga Velroyen | |
2514 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2515 | a6c43c02 | Helga Velroyen | len(candidate_certs) != len(set(candidate_certs.values())), |
2516 | a6c43c02 | Helga Velroyen | constants.CV_ECLUSTERCLIENTCERT, None,
|
2517 | a6c43c02 | Helga Velroyen | "There are at least two master candidates configured to use the same"
|
2518 | a6c43c02 | Helga Velroyen | " certificate.")
|
2519 | a6c43c02 | Helga Velroyen | |
2520 | a6c43c02 | Helga Velroyen | # collect the client certificate
|
2521 | a6c43c02 | Helga Velroyen | for node in nodes: |
2522 | a6c43c02 | Helga Velroyen | if node.offline:
|
2523 | a6c43c02 | Helga Velroyen | continue
|
2524 | a6c43c02 | Helga Velroyen | |
2525 | a6c43c02 | Helga Velroyen | nresult = all_nvinfo[node.uuid] |
2526 | a6c43c02 | Helga Velroyen | if nresult.fail_msg or not nresult.payload: |
2527 | a6c43c02 | Helga Velroyen | continue
|
2528 | a6c43c02 | Helga Velroyen | |
2529 | a6c43c02 | Helga Velroyen | (errcode, msg) = nresult.payload.get(constants.NV_CLIENT_CERT, None)
|
2530 | a6c43c02 | Helga Velroyen | |
2531 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2532 | a6c43c02 | Helga Velroyen | errcode is not None, constants.CV_ECLUSTERCLIENTCERT, None, |
2533 | a6c43c02 | Helga Velroyen | "Client certificate of node '%s' failed validation: %s (code '%s')",
|
2534 | a6c43c02 | Helga Velroyen | node.uuid, msg, errcode) |
2535 | a6c43c02 | Helga Velroyen | |
2536 | a6c43c02 | Helga Velroyen | if not errcode: |
2537 | a6c43c02 | Helga Velroyen | digest = msg |
2538 | a6c43c02 | Helga Velroyen | if node.master_candidate:
|
2539 | a6c43c02 | Helga Velroyen | if node.uuid in candidate_certs: |
2540 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2541 | a6c43c02 | Helga Velroyen | digest != candidate_certs[node.uuid], |
2542 | a6c43c02 | Helga Velroyen | constants.CV_ECLUSTERCLIENTCERT, None,
|
2543 | a6c43c02 | Helga Velroyen | "Client certificate digest of master candidate '%s' does not"
|
2544 | a6c43c02 | Helga Velroyen | " match its entry in the cluster's map of master candidate"
|
2545 | a6c43c02 | Helga Velroyen | " certificates. Expected: %s Got: %s", node.uuid,
|
2546 | a6c43c02 | Helga Velroyen | digest, candidate_certs[node.uuid]) |
2547 | a6c43c02 | Helga Velroyen | else:
|
2548 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2549 | a6c43c02 | Helga Velroyen | True, constants.CV_ECLUSTERCLIENTCERT, None, |
2550 | a6c43c02 | Helga Velroyen | "The master candidate '%s' does not have an entry in the"
|
2551 | a6c43c02 | Helga Velroyen | " map of candidate certificates.", node.uuid)
|
2552 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2553 | a6c43c02 | Helga Velroyen | digest in candidate_certs.values(),
|
2554 | a6c43c02 | Helga Velroyen | constants.CV_ECLUSTERCLIENTCERT, None,
|
2555 | a6c43c02 | Helga Velroyen | "Master candidate '%s' is using a certificate of another node.",
|
2556 | a6c43c02 | Helga Velroyen | node.uuid) |
2557 | a6c43c02 | Helga Velroyen | else:
|
2558 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2559 | a6c43c02 | Helga Velroyen | node.uuid in candidate_certs,
|
2560 | a6c43c02 | Helga Velroyen | constants.CV_ECLUSTERCLIENTCERT, None,
|
2561 | a6c43c02 | Helga Velroyen | "Node '%s' is not a master candidate, but still listed in the"
|
2562 | a6c43c02 | Helga Velroyen | " map of master candidate certificates.", node.uuid)
|
2563 | a6c43c02 | Helga Velroyen | self._ErrorIf(
|
2564 | a6c43c02 | Helga Velroyen | (node.uuid not in candidate_certs) and |
2565 | a6c43c02 | Helga Velroyen | (digest in candidate_certs.values()),
|
2566 | a6c43c02 | Helga Velroyen | constants.CV_ECLUSTERCLIENTCERT, None,
|
2567 | a6c43c02 | Helga Velroyen | "Node '%s' is not a master candidate and is incorrectly using a"
|
2568 | a6c43c02 | Helga Velroyen | " certificate of another node which is master candidate.",
|
2569 | a6c43c02 | Helga Velroyen | node.uuid) |
2570 | a6c43c02 | Helga Velroyen | |
2571 | 1c3231aa | Thomas Thrainer | def _VerifyFiles(self, nodes, master_node_uuid, all_nvinfo, |
2572 | 7352d33b | Thomas Thrainer | (files_all, files_opt, files_mc, files_vm)): |
2573 | 7352d33b | Thomas Thrainer | """Verifies file checksums collected from all nodes.
|
2574 | 7352d33b | Thomas Thrainer |
|
2575 | 1c3231aa | Thomas Thrainer | @param nodes: List of L{objects.Node} objects
|
2576 | 1c3231aa | Thomas Thrainer | @param master_node_uuid: UUID of master node
|
2577 | 7352d33b | Thomas Thrainer | @param all_nvinfo: RPC results
|
2578 | 7352d33b | Thomas Thrainer |
|
2579 | 7352d33b | Thomas Thrainer | """
|
2580 | 7352d33b | Thomas Thrainer | # Define functions determining which nodes to consider for a file
|
2581 | 7352d33b | Thomas Thrainer | files2nodefn = [ |
2582 | 7352d33b | Thomas Thrainer | (files_all, None),
|
2583 | 7352d33b | Thomas Thrainer | (files_mc, lambda node: (node.master_candidate or |
2584 | 1c3231aa | Thomas Thrainer | node.uuid == master_node_uuid)), |
2585 | 7352d33b | Thomas Thrainer | (files_vm, lambda node: node.vm_capable),
|
2586 | 7352d33b | Thomas Thrainer | ] |
2587 | 7352d33b | Thomas Thrainer | |
2588 | 7352d33b | Thomas Thrainer | # Build mapping from filename to list of nodes which should have the file
|
2589 | 7352d33b | Thomas Thrainer | nodefiles = {} |
2590 | 7352d33b | Thomas Thrainer | for (files, fn) in files2nodefn: |
2591 | 7352d33b | Thomas Thrainer | if fn is None: |
2592 | 1c3231aa | Thomas Thrainer | filenodes = nodes |
2593 | 7352d33b | Thomas Thrainer | else:
|
2594 | 1c3231aa | Thomas Thrainer | filenodes = filter(fn, nodes)
|
2595 | 7352d33b | Thomas Thrainer | nodefiles.update((filename, |
2596 | 1c3231aa | Thomas Thrainer | frozenset(map(operator.attrgetter("uuid"), filenodes))) |
2597 | 7352d33b | Thomas Thrainer | for filename in files) |
2598 | 7352d33b | Thomas Thrainer | |
2599 | 7352d33b | Thomas Thrainer | assert set(nodefiles) == (files_all | files_mc | files_vm) |
2600 | 7352d33b | Thomas Thrainer | |
2601 | 7352d33b | Thomas Thrainer | fileinfo = dict((filename, {}) for filename in nodefiles) |
2602 | 7352d33b | Thomas Thrainer | ignore_nodes = set()
|
2603 | 7352d33b | Thomas Thrainer | |
2604 | 1c3231aa | Thomas Thrainer | for node in nodes: |
2605 | 7352d33b | Thomas Thrainer | if node.offline:
|
2606 | 1c3231aa | Thomas Thrainer | ignore_nodes.add(node.uuid) |
2607 | 7352d33b | Thomas Thrainer | continue
|
2608 | 7352d33b | Thomas Thrainer | |
2609 | 1c3231aa | Thomas Thrainer | nresult = all_nvinfo[node.uuid] |
2610 | 7352d33b | Thomas Thrainer | |
2611 | 7352d33b | Thomas Thrainer | if nresult.fail_msg or not nresult.payload: |
2612 | 7352d33b | Thomas Thrainer | node_files = None
|
2613 | 7352d33b | Thomas Thrainer | else:
|
2614 | a6c43c02 | Helga Velroyen | fingerprints = nresult.payload.get(constants.NV_FILELIST, {}) |
2615 | 7352d33b | Thomas Thrainer | node_files = dict((vcluster.LocalizeVirtualPath(key), value)
|
2616 | 7352d33b | Thomas Thrainer | for (key, value) in fingerprints.items()) |
2617 | 7352d33b | Thomas Thrainer | del fingerprints
|
2618 | 7352d33b | Thomas Thrainer | |
2619 | 7352d33b | Thomas Thrainer | test = not (node_files and isinstance(node_files, dict)) |
2620 | 1c3231aa | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEFILECHECK, node.name,
|
2621 | 1c3231aa | Thomas Thrainer | "Node did not return file checksum data")
|
2622 | 7352d33b | Thomas Thrainer | if test:
|
2623 | 1c3231aa | Thomas Thrainer | ignore_nodes.add(node.uuid) |
2624 | 7352d33b | Thomas Thrainer | continue
|
2625 | 7352d33b | Thomas Thrainer | |
2626 | 7352d33b | Thomas Thrainer | # Build per-checksum mapping from filename to nodes having it
|
2627 | 7352d33b | Thomas Thrainer | for (filename, checksum) in node_files.items(): |
2628 | 7352d33b | Thomas Thrainer | assert filename in nodefiles |
2629 | 1c3231aa | Thomas Thrainer | fileinfo[filename].setdefault(checksum, set()).add(node.uuid)
|
2630 | 7352d33b | Thomas Thrainer | |
2631 | 7352d33b | Thomas Thrainer | for (filename, checksums) in fileinfo.items(): |
2632 | 7352d33b | Thomas Thrainer | assert compat.all(len(i) > 10 for i in checksums), "Invalid checksum" |
2633 | 7352d33b | Thomas Thrainer | |
2634 | 7352d33b | Thomas Thrainer | # Nodes having the file
|
2635 | 1c3231aa | Thomas Thrainer | with_file = frozenset(node_uuid
|
2636 | 1c3231aa | Thomas Thrainer | for node_uuids in fileinfo[filename].values() |
2637 | 1c3231aa | Thomas Thrainer | for node_uuid in node_uuids) - ignore_nodes |
2638 | 7352d33b | Thomas Thrainer | |
2639 | 7352d33b | Thomas Thrainer | expected_nodes = nodefiles[filename] - ignore_nodes |
2640 | 7352d33b | Thomas Thrainer | |
2641 | 7352d33b | Thomas Thrainer | # Nodes missing file
|
2642 | 7352d33b | Thomas Thrainer | missing_file = expected_nodes - with_file |
2643 | 7352d33b | Thomas Thrainer | |
2644 | 7352d33b | Thomas Thrainer | if filename in files_opt: |
2645 | 7352d33b | Thomas Thrainer | # All or no nodes
|
2646 | 1c3231aa | Thomas Thrainer | self._ErrorIf(missing_file and missing_file != expected_nodes, |
2647 | 1c3231aa | Thomas Thrainer | constants.CV_ECLUSTERFILECHECK, None,
|
2648 | 1c3231aa | Thomas Thrainer | "File %s is optional, but it must exist on all or no"
|
2649 | 1c3231aa | Thomas Thrainer | " nodes (not found on %s)",
|
2650 | 1c3231aa | Thomas Thrainer | filename, |
2651 | 1c3231aa | Thomas Thrainer | utils.CommaJoin( |
2652 | 1c3231aa | Thomas Thrainer | utils.NiceSort( |
2653 | 1c3231aa | Thomas Thrainer | map(self.cfg.GetNodeName, missing_file)))) |
2654 | 7352d33b | Thomas Thrainer | else:
|
2655 | 1c3231aa | Thomas Thrainer | self._ErrorIf(missing_file, constants.CV_ECLUSTERFILECHECK, None, |
2656 | 1c3231aa | Thomas Thrainer | "File %s is missing from node(s) %s", filename,
|
2657 | 1c3231aa | Thomas Thrainer | utils.CommaJoin( |
2658 | 1c3231aa | Thomas Thrainer | utils.NiceSort( |
2659 | 1c3231aa | Thomas Thrainer | map(self.cfg.GetNodeName, missing_file)))) |
2660 | 7352d33b | Thomas Thrainer | |
2661 | 7352d33b | Thomas Thrainer | # Warn if a node has a file it shouldn't
|
2662 | 7352d33b | Thomas Thrainer | unexpected = with_file - expected_nodes |
2663 | 1c3231aa | Thomas Thrainer | self._ErrorIf(unexpected,
|
2664 | 1c3231aa | Thomas Thrainer | constants.CV_ECLUSTERFILECHECK, None,
|
2665 | 1c3231aa | Thomas Thrainer | "File %s should not exist on node(s) %s",
|
2666 | 1c3231aa | Thomas Thrainer | filename, utils.CommaJoin( |
2667 | 1c3231aa | Thomas Thrainer | utils.NiceSort(map(self.cfg.GetNodeName, unexpected)))) |
2668 | 7352d33b | Thomas Thrainer | |
2669 | 7352d33b | Thomas Thrainer | # See if there are multiple versions of the file
|
2670 | 7352d33b | Thomas Thrainer | test = len(checksums) > 1 |
2671 | 7352d33b | Thomas Thrainer | if test:
|
2672 | 7352d33b | Thomas Thrainer | variants = ["variant %s on %s" %
|
2673 | 1c3231aa | Thomas Thrainer | (idx + 1,
|
2674 | 1c3231aa | Thomas Thrainer | utils.CommaJoin(utils.NiceSort( |
2675 | 1c3231aa | Thomas Thrainer | map(self.cfg.GetNodeName, node_uuids)))) |
2676 | 1c3231aa | Thomas Thrainer | for (idx, (checksum, node_uuids)) in |
2677 | 7352d33b | Thomas Thrainer | enumerate(sorted(checksums.items()))] |
2678 | 7352d33b | Thomas Thrainer | else:
|
2679 | 7352d33b | Thomas Thrainer | variants = [] |
2680 | 7352d33b | Thomas Thrainer | |
2681 | 1c3231aa | Thomas Thrainer | self._ErrorIf(test, constants.CV_ECLUSTERFILECHECK, None, |
2682 | 1c3231aa | Thomas Thrainer | "File %s found with %s different checksums (%s)",
|
2683 | 1c3231aa | Thomas Thrainer | filename, len(checksums), "; ".join(variants)) |
2684 | 7352d33b | Thomas Thrainer | |
2685 | 9af7ece3 | Helga Velroyen | def _VerifyNodeDrbdHelper(self, ninfo, nresult, drbd_helper): |
2686 | 9af7ece3 | Helga Velroyen | """Verify the drbd helper.
|
2687 | 7352d33b | Thomas Thrainer |
|
2688 | 7352d33b | Thomas Thrainer | """
|
2689 | 7352d33b | Thomas Thrainer | if drbd_helper:
|
2690 | 7352d33b | Thomas Thrainer | helper_result = nresult.get(constants.NV_DRBDHELPER, None)
|
2691 | 7352d33b | Thomas Thrainer | test = (helper_result is None) |
2692 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEDRBDHELPER, ninfo.name,
|
2693 | d0d7d7cf | Thomas Thrainer | "no drbd usermode helper returned")
|
2694 | 7352d33b | Thomas Thrainer | if helper_result:
|
2695 | 7352d33b | Thomas Thrainer | status, payload = helper_result |
2696 | 7352d33b | Thomas Thrainer | test = not status
|
2697 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEDRBDHELPER, ninfo.name,
|
2698 | d0d7d7cf | Thomas Thrainer | "drbd usermode helper check unsuccessful: %s", payload)
|
2699 | 7352d33b | Thomas Thrainer | test = status and (payload != drbd_helper)
|
2700 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEDRBDHELPER, ninfo.name,
|
2701 | d0d7d7cf | Thomas Thrainer | "wrong drbd usermode helper: %s", payload)
|
2702 | 7352d33b | Thomas Thrainer | |
2703 | 9af7ece3 | Helga Velroyen | def _VerifyNodeDrbd(self, ninfo, nresult, instanceinfo, drbd_helper, |
2704 | 9af7ece3 | Helga Velroyen | drbd_map): |
2705 | 9af7ece3 | Helga Velroyen | """Verifies and the node DRBD status.
|
2706 | 9af7ece3 | Helga Velroyen |
|
2707 | 9af7ece3 | Helga Velroyen | @type ninfo: L{objects.Node}
|
2708 | 9af7ece3 | Helga Velroyen | @param ninfo: the node to check
|
2709 | 9af7ece3 | Helga Velroyen | @param nresult: the remote results for the node
|
2710 | 9af7ece3 | Helga Velroyen | @param instanceinfo: the dict of instances
|
2711 | 9af7ece3 | Helga Velroyen | @param drbd_helper: the configured DRBD usermode helper
|
2712 | 9af7ece3 | Helga Velroyen | @param drbd_map: the DRBD map as returned by
|
2713 | 9af7ece3 | Helga Velroyen | L{ganeti.config.ConfigWriter.ComputeDRBDMap}
|
2714 | 9af7ece3 | Helga Velroyen |
|
2715 | 9af7ece3 | Helga Velroyen | """
|
2716 | 9af7ece3 | Helga Velroyen | self._VerifyNodeDrbdHelper(ninfo, nresult, drbd_helper)
|
2717 | 9af7ece3 | Helga Velroyen | |
2718 | 7352d33b | Thomas Thrainer | # compute the DRBD minors
|
2719 | 7352d33b | Thomas Thrainer | node_drbd = {} |
2720 | da4a52a3 | Thomas Thrainer | for minor, inst_uuid in drbd_map[ninfo.uuid].items(): |
2721 | da4a52a3 | Thomas Thrainer | test = inst_uuid not in instanceinfo |
2722 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ECLUSTERCFG, None, |
2723 | da4a52a3 | Thomas Thrainer | "ghost instance '%s' in temporary DRBD map", inst_uuid)
|
2724 | 7352d33b | Thomas Thrainer | # ghost instance should not be running, but otherwise we
|
2725 | 7352d33b | Thomas Thrainer | # don't give double warnings (both ghost instance and
|
2726 | 7352d33b | Thomas Thrainer | # unallocated minor in use)
|
2727 | 7352d33b | Thomas Thrainer | if test:
|
2728 | da4a52a3 | Thomas Thrainer | node_drbd[minor] = (inst_uuid, False)
|
2729 | 7352d33b | Thomas Thrainer | else:
|
2730 | da4a52a3 | Thomas Thrainer | instance = instanceinfo[inst_uuid] |
2731 | da4a52a3 | Thomas Thrainer | node_drbd[minor] = (inst_uuid, instance.disks_active) |
2732 | 7352d33b | Thomas Thrainer | |
2733 | 7352d33b | Thomas Thrainer | # and now check them
|
2734 | 7352d33b | Thomas Thrainer | used_minors = nresult.get(constants.NV_DRBDLIST, []) |
2735 | 7352d33b | Thomas Thrainer | test = not isinstance(used_minors, (tuple, list)) |
2736 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEDRBD, ninfo.name,
|
2737 | d0d7d7cf | Thomas Thrainer | "cannot parse drbd status file: %s", str(used_minors)) |
2738 | 7352d33b | Thomas Thrainer | if test:
|
2739 | 7352d33b | Thomas Thrainer | # we cannot check drbd status
|
2740 | 7352d33b | Thomas Thrainer | return
|
2741 | 7352d33b | Thomas Thrainer | |
2742 | da4a52a3 | Thomas Thrainer | for minor, (inst_uuid, must_exist) in node_drbd.items(): |
2743 | 7352d33b | Thomas Thrainer | test = minor not in used_minors and must_exist |
2744 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEDRBD, ninfo.name,
|
2745 | da4a52a3 | Thomas Thrainer | "drbd minor %d of instance %s is not active", minor,
|
2746 | da4a52a3 | Thomas Thrainer | self.cfg.GetInstanceName(inst_uuid))
|
2747 | 7352d33b | Thomas Thrainer | for minor in used_minors: |
2748 | 7352d33b | Thomas Thrainer | test = minor not in node_drbd |
2749 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEDRBD, ninfo.name,
|
2750 | d0d7d7cf | Thomas Thrainer | "unallocated drbd minor %d is in use", minor)
|
2751 | 7352d33b | Thomas Thrainer | |
2752 | 7352d33b | Thomas Thrainer | def _UpdateNodeOS(self, ninfo, nresult, nimg): |
2753 | 7352d33b | Thomas Thrainer | """Builds the node OS structures.
|
2754 | 7352d33b | Thomas Thrainer |
|
2755 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2756 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2757 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2758 | 7352d33b | Thomas Thrainer | @param nimg: the node image object
|
2759 | 7352d33b | Thomas Thrainer |
|
2760 | 7352d33b | Thomas Thrainer | """
|
2761 | 7352d33b | Thomas Thrainer | remote_os = nresult.get(constants.NV_OSLIST, None)
|
2762 | 7352d33b | Thomas Thrainer | test = (not isinstance(remote_os, list) or |
2763 | 7352d33b | Thomas Thrainer | not compat.all(isinstance(v, list) and len(v) == 7 |
2764 | 7352d33b | Thomas Thrainer | for v in remote_os)) |
2765 | 7352d33b | Thomas Thrainer | |
2766 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEOS, ninfo.name,
|
2767 | d0d7d7cf | Thomas Thrainer | "node hasn't returned valid OS data")
|
2768 | 7352d33b | Thomas Thrainer | |
2769 | 7352d33b | Thomas Thrainer | nimg.os_fail = test |
2770 | 7352d33b | Thomas Thrainer | |
2771 | 7352d33b | Thomas Thrainer | if test:
|
2772 | 7352d33b | Thomas Thrainer | return
|
2773 | 7352d33b | Thomas Thrainer | |
2774 | 7352d33b | Thomas Thrainer | os_dict = {} |
2775 | 7352d33b | Thomas Thrainer | |
2776 | 7352d33b | Thomas Thrainer | for (name, os_path, status, diagnose,
|
2777 | 7352d33b | Thomas Thrainer | variants, parameters, api_ver) in nresult[constants.NV_OSLIST]:
|
2778 | 7352d33b | Thomas Thrainer | |
2779 | 7352d33b | Thomas Thrainer | if name not in os_dict: |
2780 | 7352d33b | Thomas Thrainer | os_dict[name] = [] |
2781 | 7352d33b | Thomas Thrainer | |
2782 | 7352d33b | Thomas Thrainer | # parameters is a list of lists instead of list of tuples due to
|
2783 | 7352d33b | Thomas Thrainer | # JSON lacking a real tuple type, fix it:
|
2784 | 7352d33b | Thomas Thrainer | parameters = [tuple(v) for v in parameters] |
2785 | 7352d33b | Thomas Thrainer | os_dict[name].append((os_path, status, diagnose, |
2786 | 7352d33b | Thomas Thrainer | set(variants), set(parameters), set(api_ver))) |
2787 | 7352d33b | Thomas Thrainer | |
2788 | 7352d33b | Thomas Thrainer | nimg.oslist = os_dict |
2789 | 7352d33b | Thomas Thrainer | |
2790 | 7352d33b | Thomas Thrainer | def _VerifyNodeOS(self, ninfo, nimg, base): |
2791 | 7352d33b | Thomas Thrainer | """Verifies the node OS list.
|
2792 | 7352d33b | Thomas Thrainer |
|
2793 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2794 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2795 | 7352d33b | Thomas Thrainer | @param nimg: the node image object
|
2796 | 7352d33b | Thomas Thrainer | @param base: the 'template' node we match against (e.g. from the master)
|
2797 | 7352d33b | Thomas Thrainer |
|
2798 | 7352d33b | Thomas Thrainer | """
|
2799 | 7352d33b | Thomas Thrainer | assert not nimg.os_fail, "Entered _VerifyNodeOS with failed OS rpc?" |
2800 | 7352d33b | Thomas Thrainer | |
2801 | 7352d33b | Thomas Thrainer | beautify_params = lambda l: ["%s: %s" % (k, v) for (k, v) in l] |
2802 | 7352d33b | Thomas Thrainer | for os_name, os_data in nimg.oslist.items(): |
2803 | 7352d33b | Thomas Thrainer | assert os_data, "Empty OS status for OS %s?!" % os_name |
2804 | 7352d33b | Thomas Thrainer | f_path, f_status, f_diag, f_var, f_param, f_api = os_data[0]
|
2805 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(not f_status, constants.CV_ENODEOS, ninfo.name, |
2806 | d0d7d7cf | Thomas Thrainer | "Invalid OS %s (located at %s): %s",
|
2807 | d0d7d7cf | Thomas Thrainer | os_name, f_path, f_diag) |
2808 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(len(os_data) > 1, constants.CV_ENODEOS, ninfo.name, |
2809 | d0d7d7cf | Thomas Thrainer | "OS '%s' has multiple entries"
|
2810 | d0d7d7cf | Thomas Thrainer | " (first one shadows the rest): %s",
|
2811 | d0d7d7cf | Thomas Thrainer | os_name, utils.CommaJoin([v[0] for v in os_data])) |
2812 | 7352d33b | Thomas Thrainer | # comparisons with the 'base' image
|
2813 | 7352d33b | Thomas Thrainer | test = os_name not in base.oslist |
2814 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEOS, ninfo.name,
|
2815 | d0d7d7cf | Thomas Thrainer | "Extra OS %s not present on reference node (%s)",
|
2816 | d0d7d7cf | Thomas Thrainer | os_name, self.cfg.GetNodeName(base.uuid))
|
2817 | 7352d33b | Thomas Thrainer | if test:
|
2818 | 7352d33b | Thomas Thrainer | continue
|
2819 | 7352d33b | Thomas Thrainer | assert base.oslist[os_name], "Base node has empty OS status?" |
2820 | 7352d33b | Thomas Thrainer | _, b_status, _, b_var, b_param, b_api = base.oslist[os_name][0]
|
2821 | 7352d33b | Thomas Thrainer | if not b_status: |
2822 | 7352d33b | Thomas Thrainer | # base OS is invalid, skipping
|
2823 | 7352d33b | Thomas Thrainer | continue
|
2824 | 7352d33b | Thomas Thrainer | for kind, a, b in [("API version", f_api, b_api), |
2825 | 7352d33b | Thomas Thrainer | ("variants list", f_var, b_var),
|
2826 | 7352d33b | Thomas Thrainer | ("parameters", beautify_params(f_param),
|
2827 | 7352d33b | Thomas Thrainer | beautify_params(b_param))]: |
2828 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(a != b, constants.CV_ENODEOS, ninfo.name,
|
2829 | d0d7d7cf | Thomas Thrainer | "OS %s for %s differs from reference node %s:"
|
2830 | d0d7d7cf | Thomas Thrainer | " [%s] vs. [%s]", kind, os_name,
|
2831 | d0d7d7cf | Thomas Thrainer | self.cfg.GetNodeName(base.uuid),
|
2832 | d0d7d7cf | Thomas Thrainer | utils.CommaJoin(sorted(a)), utils.CommaJoin(sorted(b))) |
2833 | 7352d33b | Thomas Thrainer | |
2834 | 7352d33b | Thomas Thrainer | # check any missing OSes
|
2835 | 7352d33b | Thomas Thrainer | missing = set(base.oslist.keys()).difference(nimg.oslist.keys())
|
2836 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(missing, constants.CV_ENODEOS, ninfo.name,
|
2837 | d0d7d7cf | Thomas Thrainer | "OSes present on reference node %s"
|
2838 | d0d7d7cf | Thomas Thrainer | " but missing on this node: %s",
|
2839 | d0d7d7cf | Thomas Thrainer | self.cfg.GetNodeName(base.uuid), utils.CommaJoin(missing))
|
2840 | 7352d33b | Thomas Thrainer | |
2841 | 13a6c760 | Helga Velroyen | def _VerifyAcceptedFileStoragePaths(self, ninfo, nresult, is_master): |
2842 | 7352d33b | Thomas Thrainer | """Verifies paths in L{pathutils.FILE_STORAGE_PATHS_FILE}.
|
2843 | 7352d33b | Thomas Thrainer |
|
2844 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2845 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2846 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2847 | 7352d33b | Thomas Thrainer | @type is_master: bool
|
2848 | 7352d33b | Thomas Thrainer | @param is_master: Whether node is the master node
|
2849 | 7352d33b | Thomas Thrainer |
|
2850 | 7352d33b | Thomas Thrainer | """
|
2851 | 13a6c760 | Helga Velroyen | cluster = self.cfg.GetClusterInfo()
|
2852 | 7352d33b | Thomas Thrainer | if (is_master and |
2853 | 13a6c760 | Helga Velroyen | (cluster.IsFileStorageEnabled() or
|
2854 | 13a6c760 | Helga Velroyen | cluster.IsSharedFileStorageEnabled())): |
2855 | 7352d33b | Thomas Thrainer | try:
|
2856 | 13a6c760 | Helga Velroyen | fspaths = nresult[constants.NV_ACCEPTED_STORAGE_PATHS] |
2857 | 7352d33b | Thomas Thrainer | except KeyError: |
2858 | 7352d33b | Thomas Thrainer | # This should never happen
|
2859 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODEFILESTORAGEPATHS, ninfo.name, |
2860 | 7352d33b | Thomas Thrainer | "Node did not return forbidden file storage paths")
|
2861 | 7352d33b | Thomas Thrainer | else:
|
2862 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(fspaths, constants.CV_ENODEFILESTORAGEPATHS, ninfo.name,
|
2863 | 7352d33b | Thomas Thrainer | "Found forbidden file storage paths: %s",
|
2864 | 7352d33b | Thomas Thrainer | utils.CommaJoin(fspaths)) |
2865 | 7352d33b | Thomas Thrainer | else:
|
2866 | 13a6c760 | Helga Velroyen | self._ErrorIf(constants.NV_ACCEPTED_STORAGE_PATHS in nresult, |
2867 | d0d7d7cf | Thomas Thrainer | constants.CV_ENODEFILESTORAGEPATHS, ninfo.name, |
2868 | 7352d33b | Thomas Thrainer | "Node should not have returned forbidden file storage"
|
2869 | 7352d33b | Thomas Thrainer | " paths")
|
2870 | 7352d33b | Thomas Thrainer | |
2871 | 4b322a76 | Helga Velroyen | def _VerifyStoragePaths(self, ninfo, nresult, file_disk_template, |
2872 | 4b322a76 | Helga Velroyen | verify_key, error_key): |
2873 | 9c1c3c19 | Helga Velroyen | """Verifies (file) storage paths.
|
2874 | 9c1c3c19 | Helga Velroyen |
|
2875 | 9c1c3c19 | Helga Velroyen | @type ninfo: L{objects.Node}
|
2876 | 9c1c3c19 | Helga Velroyen | @param ninfo: the node to check
|
2877 | 9c1c3c19 | Helga Velroyen | @param nresult: the remote results for the node
|
2878 | 4b322a76 | Helga Velroyen | @type file_disk_template: string
|
2879 | 4b322a76 | Helga Velroyen | @param file_disk_template: file-based disk template, whose directory
|
2880 | 4b322a76 | Helga Velroyen | is supposed to be verified
|
2881 | 4b322a76 | Helga Velroyen | @type verify_key: string
|
2882 | 4b322a76 | Helga Velroyen | @param verify_key: key for the verification map of this file
|
2883 | 4b322a76 | Helga Velroyen | verification step
|
2884 | 4b322a76 | Helga Velroyen | @param error_key: error key to be added to the verification results
|
2885 | 4b322a76 | Helga Velroyen | in case something goes wrong in this verification step
|
2886 | 9c1c3c19 | Helga Velroyen |
|
2887 | 9c1c3c19 | Helga Velroyen | """
|
2888 | 5a904197 | Santi Raffa | assert (file_disk_template in utils.storage.GetDiskTemplatesOfStorageTypes( |
2889 | 5a904197 | Santi Raffa | constants.ST_FILE, constants.ST_SHARED_FILE |
2890 | 5a904197 | Santi Raffa | )) |
2891 | 5a904197 | Santi Raffa | |
2892 | 9c1c3c19 | Helga Velroyen | cluster = self.cfg.GetClusterInfo()
|
2893 | 4b322a76 | Helga Velroyen | if cluster.IsDiskTemplateEnabled(file_disk_template):
|
2894 | 9c1c3c19 | Helga Velroyen | self._ErrorIf(
|
2895 | 4b322a76 | Helga Velroyen | verify_key in nresult,
|
2896 | 4b322a76 | Helga Velroyen | error_key, ninfo.name, |
2897 | 4b322a76 | Helga Velroyen | "The configured %s storage path is unusable: %s" %
|
2898 | 4b322a76 | Helga Velroyen | (file_disk_template, nresult.get(verify_key))) |
2899 | 4b322a76 | Helga Velroyen | |
2900 | 4b322a76 | Helga Velroyen | def _VerifyFileStoragePaths(self, ninfo, nresult): |
2901 | 4b322a76 | Helga Velroyen | """Verifies (file) storage paths.
|
2902 | 4b322a76 | Helga Velroyen |
|
2903 | 4b322a76 | Helga Velroyen | @see: C{_VerifyStoragePaths}
|
2904 | 4b322a76 | Helga Velroyen |
|
2905 | 4b322a76 | Helga Velroyen | """
|
2906 | 4b322a76 | Helga Velroyen | self._VerifyStoragePaths(
|
2907 | 4b322a76 | Helga Velroyen | ninfo, nresult, constants.DT_FILE, |
2908 | 4b322a76 | Helga Velroyen | constants.NV_FILE_STORAGE_PATH, |
2909 | 4b322a76 | Helga Velroyen | constants.CV_ENODEFILESTORAGEPATHUNUSABLE) |
2910 | 4b322a76 | Helga Velroyen | |
2911 | 4b322a76 | Helga Velroyen | def _VerifySharedFileStoragePaths(self, ninfo, nresult): |
2912 | 4b322a76 | Helga Velroyen | """Verifies (file) storage paths.
|
2913 | 4b322a76 | Helga Velroyen |
|
2914 | 4b322a76 | Helga Velroyen | @see: C{_VerifyStoragePaths}
|
2915 | 4b322a76 | Helga Velroyen |
|
2916 | 4b322a76 | Helga Velroyen | """
|
2917 | 4b322a76 | Helga Velroyen | self._VerifyStoragePaths(
|
2918 | 4b322a76 | Helga Velroyen | ninfo, nresult, constants.DT_SHARED_FILE, |
2919 | 4b322a76 | Helga Velroyen | constants.NV_SHARED_FILE_STORAGE_PATH, |
2920 | 4b322a76 | Helga Velroyen | constants.CV_ENODESHAREDFILESTORAGEPATHUNUSABLE) |
2921 | 9c1c3c19 | Helga Velroyen | |
2922 | 7352d33b | Thomas Thrainer | def _VerifyOob(self, ninfo, nresult): |
2923 | 7352d33b | Thomas Thrainer | """Verifies out of band functionality of a node.
|
2924 | 7352d33b | Thomas Thrainer |
|
2925 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2926 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2927 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2928 | 7352d33b | Thomas Thrainer |
|
2929 | 7352d33b | Thomas Thrainer | """
|
2930 | 7352d33b | Thomas Thrainer | # We just have to verify the paths on master and/or master candidates
|
2931 | 7352d33b | Thomas Thrainer | # as the oob helper is invoked on the master
|
2932 | 7352d33b | Thomas Thrainer | if ((ninfo.master_candidate or ninfo.master_capable) and |
2933 | 7352d33b | Thomas Thrainer | constants.NV_OOB_PATHS in nresult):
|
2934 | 7352d33b | Thomas Thrainer | for path_result in nresult[constants.NV_OOB_PATHS]: |
2935 | 1c3231aa | Thomas Thrainer | self._ErrorIf(path_result, constants.CV_ENODEOOBPATH,
|
2936 | d0d7d7cf | Thomas Thrainer | ninfo.name, path_result) |
2937 | 7352d33b | Thomas Thrainer | |
2938 | 7352d33b | Thomas Thrainer | def _UpdateNodeVolumes(self, ninfo, nresult, nimg, vg_name): |
2939 | 7352d33b | Thomas Thrainer | """Verifies and updates the node volume data.
|
2940 | 7352d33b | Thomas Thrainer |
|
2941 | 7352d33b | Thomas Thrainer | This function will update a L{NodeImage}'s internal structures
|
2942 | 7352d33b | Thomas Thrainer | with data from the remote call.
|
2943 | 7352d33b | Thomas Thrainer |
|
2944 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2945 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2946 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2947 | 7352d33b | Thomas Thrainer | @param nimg: the node image object
|
2948 | 7352d33b | Thomas Thrainer | @param vg_name: the configured VG name
|
2949 | 7352d33b | Thomas Thrainer |
|
2950 | 7352d33b | Thomas Thrainer | """
|
2951 | 7352d33b | Thomas Thrainer | nimg.lvm_fail = True
|
2952 | 7352d33b | Thomas Thrainer | lvdata = nresult.get(constants.NV_LVLIST, "Missing LV data")
|
2953 | 7352d33b | Thomas Thrainer | if vg_name is None: |
2954 | 7352d33b | Thomas Thrainer | pass
|
2955 | 7352d33b | Thomas Thrainer | elif isinstance(lvdata, basestring): |
2956 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODELVM, ninfo.name, |
2957 | d0d7d7cf | Thomas Thrainer | "LVM problem on node: %s", utils.SafeEncode(lvdata))
|
2958 | 7352d33b | Thomas Thrainer | elif not isinstance(lvdata, dict): |
2959 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODELVM, ninfo.name, |
2960 | d0d7d7cf | Thomas Thrainer | "rpc call to node failed (lvlist)")
|
2961 | 7352d33b | Thomas Thrainer | else:
|
2962 | 7352d33b | Thomas Thrainer | nimg.volumes = lvdata |
2963 | 7352d33b | Thomas Thrainer | nimg.lvm_fail = False
|
2964 | 7352d33b | Thomas Thrainer | |
2965 | 7352d33b | Thomas Thrainer | def _UpdateNodeInstances(self, ninfo, nresult, nimg): |
2966 | 7352d33b | Thomas Thrainer | """Verifies and updates the node instance list.
|
2967 | 7352d33b | Thomas Thrainer |
|
2968 | 7352d33b | Thomas Thrainer | If the listing was successful, then updates this node's instance
|
2969 | 7352d33b | Thomas Thrainer | list. Otherwise, it marks the RPC call as failed for the instance
|
2970 | 7352d33b | Thomas Thrainer | list key.
|
2971 | 7352d33b | Thomas Thrainer |
|
2972 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2973 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2974 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2975 | 7352d33b | Thomas Thrainer | @param nimg: the node image object
|
2976 | 7352d33b | Thomas Thrainer |
|
2977 | 7352d33b | Thomas Thrainer | """
|
2978 | 7352d33b | Thomas Thrainer | idata = nresult.get(constants.NV_INSTANCELIST, None)
|
2979 | 7352d33b | Thomas Thrainer | test = not isinstance(idata, list) |
2980 | 7352d33b | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEHV, ninfo.name,
|
2981 | 7352d33b | Thomas Thrainer | "rpc call to node failed (instancelist): %s",
|
2982 | 7352d33b | Thomas Thrainer | utils.SafeEncode(str(idata)))
|
2983 | 7352d33b | Thomas Thrainer | if test:
|
2984 | 7352d33b | Thomas Thrainer | nimg.hyp_fail = True
|
2985 | 7352d33b | Thomas Thrainer | else:
|
2986 | da4a52a3 | Thomas Thrainer | nimg.instances = [inst.uuid for (_, inst) in |
2987 | da4a52a3 | Thomas Thrainer | self.cfg.GetMultiInstanceInfoByName(idata)]
|
2988 | 7352d33b | Thomas Thrainer | |
2989 | 7352d33b | Thomas Thrainer | def _UpdateNodeInfo(self, ninfo, nresult, nimg, vg_name): |
2990 | 7352d33b | Thomas Thrainer | """Verifies and computes a node information map
|
2991 | 7352d33b | Thomas Thrainer |
|
2992 | 7352d33b | Thomas Thrainer | @type ninfo: L{objects.Node}
|
2993 | 7352d33b | Thomas Thrainer | @param ninfo: the node to check
|
2994 | 7352d33b | Thomas Thrainer | @param nresult: the remote results for the node
|
2995 | 7352d33b | Thomas Thrainer | @param nimg: the node image object
|
2996 | 7352d33b | Thomas Thrainer | @param vg_name: the configured VG name
|
2997 | 7352d33b | Thomas Thrainer |
|
2998 | 7352d33b | Thomas Thrainer | """
|
2999 | 7352d33b | Thomas Thrainer | # try to read free memory (from the hypervisor)
|
3000 | 7352d33b | Thomas Thrainer | hv_info = nresult.get(constants.NV_HVINFO, None)
|
3001 | 7352d33b | Thomas Thrainer | test = not isinstance(hv_info, dict) or "memory_free" not in hv_info |
3002 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEHV, ninfo.name,
|
3003 | d0d7d7cf | Thomas Thrainer | "rpc call to node failed (hvinfo)")
|
3004 | 7352d33b | Thomas Thrainer | if not test: |
3005 | 7352d33b | Thomas Thrainer | try:
|
3006 | 7352d33b | Thomas Thrainer | nimg.mfree = int(hv_info["memory_free"]) |
3007 | 7352d33b | Thomas Thrainer | except (ValueError, TypeError): |
3008 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODERPC, ninfo.name, |
3009 | d0d7d7cf | Thomas Thrainer | "node returned invalid nodeinfo, check hypervisor")
|
3010 | 7352d33b | Thomas Thrainer | |
3011 | 7352d33b | Thomas Thrainer | # FIXME: devise a free space model for file based instances as well
|
3012 | 7352d33b | Thomas Thrainer | if vg_name is not None: |
3013 | 7352d33b | Thomas Thrainer | test = (constants.NV_VGLIST not in nresult or |
3014 | 7352d33b | Thomas Thrainer | vg_name not in nresult[constants.NV_VGLIST]) |
3015 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODELVM, ninfo.name,
|
3016 | d0d7d7cf | Thomas Thrainer | "node didn't return data for the volume group '%s'"
|
3017 | d0d7d7cf | Thomas Thrainer | " - it is either missing or broken", vg_name)
|
3018 | 7352d33b | Thomas Thrainer | if not test: |
3019 | 7352d33b | Thomas Thrainer | try:
|
3020 | 7352d33b | Thomas Thrainer | nimg.dfree = int(nresult[constants.NV_VGLIST][vg_name])
|
3021 | 7352d33b | Thomas Thrainer | except (ValueError, TypeError): |
3022 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(True, constants.CV_ENODERPC, ninfo.name, |
3023 | d0d7d7cf | Thomas Thrainer | "node returned invalid LVM info, check LVM status")
|
3024 | 7352d33b | Thomas Thrainer | |
3025 | 1c3231aa | Thomas Thrainer | def _CollectDiskInfo(self, node_uuids, node_image, instanceinfo): |
3026 | 7352d33b | Thomas Thrainer | """Gets per-disk status information for all instances.
|
3027 | 7352d33b | Thomas Thrainer |
|
3028 | 1c3231aa | Thomas Thrainer | @type node_uuids: list of strings
|
3029 | 1c3231aa | Thomas Thrainer | @param node_uuids: Node UUIDs
|
3030 | da4a52a3 | Thomas Thrainer | @type node_image: dict of (UUID, L{objects.Node})
|
3031 | 7352d33b | Thomas Thrainer | @param node_image: Node objects
|
3032 | da4a52a3 | Thomas Thrainer | @type instanceinfo: dict of (UUID, L{objects.Instance})
|
3033 | 7352d33b | Thomas Thrainer | @param instanceinfo: Instance objects
|
3034 | 7352d33b | Thomas Thrainer | @rtype: {instance: {node: [(succes, payload)]}}
|
3035 | 7352d33b | Thomas Thrainer | @return: a dictionary of per-instance dictionaries with nodes as
|
3036 | 7352d33b | Thomas Thrainer | keys and disk information as values; the disk information is a
|
3037 | 7352d33b | Thomas Thrainer | list of tuples (success, payload)
|
3038 | 7352d33b | Thomas Thrainer |
|
3039 | 7352d33b | Thomas Thrainer | """
|
3040 | 7352d33b | Thomas Thrainer | node_disks = {} |
3041 | 0c3d9c7c | Thomas Thrainer | node_disks_dev_inst_only = {} |
3042 | 7352d33b | Thomas Thrainer | diskless_instances = set()
|
3043 | 099ed3b2 | Klaus Aehlig | nodisk_instances = set()
|
3044 | 7352d33b | Thomas Thrainer | diskless = constants.DT_DISKLESS |
3045 | 7352d33b | Thomas Thrainer | |
3046 | 1c3231aa | Thomas Thrainer | for nuuid in node_uuids: |
3047 | da4a52a3 | Thomas Thrainer | node_inst_uuids = list(itertools.chain(node_image[nuuid].pinst,
|
3048 | da4a52a3 | Thomas Thrainer | node_image[nuuid].sinst)) |
3049 | da4a52a3 | Thomas Thrainer | diskless_instances.update(uuid for uuid in node_inst_uuids |
3050 | da4a52a3 | Thomas Thrainer | if instanceinfo[uuid].disk_template == diskless)
|
3051 | da4a52a3 | Thomas Thrainer | disks = [(inst_uuid, disk) |
3052 | da4a52a3 | Thomas Thrainer | for inst_uuid in node_inst_uuids |
3053 | da4a52a3 | Thomas Thrainer | for disk in instanceinfo[inst_uuid].disks] |
3054 | 7352d33b | Thomas Thrainer | |
3055 | 7352d33b | Thomas Thrainer | if not disks: |
3056 | 099ed3b2 | Klaus Aehlig | nodisk_instances.update(uuid for uuid in node_inst_uuids |
3057 | 099ed3b2 | Klaus Aehlig | if instanceinfo[uuid].disk_template != diskless)
|
3058 | 7352d33b | Thomas Thrainer | # No need to collect data
|
3059 | 7352d33b | Thomas Thrainer | continue
|
3060 | 7352d33b | Thomas Thrainer | |
3061 | 1c3231aa | Thomas Thrainer | node_disks[nuuid] = disks |
3062 | 7352d33b | Thomas Thrainer | |
3063 | 7352d33b | Thomas Thrainer | # _AnnotateDiskParams makes already copies of the disks
|
3064 | 0c3d9c7c | Thomas Thrainer | dev_inst_only = [] |
3065 | da4a52a3 | Thomas Thrainer | for (inst_uuid, dev) in disks: |
3066 | da4a52a3 | Thomas Thrainer | (anno_disk,) = AnnotateDiskParams(instanceinfo[inst_uuid], [dev], |
3067 | da4a52a3 | Thomas Thrainer | self.cfg)
|
3068 | 0c3d9c7c | Thomas Thrainer | dev_inst_only.append((anno_disk, instanceinfo[inst_uuid])) |
3069 | 7352d33b | Thomas Thrainer | |
3070 | 0c3d9c7c | Thomas Thrainer | node_disks_dev_inst_only[nuuid] = dev_inst_only |
3071 | 7352d33b | Thomas Thrainer | |
3072 | 0c3d9c7c | Thomas Thrainer | assert len(node_disks) == len(node_disks_dev_inst_only) |
3073 | 7352d33b | Thomas Thrainer | |
3074 | 7352d33b | Thomas Thrainer | # Collect data from all nodes with disks
|
3075 | 0c3d9c7c | Thomas Thrainer | result = self.rpc.call_blockdev_getmirrorstatus_multi(
|
3076 | 0c3d9c7c | Thomas Thrainer | node_disks.keys(), node_disks_dev_inst_only) |
3077 | 7352d33b | Thomas Thrainer | |
3078 | 7352d33b | Thomas Thrainer | assert len(result) == len(node_disks) |
3079 | 7352d33b | Thomas Thrainer | |
3080 | 7352d33b | Thomas Thrainer | instdisk = {} |
3081 | 7352d33b | Thomas Thrainer | |
3082 | 1c3231aa | Thomas Thrainer | for (nuuid, nres) in result.items(): |
3083 | 1c3231aa | Thomas Thrainer | node = self.cfg.GetNodeInfo(nuuid)
|
3084 | 1c3231aa | Thomas Thrainer | disks = node_disks[node.uuid] |
3085 | 7352d33b | Thomas Thrainer | |
3086 | 7352d33b | Thomas Thrainer | if nres.offline:
|
3087 | 7352d33b | Thomas Thrainer | # No data from this node
|
3088 | 7352d33b | Thomas Thrainer | data = len(disks) * [(False, "node offline")] |
3089 | 7352d33b | Thomas Thrainer | else:
|
3090 | 7352d33b | Thomas Thrainer | msg = nres.fail_msg |
3091 | 1c3231aa | Thomas Thrainer | self._ErrorIf(msg, constants.CV_ENODERPC, node.name,
|
3092 | 1c3231aa | Thomas Thrainer | "while getting disk information: %s", msg)
|
3093 | 7352d33b | Thomas Thrainer | if msg:
|
3094 | 7352d33b | Thomas Thrainer | # No data from this node
|
3095 | 7352d33b | Thomas Thrainer | data = len(disks) * [(False, msg)] |
3096 | 7352d33b | Thomas Thrainer | else:
|
3097 | 7352d33b | Thomas Thrainer | data = [] |
3098 | 7352d33b | Thomas Thrainer | for idx, i in enumerate(nres.payload): |
3099 | 7352d33b | Thomas Thrainer | if isinstance(i, (tuple, list)) and len(i) == 2: |
3100 | 7352d33b | Thomas Thrainer | data.append(i) |
3101 | 7352d33b | Thomas Thrainer | else:
|
3102 | 7352d33b | Thomas Thrainer | logging.warning("Invalid result from node %s, entry %d: %s",
|
3103 | 1c3231aa | Thomas Thrainer | node.name, idx, i) |
3104 | 7352d33b | Thomas Thrainer | data.append((False, "Invalid result from the remote node")) |
3105 | 7352d33b | Thomas Thrainer | |
3106 | da4a52a3 | Thomas Thrainer | for ((inst_uuid, _), status) in zip(disks, data): |
3107 | da4a52a3 | Thomas Thrainer | instdisk.setdefault(inst_uuid, {}).setdefault(node.uuid, []) \ |
3108 | da4a52a3 | Thomas Thrainer | .append(status) |
3109 | 7352d33b | Thomas Thrainer | |
3110 | 7352d33b | Thomas Thrainer | # Add empty entries for diskless instances.
|
3111 | da4a52a3 | Thomas Thrainer | for inst_uuid in diskless_instances: |
3112 | da4a52a3 | Thomas Thrainer | assert inst_uuid not in instdisk |
3113 | da4a52a3 | Thomas Thrainer | instdisk[inst_uuid] = {} |
3114 | 099ed3b2 | Klaus Aehlig | # ...and disk-full instances that happen to have no disks
|
3115 | 099ed3b2 | Klaus Aehlig | for inst_uuid in nodisk_instances: |
3116 | 099ed3b2 | Klaus Aehlig | assert inst_uuid not in instdisk |
3117 | 099ed3b2 | Klaus Aehlig | instdisk[inst_uuid] = {} |
3118 | 7352d33b | Thomas Thrainer | |
3119 | 7352d33b | Thomas Thrainer | assert compat.all(len(statuses) == len(instanceinfo[inst].disks) and |
3120 | 1c3231aa | Thomas Thrainer | len(nuuids) <= len(instanceinfo[inst].all_nodes) and |
3121 | 7352d33b | Thomas Thrainer | compat.all(isinstance(s, (tuple, list)) and |
3122 | 7352d33b | Thomas Thrainer | len(s) == 2 for s in statuses) |
3123 | 1c3231aa | Thomas Thrainer | for inst, nuuids in instdisk.items() |
3124 | 1c3231aa | Thomas Thrainer | for nuuid, statuses in nuuids.items()) |
3125 | 7352d33b | Thomas Thrainer | if __debug__:
|
3126 | 7352d33b | Thomas Thrainer | instdisk_keys = set(instdisk)
|
3127 | 7352d33b | Thomas Thrainer | instanceinfo_keys = set(instanceinfo)
|
3128 | 7352d33b | Thomas Thrainer | assert instdisk_keys == instanceinfo_keys, \
|
3129 | 7352d33b | Thomas Thrainer | ("instdisk keys (%s) do not match instanceinfo keys (%s)" %
|
3130 | 7352d33b | Thomas Thrainer | (instdisk_keys, instanceinfo_keys)) |
3131 | 7352d33b | Thomas Thrainer | |
3132 | 7352d33b | Thomas Thrainer | return instdisk
|
3133 | 7352d33b | Thomas Thrainer | |
3134 | 7352d33b | Thomas Thrainer | @staticmethod
|
3135 | 7352d33b | Thomas Thrainer | def _SshNodeSelector(group_uuid, all_nodes): |
3136 | 7352d33b | Thomas Thrainer | """Create endless iterators for all potential SSH check hosts.
|
3137 | 7352d33b | Thomas Thrainer |
|
3138 | 7352d33b | Thomas Thrainer | """
|
3139 | 7352d33b | Thomas Thrainer | nodes = [node for node in all_nodes |
3140 | 7352d33b | Thomas Thrainer | if (node.group != group_uuid and |
3141 | 7352d33b | Thomas Thrainer | not node.offline)]
|
3142 | 7352d33b | Thomas Thrainer | keyfunc = operator.attrgetter("group")
|
3143 | 7352d33b | Thomas Thrainer | |
3144 | 7352d33b | Thomas Thrainer | return map(itertools.cycle, |
3145 | 7352d33b | Thomas Thrainer | [sorted(map(operator.attrgetter("name"), names)) |
3146 | 7352d33b | Thomas Thrainer | for _, names in itertools.groupby(sorted(nodes, key=keyfunc), |
3147 | 7352d33b | Thomas Thrainer | keyfunc)]) |
3148 | 7352d33b | Thomas Thrainer | |
3149 | 7352d33b | Thomas Thrainer | @classmethod
|
3150 | 7352d33b | Thomas Thrainer | def _SelectSshCheckNodes(cls, group_nodes, group_uuid, all_nodes): |
3151 | 7352d33b | Thomas Thrainer | """Choose which nodes should talk to which other nodes.
|
3152 | 7352d33b | Thomas Thrainer |
|
3153 | 7352d33b | Thomas Thrainer | We will make nodes contact all nodes in their group, and one node from
|
3154 | 7352d33b | Thomas Thrainer | every other group.
|
3155 | 7352d33b | Thomas Thrainer |
|
3156 | 7352d33b | Thomas Thrainer | @warning: This algorithm has a known issue if one node group is much
|
3157 | 7352d33b | Thomas Thrainer | smaller than others (e.g. just one node). In such a case all other
|
3158 | 7352d33b | Thomas Thrainer | nodes will talk to the single node.
|
3159 | 7352d33b | Thomas Thrainer |
|
3160 | 7352d33b | Thomas Thrainer | """
|
3161 | 7352d33b | Thomas Thrainer | online_nodes = sorted(node.name for node in group_nodes if not node.offline) |
3162 | 7352d33b | Thomas Thrainer | sel = cls._SshNodeSelector(group_uuid, all_nodes) |
3163 | 7352d33b | Thomas Thrainer | |
3164 | 7352d33b | Thomas Thrainer | return (online_nodes,
|
3165 | 7352d33b | Thomas Thrainer | dict((name, sorted([i.next() for i in sel])) |
3166 | 7352d33b | Thomas Thrainer | for name in online_nodes)) |
3167 | 7352d33b | Thomas Thrainer | |
3168 | 7352d33b | Thomas Thrainer | def BuildHooksEnv(self): |
3169 | 7352d33b | Thomas Thrainer | """Build hooks env.
|
3170 | 7352d33b | Thomas Thrainer |
|
3171 | 7352d33b | Thomas Thrainer | Cluster-Verify hooks just ran in the post phase and their failure makes
|
3172 | 7352d33b | Thomas Thrainer | the output be logged in the verify output and the verification to fail.
|
3173 | 7352d33b | Thomas Thrainer |
|
3174 | 7352d33b | Thomas Thrainer | """
|
3175 | 7352d33b | Thomas Thrainer | env = { |
3176 | 7352d33b | Thomas Thrainer | "CLUSTER_TAGS": " ".join(self.cfg.GetClusterInfo().GetTags()), |
3177 | 7352d33b | Thomas Thrainer | } |
3178 | 7352d33b | Thomas Thrainer | |
3179 | 7352d33b | Thomas Thrainer | env.update(("NODE_TAGS_%s" % node.name, " ".join(node.GetTags())) |
3180 | 7352d33b | Thomas Thrainer | for node in self.my_node_info.values()) |
3181 | 7352d33b | Thomas Thrainer | |
3182 | 7352d33b | Thomas Thrainer | return env
|
3183 | 7352d33b | Thomas Thrainer | |
3184 | 7352d33b | Thomas Thrainer | def BuildHooksNodes(self): |
3185 | 7352d33b | Thomas Thrainer | """Build hooks nodes.
|
3186 | 7352d33b | Thomas Thrainer |
|
3187 | 7352d33b | Thomas Thrainer | """
|
3188 | 1c3231aa | Thomas Thrainer | return ([], list(self.my_node_info.keys())) |
3189 | 7352d33b | Thomas Thrainer | |
3190 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
3191 | 7352d33b | Thomas Thrainer | """Verify integrity of the node group, performing various test on nodes.
|
3192 | 7352d33b | Thomas Thrainer |
|
3193 | 7352d33b | Thomas Thrainer | """
|
3194 | 7352d33b | Thomas Thrainer | # This method has too many local variables. pylint: disable=R0914
|
3195 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying group '%s'" % self.group_info.name) |
3196 | 7352d33b | Thomas Thrainer | |
3197 | 1c3231aa | Thomas Thrainer | if not self.my_node_uuids: |
3198 | 7352d33b | Thomas Thrainer | # empty node group
|
3199 | 7352d33b | Thomas Thrainer | feedback_fn("* Empty node group, skipping verification")
|
3200 | 7352d33b | Thomas Thrainer | return True |
3201 | 7352d33b | Thomas Thrainer | |
3202 | 7352d33b | Thomas Thrainer | self.bad = False |
3203 | 7352d33b | Thomas Thrainer | verbose = self.op.verbose
|
3204 | 7352d33b | Thomas Thrainer | self._feedback_fn = feedback_fn
|
3205 | 7352d33b | Thomas Thrainer | |
3206 | 7352d33b | Thomas Thrainer | vg_name = self.cfg.GetVGName()
|
3207 | 7352d33b | Thomas Thrainer | drbd_helper = self.cfg.GetDRBDHelper()
|
3208 | 7352d33b | Thomas Thrainer | cluster = self.cfg.GetClusterInfo()
|
3209 | 7352d33b | Thomas Thrainer | hypervisors = cluster.enabled_hypervisors |
3210 | 1c3231aa | Thomas Thrainer | node_data_list = self.my_node_info.values()
|
3211 | 7352d33b | Thomas Thrainer | |
3212 | 7352d33b | Thomas Thrainer | i_non_redundant = [] # Non redundant instances
|
3213 | 7352d33b | Thomas Thrainer | i_non_a_balanced = [] # Non auto-balanced instances
|
3214 | 7352d33b | Thomas Thrainer | i_offline = 0 # Count of offline instances |
3215 | 7352d33b | Thomas Thrainer | n_offline = 0 # Count of offline nodes |
3216 | 7352d33b | Thomas Thrainer | n_drained = 0 # Count of nodes being drained |
3217 | 7352d33b | Thomas Thrainer | node_vol_should = {} |
3218 | 7352d33b | Thomas Thrainer | |
3219 | 7352d33b | Thomas Thrainer | # FIXME: verify OS list
|
3220 | 7352d33b | Thomas Thrainer | |
3221 | 7352d33b | Thomas Thrainer | # File verification
|
3222 | 5eacbcae | Thomas Thrainer | filemap = ComputeAncillaryFiles(cluster, False)
|
3223 | 7352d33b | Thomas Thrainer | |
3224 | 7352d33b | Thomas Thrainer | # do local checksums
|
3225 | 1c3231aa | Thomas Thrainer | master_node_uuid = self.master_node = self.cfg.GetMasterNode() |
3226 | 7352d33b | Thomas Thrainer | master_ip = self.cfg.GetMasterIP()
|
3227 | 7352d33b | Thomas Thrainer | |
3228 | 1c3231aa | Thomas Thrainer | feedback_fn("* Gathering data (%d nodes)" % len(self.my_node_uuids)) |
3229 | 7352d33b | Thomas Thrainer | |
3230 | 7352d33b | Thomas Thrainer | user_scripts = [] |
3231 | 7352d33b | Thomas Thrainer | if self.cfg.GetUseExternalMipScript(): |
3232 | 7352d33b | Thomas Thrainer | user_scripts.append(pathutils.EXTERNAL_MASTER_SETUP_SCRIPT) |
3233 | 7352d33b | Thomas Thrainer | |
3234 | 7352d33b | Thomas Thrainer | node_verify_param = { |
3235 | 7352d33b | Thomas Thrainer | constants.NV_FILELIST: |
3236 | 7352d33b | Thomas Thrainer | map(vcluster.MakeVirtualPath,
|
3237 | 7352d33b | Thomas Thrainer | utils.UniqueSequence(filename |
3238 | 7352d33b | Thomas Thrainer | for files in filemap |
3239 | 7352d33b | Thomas Thrainer | for filename in files)), |
3240 | 7352d33b | Thomas Thrainer | constants.NV_NODELIST: |
3241 | 7352d33b | Thomas Thrainer | self._SelectSshCheckNodes(node_data_list, self.group_uuid, |
3242 | 7352d33b | Thomas Thrainer | self.all_node_info.values()),
|
3243 | 7352d33b | Thomas Thrainer | constants.NV_HYPERVISOR: hypervisors, |
3244 | 7352d33b | Thomas Thrainer | constants.NV_HVPARAMS: |
3245 | 7352d33b | Thomas Thrainer | _GetAllHypervisorParameters(cluster, self.all_inst_info.values()),
|
3246 | 7352d33b | Thomas Thrainer | constants.NV_NODENETTEST: [(node.name, node.primary_ip, node.secondary_ip) |
3247 | 7352d33b | Thomas Thrainer | for node in node_data_list |
3248 | 7352d33b | Thomas Thrainer | if not node.offline], |
3249 | 7352d33b | Thomas Thrainer | constants.NV_INSTANCELIST: hypervisors, |
3250 | 7352d33b | Thomas Thrainer | constants.NV_VERSION: None,
|
3251 | 7352d33b | Thomas Thrainer | constants.NV_HVINFO: self.cfg.GetHypervisorType(),
|
3252 | 7352d33b | Thomas Thrainer | constants.NV_NODESETUP: None,
|
3253 | 7352d33b | Thomas Thrainer | constants.NV_TIME: None,
|
3254 | 1c3231aa | Thomas Thrainer | constants.NV_MASTERIP: (self.cfg.GetMasterNodeName(), master_ip),
|
3255 | 7352d33b | Thomas Thrainer | constants.NV_OSLIST: None,
|
3256 | 7352d33b | Thomas Thrainer | constants.NV_VMNODES: self.cfg.GetNonVmCapableNodeList(),
|
3257 | 7352d33b | Thomas Thrainer | constants.NV_USERSCRIPTS: user_scripts, |
3258 | a6c43c02 | Helga Velroyen | constants.NV_CLIENT_CERT: None,
|
3259 | 7352d33b | Thomas Thrainer | } |
3260 | 7352d33b | Thomas Thrainer | |
3261 | 7352d33b | Thomas Thrainer | if vg_name is not None: |
3262 | 7352d33b | Thomas Thrainer | node_verify_param[constants.NV_VGLIST] = None
|
3263 | 7352d33b | Thomas Thrainer | node_verify_param[constants.NV_LVLIST] = vg_name |
3264 | 7352d33b | Thomas Thrainer | node_verify_param[constants.NV_PVLIST] = [vg_name] |
3265 | 7352d33b | Thomas Thrainer | |
3266 | 9af7ece3 | Helga Velroyen | if cluster.IsDiskTemplateEnabled(constants.DT_DRBD8):
|
3267 | 9af7ece3 | Helga Velroyen | if drbd_helper:
|
3268 | 9af7ece3 | Helga Velroyen | node_verify_param[constants.NV_DRBDVERSION] = None
|
3269 | 9af7ece3 | Helga Velroyen | node_verify_param[constants.NV_DRBDLIST] = None
|
3270 | 9af7ece3 | Helga Velroyen | node_verify_param[constants.NV_DRBDHELPER] = drbd_helper |
3271 | 7352d33b | Thomas Thrainer | |
3272 | 850c53f1 | Helga Velroyen | if cluster.IsFileStorageEnabled() or \ |
3273 | 850c53f1 | Helga Velroyen | cluster.IsSharedFileStorageEnabled(): |
3274 | 7352d33b | Thomas Thrainer | # Load file storage paths only from master node
|
3275 | 13a6c760 | Helga Velroyen | node_verify_param[constants.NV_ACCEPTED_STORAGE_PATHS] = \ |
3276 | 1c3231aa | Thomas Thrainer | self.cfg.GetMasterNodeName()
|
3277 | 13a6c760 | Helga Velroyen | if cluster.IsFileStorageEnabled():
|
3278 | 13a6c760 | Helga Velroyen | node_verify_param[constants.NV_FILE_STORAGE_PATH] = \ |
3279 | 13a6c760 | Helga Velroyen | cluster.file_storage_dir |
3280 | 7352d33b | Thomas Thrainer | |
3281 | 7352d33b | Thomas Thrainer | # bridge checks
|
3282 | 7352d33b | Thomas Thrainer | # FIXME: this needs to be changed per node-group, not cluster-wide
|
3283 | 7352d33b | Thomas Thrainer | bridges = set()
|
3284 | 7352d33b | Thomas Thrainer | default_nicpp = cluster.nicparams[constants.PP_DEFAULT] |
3285 | 7352d33b | Thomas Thrainer | if default_nicpp[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
|
3286 | 7352d33b | Thomas Thrainer | bridges.add(default_nicpp[constants.NIC_LINK]) |
3287 | da4a52a3 | Thomas Thrainer | for inst_uuid in self.my_inst_info.values(): |
3288 | da4a52a3 | Thomas Thrainer | for nic in inst_uuid.nics: |
3289 | 7352d33b | Thomas Thrainer | full_nic = cluster.SimpleFillNIC(nic.nicparams) |
3290 | 7352d33b | Thomas Thrainer | if full_nic[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
|
3291 | 7352d33b | Thomas Thrainer | bridges.add(full_nic[constants.NIC_LINK]) |
3292 | 7352d33b | Thomas Thrainer | |
3293 | 7352d33b | Thomas Thrainer | if bridges:
|
3294 | 7352d33b | Thomas Thrainer | node_verify_param[constants.NV_BRIDGES] = list(bridges)
|
3295 | 7352d33b | Thomas Thrainer | |
3296 | 7352d33b | Thomas Thrainer | # Build our expected cluster state
|
3297 | 1c3231aa | Thomas Thrainer | node_image = dict((node.uuid, self.NodeImage(offline=node.offline, |
3298 | 1c3231aa | Thomas Thrainer | uuid=node.uuid, |
3299 | 7352d33b | Thomas Thrainer | vm_capable=node.vm_capable)) |
3300 | 7352d33b | Thomas Thrainer | for node in node_data_list) |
3301 | 7352d33b | Thomas Thrainer | |
3302 | 7352d33b | Thomas Thrainer | # Gather OOB paths
|
3303 | 7352d33b | Thomas Thrainer | oob_paths = [] |
3304 | 7352d33b | Thomas Thrainer | for node in self.all_node_info.values(): |
3305 | 5eacbcae | Thomas Thrainer | path = SupportsOob(self.cfg, node)
|
3306 | 7352d33b | Thomas Thrainer | if path and path not in oob_paths: |
3307 | 7352d33b | Thomas Thrainer | oob_paths.append(path) |
3308 | 7352d33b | Thomas Thrainer | |
3309 | 7352d33b | Thomas Thrainer | if oob_paths:
|
3310 | 7352d33b | Thomas Thrainer | node_verify_param[constants.NV_OOB_PATHS] = oob_paths |
3311 | 7352d33b | Thomas Thrainer | |
3312 | da4a52a3 | Thomas Thrainer | for inst_uuid in self.my_inst_uuids: |
3313 | da4a52a3 | Thomas Thrainer | instance = self.my_inst_info[inst_uuid]
|
3314 | da4a52a3 | Thomas Thrainer | if instance.admin_state == constants.ADMINST_OFFLINE:
|
3315 | 7352d33b | Thomas Thrainer | i_offline += 1
|
3316 | 7352d33b | Thomas Thrainer | |
3317 | da4a52a3 | Thomas Thrainer | for nuuid in instance.all_nodes: |
3318 | 1c3231aa | Thomas Thrainer | if nuuid not in node_image: |
3319 | 1c3231aa | Thomas Thrainer | gnode = self.NodeImage(uuid=nuuid)
|
3320 | 1c3231aa | Thomas Thrainer | gnode.ghost = (nuuid not in self.all_node_info) |
3321 | 1c3231aa | Thomas Thrainer | node_image[nuuid] = gnode |
3322 | 7352d33b | Thomas Thrainer | |
3323 | da4a52a3 | Thomas Thrainer | instance.MapLVsByNode(node_vol_should) |
3324 | 7352d33b | Thomas Thrainer | |
3325 | da4a52a3 | Thomas Thrainer | pnode = instance.primary_node |
3326 | da4a52a3 | Thomas Thrainer | node_image[pnode].pinst.append(instance.uuid) |
3327 | 7352d33b | Thomas Thrainer | |
3328 | da4a52a3 | Thomas Thrainer | for snode in instance.secondary_nodes: |
3329 | 7352d33b | Thomas Thrainer | nimg = node_image[snode] |
3330 | da4a52a3 | Thomas Thrainer | nimg.sinst.append(instance.uuid) |
3331 | 7352d33b | Thomas Thrainer | if pnode not in nimg.sbp: |
3332 | 7352d33b | Thomas Thrainer | nimg.sbp[pnode] = [] |
3333 | da4a52a3 | Thomas Thrainer | nimg.sbp[pnode].append(instance.uuid) |
3334 | 7352d33b | Thomas Thrainer | |
3335 | 1c3231aa | Thomas Thrainer | es_flags = rpc.GetExclusiveStorageForNodes(self.cfg,
|
3336 | 1c3231aa | Thomas Thrainer | self.my_node_info.keys())
|
3337 | 7352d33b | Thomas Thrainer | # The value of exclusive_storage should be the same across the group, so if
|
3338 | 7352d33b | Thomas Thrainer | # it's True for at least a node, we act as if it were set for all the nodes
|
3339 | 7352d33b | Thomas Thrainer | self._exclusive_storage = compat.any(es_flags.values())
|
3340 | 7352d33b | Thomas Thrainer | if self._exclusive_storage: |
3341 | 7352d33b | Thomas Thrainer | node_verify_param[constants.NV_EXCLUSIVEPVS] = True
|
3342 | 7352d33b | Thomas Thrainer | |
3343 | a9f33339 | Petr Pudlak | node_group_uuids = dict(map(lambda n: (n.name, n.group), |
3344 | a9f33339 | Petr Pudlak | self.cfg.GetAllNodesInfo().values()))
|
3345 | a9f33339 | Petr Pudlak | groups_config = self.cfg.GetAllNodeGroupsInfoDict()
|
3346 | a9f33339 | Petr Pudlak | |
3347 | 7352d33b | Thomas Thrainer | # At this point, we have the in-memory data structures complete,
|
3348 | 7352d33b | Thomas Thrainer | # except for the runtime information, which we'll gather next
|
3349 | 7352d33b | Thomas Thrainer | |
3350 | 7352d33b | Thomas Thrainer | # Due to the way our RPC system works, exact response times cannot be
|
3351 | 7352d33b | Thomas Thrainer | # guaranteed (e.g. a broken node could run into a timeout). By keeping the
|
3352 | 7352d33b | Thomas Thrainer | # time before and after executing the request, we can at least have a time
|
3353 | 7352d33b | Thomas Thrainer | # window.
|
3354 | 7352d33b | Thomas Thrainer | nvinfo_starttime = time.time() |
3355 | 1c3231aa | Thomas Thrainer | all_nvinfo = self.rpc.call_node_verify(self.my_node_uuids, |
3356 | 7352d33b | Thomas Thrainer | node_verify_param, |
3357 | 5b0dfcef | Helga Velroyen | self.cfg.GetClusterName(),
|
3358 | a9f33339 | Petr Pudlak | self.cfg.GetClusterInfo().hvparams,
|
3359 | a9f33339 | Petr Pudlak | node_group_uuids, |
3360 | a9f33339 | Petr Pudlak | groups_config) |
3361 | 7352d33b | Thomas Thrainer | nvinfo_endtime = time.time() |
3362 | 7352d33b | Thomas Thrainer | |
3363 | 7352d33b | Thomas Thrainer | if self.extra_lv_nodes and vg_name is not None: |
3364 | 7352d33b | Thomas Thrainer | extra_lv_nvinfo = \ |
3365 | 7352d33b | Thomas Thrainer | self.rpc.call_node_verify(self.extra_lv_nodes, |
3366 | 7352d33b | Thomas Thrainer | {constants.NV_LVLIST: vg_name}, |
3367 | 5b0dfcef | Helga Velroyen | self.cfg.GetClusterName(),
|
3368 | a9f33339 | Petr Pudlak | self.cfg.GetClusterInfo().hvparams,
|
3369 | a9f33339 | Petr Pudlak | node_group_uuids, |
3370 | a9f33339 | Petr Pudlak | groups_config) |
3371 | 7352d33b | Thomas Thrainer | else:
|
3372 | 7352d33b | Thomas Thrainer | extra_lv_nvinfo = {} |
3373 | 7352d33b | Thomas Thrainer | |
3374 | 7352d33b | Thomas Thrainer | all_drbd_map = self.cfg.ComputeDRBDMap()
|
3375 | 7352d33b | Thomas Thrainer | |
3376 | 7352d33b | Thomas Thrainer | feedback_fn("* Gathering disk information (%s nodes)" %
|
3377 | 1c3231aa | Thomas Thrainer | len(self.my_node_uuids)) |
3378 | 1c3231aa | Thomas Thrainer | instdisk = self._CollectDiskInfo(self.my_node_info.keys(), node_image, |
3379 | 7352d33b | Thomas Thrainer | self.my_inst_info)
|
3380 | 7352d33b | Thomas Thrainer | |
3381 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying configuration file consistency")
|
3382 | 7352d33b | Thomas Thrainer | |
3383 | d5104ca4 | Helga Velroyen | self._VerifyClientCertificates(self.my_node_info.values(), all_nvinfo) |
3384 | 7352d33b | Thomas Thrainer | # If not all nodes are being checked, we need to make sure the master node
|
3385 | 7352d33b | Thomas Thrainer | # and a non-checked vm_capable node are in the list.
|
3386 | 1c3231aa | Thomas Thrainer | absent_node_uuids = set(self.all_node_info).difference(self.my_node_info) |
3387 | 1c3231aa | Thomas Thrainer | if absent_node_uuids:
|
3388 | 7352d33b | Thomas Thrainer | vf_nvinfo = all_nvinfo.copy() |
3389 | 7352d33b | Thomas Thrainer | vf_node_info = list(self.my_node_info.values()) |
3390 | 1c3231aa | Thomas Thrainer | additional_node_uuids = [] |
3391 | 1c3231aa | Thomas Thrainer | if master_node_uuid not in self.my_node_info: |
3392 | 1c3231aa | Thomas Thrainer | additional_node_uuids.append(master_node_uuid) |
3393 | 1c3231aa | Thomas Thrainer | vf_node_info.append(self.all_node_info[master_node_uuid])
|
3394 | 7352d33b | Thomas Thrainer | # Add the first vm_capable node we find which is not included,
|
3395 | 7352d33b | Thomas Thrainer | # excluding the master node (which we already have)
|
3396 | 1c3231aa | Thomas Thrainer | for node_uuid in absent_node_uuids: |
3397 | 1c3231aa | Thomas Thrainer | nodeinfo = self.all_node_info[node_uuid]
|
3398 | 7352d33b | Thomas Thrainer | if (nodeinfo.vm_capable and not nodeinfo.offline and |
3399 | 1c3231aa | Thomas Thrainer | node_uuid != master_node_uuid): |
3400 | 1c3231aa | Thomas Thrainer | additional_node_uuids.append(node_uuid) |
3401 | 1c3231aa | Thomas Thrainer | vf_node_info.append(self.all_node_info[node_uuid])
|
3402 | 7352d33b | Thomas Thrainer | break
|
3403 | 7352d33b | Thomas Thrainer | key = constants.NV_FILELIST |
3404 | 5b0dfcef | Helga Velroyen | vf_nvinfo.update(self.rpc.call_node_verify(
|
3405 | 1c3231aa | Thomas Thrainer | additional_node_uuids, {key: node_verify_param[key]}, |
3406 | a9f33339 | Petr Pudlak | self.cfg.GetClusterName(), self.cfg.GetClusterInfo().hvparams, |
3407 | a9f33339 | Petr Pudlak | node_group_uuids, |
3408 | a9f33339 | Petr Pudlak | groups_config)) |
3409 | 7352d33b | Thomas Thrainer | else:
|
3410 | 7352d33b | Thomas Thrainer | vf_nvinfo = all_nvinfo |
3411 | 7352d33b | Thomas Thrainer | vf_node_info = self.my_node_info.values()
|
3412 | 7352d33b | Thomas Thrainer | |
3413 | 1c3231aa | Thomas Thrainer | self._VerifyFiles(vf_node_info, master_node_uuid, vf_nvinfo, filemap)
|
3414 | 7352d33b | Thomas Thrainer | |
3415 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying node status")
|
3416 | 7352d33b | Thomas Thrainer | |
3417 | 7352d33b | Thomas Thrainer | refos_img = None
|
3418 | 7352d33b | Thomas Thrainer | |
3419 | 7352d33b | Thomas Thrainer | for node_i in node_data_list: |
3420 | 1c3231aa | Thomas Thrainer | nimg = node_image[node_i.uuid] |
3421 | 7352d33b | Thomas Thrainer | |
3422 | 7352d33b | Thomas Thrainer | if node_i.offline:
|
3423 | 7352d33b | Thomas Thrainer | if verbose:
|
3424 | 1c3231aa | Thomas Thrainer | feedback_fn("* Skipping offline node %s" % (node_i.name,))
|
3425 | 7352d33b | Thomas Thrainer | n_offline += 1
|
3426 | 7352d33b | Thomas Thrainer | continue
|
3427 | 7352d33b | Thomas Thrainer | |
3428 | 1c3231aa | Thomas Thrainer | if node_i.uuid == master_node_uuid:
|
3429 | 7352d33b | Thomas Thrainer | ntype = "master"
|
3430 | 7352d33b | Thomas Thrainer | elif node_i.master_candidate:
|
3431 | 7352d33b | Thomas Thrainer | ntype = "master candidate"
|
3432 | 7352d33b | Thomas Thrainer | elif node_i.drained:
|
3433 | 7352d33b | Thomas Thrainer | ntype = "drained"
|
3434 | 7352d33b | Thomas Thrainer | n_drained += 1
|
3435 | 7352d33b | Thomas Thrainer | else:
|
3436 | 7352d33b | Thomas Thrainer | ntype = "regular"
|
3437 | 7352d33b | Thomas Thrainer | if verbose:
|
3438 | 1c3231aa | Thomas Thrainer | feedback_fn("* Verifying node %s (%s)" % (node_i.name, ntype))
|
3439 | 7352d33b | Thomas Thrainer | |
3440 | 1c3231aa | Thomas Thrainer | msg = all_nvinfo[node_i.uuid].fail_msg |
3441 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(msg, constants.CV_ENODERPC, node_i.name,
|
3442 | d0d7d7cf | Thomas Thrainer | "while contacting node: %s", msg)
|
3443 | 7352d33b | Thomas Thrainer | if msg:
|
3444 | 7352d33b | Thomas Thrainer | nimg.rpc_fail = True
|
3445 | 7352d33b | Thomas Thrainer | continue
|
3446 | 7352d33b | Thomas Thrainer | |
3447 | 1c3231aa | Thomas Thrainer | nresult = all_nvinfo[node_i.uuid].payload |
3448 | 7352d33b | Thomas Thrainer | |
3449 | 7352d33b | Thomas Thrainer | nimg.call_ok = self._VerifyNode(node_i, nresult)
|
3450 | 7352d33b | Thomas Thrainer | self._VerifyNodeTime(node_i, nresult, nvinfo_starttime, nvinfo_endtime)
|
3451 | 7352d33b | Thomas Thrainer | self._VerifyNodeNetwork(node_i, nresult)
|
3452 | 7352d33b | Thomas Thrainer | self._VerifyNodeUserScripts(node_i, nresult)
|
3453 | 7352d33b | Thomas Thrainer | self._VerifyOob(node_i, nresult)
|
3454 | 13a6c760 | Helga Velroyen | self._VerifyAcceptedFileStoragePaths(node_i, nresult,
|
3455 | 13a6c760 | Helga Velroyen | node_i.uuid == master_node_uuid) |
3456 | 4b322a76 | Helga Velroyen | self._VerifyFileStoragePaths(node_i, nresult)
|
3457 | 4b322a76 | Helga Velroyen | self._VerifySharedFileStoragePaths(node_i, nresult)
|
3458 | 7352d33b | Thomas Thrainer | |
3459 | 7352d33b | Thomas Thrainer | if nimg.vm_capable:
|
3460 | 7352d33b | Thomas Thrainer | self._UpdateVerifyNodeLVM(node_i, nresult, vg_name, nimg)
|
3461 | 7352d33b | Thomas Thrainer | self._VerifyNodeDrbd(node_i, nresult, self.all_inst_info, drbd_helper, |
3462 | 7352d33b | Thomas Thrainer | all_drbd_map) |
3463 | 7352d33b | Thomas Thrainer | |
3464 | 7352d33b | Thomas Thrainer | self._UpdateNodeVolumes(node_i, nresult, nimg, vg_name)
|
3465 | 7352d33b | Thomas Thrainer | self._UpdateNodeInstances(node_i, nresult, nimg)
|
3466 | 7352d33b | Thomas Thrainer | self._UpdateNodeInfo(node_i, nresult, nimg, vg_name)
|
3467 | 7352d33b | Thomas Thrainer | self._UpdateNodeOS(node_i, nresult, nimg)
|
3468 | 7352d33b | Thomas Thrainer | |
3469 | 7352d33b | Thomas Thrainer | if not nimg.os_fail: |
3470 | 7352d33b | Thomas Thrainer | if refos_img is None: |
3471 | 7352d33b | Thomas Thrainer | refos_img = nimg |
3472 | 7352d33b | Thomas Thrainer | self._VerifyNodeOS(node_i, nimg, refos_img)
|
3473 | 7352d33b | Thomas Thrainer | self._VerifyNodeBridges(node_i, nresult, bridges)
|
3474 | 7352d33b | Thomas Thrainer | |
3475 | da4a52a3 | Thomas Thrainer | # Check whether all running instances are primary for the node. (This
|
3476 | 7352d33b | Thomas Thrainer | # can no longer be done from _VerifyInstance below, since some of the
|
3477 | 7352d33b | Thomas Thrainer | # wrong instances could be from other node groups.)
|
3478 | da4a52a3 | Thomas Thrainer | non_primary_inst_uuids = set(nimg.instances).difference(nimg.pinst)
|
3479 | 7352d33b | Thomas Thrainer | |
3480 | da4a52a3 | Thomas Thrainer | for inst_uuid in non_primary_inst_uuids: |
3481 | da4a52a3 | Thomas Thrainer | test = inst_uuid in self.all_inst_info |
3482 | da4a52a3 | Thomas Thrainer | self._ErrorIf(test, constants.CV_EINSTANCEWRONGNODE,
|
3483 | da4a52a3 | Thomas Thrainer | self.cfg.GetInstanceName(inst_uuid),
|
3484 | d0d7d7cf | Thomas Thrainer | "instance should not run on node %s", node_i.name)
|
3485 | d0d7d7cf | Thomas Thrainer | self._ErrorIf(not test, constants.CV_ENODEORPHANINSTANCE, node_i.name, |
3486 | da4a52a3 | Thomas Thrainer | "node is running unknown instance %s", inst_uuid)
|
3487 | 7352d33b | Thomas Thrainer | |
3488 | 1bb99a33 | Bernardo Dal Seno | self._VerifyGroupDRBDVersion(all_nvinfo)
|
3489 | 7352d33b | Thomas Thrainer | self._VerifyGroupLVM(node_image, vg_name)
|
3490 | 7352d33b | Thomas Thrainer | |
3491 | 1c3231aa | Thomas Thrainer | for node_uuid, result in extra_lv_nvinfo.items(): |
3492 | 1c3231aa | Thomas Thrainer | self._UpdateNodeVolumes(self.all_node_info[node_uuid], result.payload, |
3493 | 1c3231aa | Thomas Thrainer | node_image[node_uuid], vg_name) |
3494 | 7352d33b | Thomas Thrainer | |
3495 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying instance status")
|
3496 | da4a52a3 | Thomas Thrainer | for inst_uuid in self.my_inst_uuids: |
3497 | da4a52a3 | Thomas Thrainer | instance = self.my_inst_info[inst_uuid]
|
3498 | 7352d33b | Thomas Thrainer | if verbose:
|
3499 | da4a52a3 | Thomas Thrainer | feedback_fn("* Verifying instance %s" % instance.name)
|
3500 | da4a52a3 | Thomas Thrainer | self._VerifyInstance(instance, node_image, instdisk[inst_uuid])
|
3501 | 7352d33b | Thomas Thrainer | |
3502 | 7352d33b | Thomas Thrainer | # If the instance is non-redundant we cannot survive losing its primary
|
3503 | 7352d33b | Thomas Thrainer | # node, so we are not N+1 compliant.
|
3504 | da4a52a3 | Thomas Thrainer | if instance.disk_template not in constants.DTS_MIRRORED: |
3505 | 7352d33b | Thomas Thrainer | i_non_redundant.append(instance) |
3506 | 7352d33b | Thomas Thrainer | |
3507 | da4a52a3 | Thomas Thrainer | if not cluster.FillBE(instance)[constants.BE_AUTO_BALANCE]: |
3508 | 7352d33b | Thomas Thrainer | i_non_a_balanced.append(instance) |
3509 | 7352d33b | Thomas Thrainer | |
3510 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying orphan volumes")
|
3511 | 7352d33b | Thomas Thrainer | reserved = utils.FieldSet(*cluster.reserved_lvs) |
3512 | 7352d33b | Thomas Thrainer | |
3513 | 7352d33b | Thomas Thrainer | # We will get spurious "unknown volume" warnings if any node of this group
|
3514 | 7352d33b | Thomas Thrainer | # is secondary for an instance whose primary is in another group. To avoid
|
3515 | 7352d33b | Thomas Thrainer | # them, we find these instances and add their volumes to node_vol_should.
|
3516 | da4a52a3 | Thomas Thrainer | for instance in self.all_inst_info.values(): |
3517 | da4a52a3 | Thomas Thrainer | for secondary in instance.secondary_nodes: |
3518 | 7352d33b | Thomas Thrainer | if (secondary in self.my_node_info |
3519 | da4a52a3 | Thomas Thrainer | and instance.name not in self.my_inst_info): |
3520 | da4a52a3 | Thomas Thrainer | instance.MapLVsByNode(node_vol_should) |
3521 | 7352d33b | Thomas Thrainer | break
|
3522 | 7352d33b | Thomas Thrainer | |
3523 | 7352d33b | Thomas Thrainer | self._VerifyOrphanVolumes(node_vol_should, node_image, reserved)
|
3524 | 7352d33b | Thomas Thrainer | |
3525 | 7352d33b | Thomas Thrainer | if constants.VERIFY_NPLUSONE_MEM not in self.op.skip_checks: |
3526 | 7352d33b | Thomas Thrainer | feedback_fn("* Verifying N+1 Memory redundancy")
|
3527 | 7352d33b | Thomas Thrainer | self._VerifyNPlusOneMemory(node_image, self.my_inst_info) |
3528 | 7352d33b | Thomas Thrainer | |
3529 | 7352d33b | Thomas Thrainer | feedback_fn("* Other Notes")
|
3530 | 7352d33b | Thomas Thrainer | if i_non_redundant:
|
3531 | 7352d33b | Thomas Thrainer | feedback_fn(" - NOTICE: %d non-redundant instance(s) found."
|
3532 | 7352d33b | Thomas Thrainer | % len(i_non_redundant))
|
3533 | 7352d33b | Thomas Thrainer | |
3534 | 7352d33b | Thomas Thrainer | if i_non_a_balanced:
|
3535 | 7352d33b | Thomas Thrainer | feedback_fn(" - NOTICE: %d non-auto-balanced instance(s) found."
|
3536 | 7352d33b | Thomas Thrainer | % len(i_non_a_balanced))
|
3537 | 7352d33b | Thomas Thrainer | |
3538 | 7352d33b | Thomas Thrainer | if i_offline:
|
3539 | 7352d33b | Thomas Thrainer | feedback_fn(" - NOTICE: %d offline instance(s) found." % i_offline)
|
3540 | 7352d33b | Thomas Thrainer | |
3541 | 7352d33b | Thomas Thrainer | if n_offline:
|
3542 | 7352d33b | Thomas Thrainer | feedback_fn(" - NOTICE: %d offline node(s) found." % n_offline)
|
3543 | 7352d33b | Thomas Thrainer | |
3544 | 7352d33b | Thomas Thrainer | if n_drained:
|
3545 | 7352d33b | Thomas Thrainer | feedback_fn(" - NOTICE: %d drained node(s) found." % n_drained)
|
3546 | 7352d33b | Thomas Thrainer | |
3547 | 7352d33b | Thomas Thrainer | return not self.bad |
3548 | 7352d33b | Thomas Thrainer | |
3549 | 7352d33b | Thomas Thrainer | def HooksCallBack(self, phase, hooks_results, feedback_fn, lu_result): |
3550 | 7352d33b | Thomas Thrainer | """Analyze the post-hooks' result
|
3551 | 7352d33b | Thomas Thrainer |
|
3552 | 7352d33b | Thomas Thrainer | This method analyses the hook result, handles it, and sends some
|
3553 | 7352d33b | Thomas Thrainer | nicely-formatted feedback back to the user.
|
3554 | 7352d33b | Thomas Thrainer |
|
3555 | 7352d33b | Thomas Thrainer | @param phase: one of L{constants.HOOKS_PHASE_POST} or
|
3556 | 7352d33b | Thomas Thrainer | L{constants.HOOKS_PHASE_PRE}; it denotes the hooks phase
|
3557 | 7352d33b | Thomas Thrainer | @param hooks_results: the results of the multi-node hooks rpc call
|
3558 | 7352d33b | Thomas Thrainer | @param feedback_fn: function used send feedback back to the caller
|
3559 | 7352d33b | Thomas Thrainer | @param lu_result: previous Exec result
|
3560 | 7352d33b | Thomas Thrainer | @return: the new Exec result, based on the previous result
|
3561 | 7352d33b | Thomas Thrainer | and hook results
|
3562 | 7352d33b | Thomas Thrainer |
|
3563 | 7352d33b | Thomas Thrainer | """
|
3564 | 7352d33b | Thomas Thrainer | # We only really run POST phase hooks, only for non-empty groups,
|
3565 | 7352d33b | Thomas Thrainer | # and are only interested in their results
|
3566 | 1c3231aa | Thomas Thrainer | if not self.my_node_uuids: |
3567 | 7352d33b | Thomas Thrainer | # empty node group
|
3568 | 7352d33b | Thomas Thrainer | pass
|
3569 | 7352d33b | Thomas Thrainer | elif phase == constants.HOOKS_PHASE_POST:
|
3570 | 7352d33b | Thomas Thrainer | # Used to change hooks' output to proper indentation
|
3571 | 7352d33b | Thomas Thrainer | feedback_fn("* Hooks Results")
|
3572 | 7352d33b | Thomas Thrainer | assert hooks_results, "invalid result from hooks" |
3573 | 7352d33b | Thomas Thrainer | |
3574 | 7352d33b | Thomas Thrainer | for node_name in hooks_results: |
3575 | 7352d33b | Thomas Thrainer | res = hooks_results[node_name] |
3576 | 7352d33b | Thomas Thrainer | msg = res.fail_msg |
3577 | 7352d33b | Thomas Thrainer | test = msg and not res.offline |
3578 | 7352d33b | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEHOOKS, node_name,
|
3579 | 7352d33b | Thomas Thrainer | "Communication failure in hooks execution: %s", msg)
|
3580 | 7352d33b | Thomas Thrainer | if res.offline or msg: |
3581 | 7352d33b | Thomas Thrainer | # No need to investigate payload if node is offline or gave
|
3582 | 7352d33b | Thomas Thrainer | # an error.
|
3583 | 7352d33b | Thomas Thrainer | continue
|
3584 | 7352d33b | Thomas Thrainer | for script, hkr, output in res.payload: |
3585 | 7352d33b | Thomas Thrainer | test = hkr == constants.HKR_FAIL |
3586 | 7352d33b | Thomas Thrainer | self._ErrorIf(test, constants.CV_ENODEHOOKS, node_name,
|
3587 | 7352d33b | Thomas Thrainer | "Script %s failed, output:", script)
|
3588 | 7352d33b | Thomas Thrainer | if test:
|
3589 | 7352d33b | Thomas Thrainer | output = self._HOOKS_INDENT_RE.sub(" ", output) |
3590 | 7352d33b | Thomas Thrainer | feedback_fn("%s" % output)
|
3591 | 7352d33b | Thomas Thrainer | lu_result = False
|
3592 | 7352d33b | Thomas Thrainer | |
3593 | 7352d33b | Thomas Thrainer | return lu_result
|
3594 | 7352d33b | Thomas Thrainer | |
3595 | 7352d33b | Thomas Thrainer | |
3596 | 7352d33b | Thomas Thrainer | class LUClusterVerifyDisks(NoHooksLU): |
3597 | 7352d33b | Thomas Thrainer | """Verifies the cluster disks status.
|
3598 | 7352d33b | Thomas Thrainer |
|
3599 | 7352d33b | Thomas Thrainer | """
|
3600 | 7352d33b | Thomas Thrainer | REQ_BGL = False
|
3601 | 7352d33b | Thomas Thrainer | |
3602 | 7352d33b | Thomas Thrainer | def ExpandNames(self): |
3603 | 5eacbcae | Thomas Thrainer | self.share_locks = ShareAll()
|
3604 | 7352d33b | Thomas Thrainer | self.needed_locks = {
|
3605 | 7352d33b | Thomas Thrainer | locking.LEVEL_NODEGROUP: locking.ALL_SET, |
3606 | 7352d33b | Thomas Thrainer | } |
3607 | 7352d33b | Thomas Thrainer | |
3608 | 7352d33b | Thomas Thrainer | def Exec(self, feedback_fn): |
3609 | 7352d33b | Thomas Thrainer | group_names = self.owned_locks(locking.LEVEL_NODEGROUP)
|
3610 | 7352d33b | Thomas Thrainer | |
3611 | 7352d33b | Thomas Thrainer | # Submit one instance of L{opcodes.OpGroupVerifyDisks} per node group
|
3612 | 7352d33b | Thomas Thrainer | return ResultWithJobs([[opcodes.OpGroupVerifyDisks(group_name=group)]
|
3613 | 7352d33b | Thomas Thrainer | for group in group_names]) |