Revision a5c30dc2
b/lib/cmdlib.py | ||
---|---|---|
1286 | 1286 |
raise errors.ProgrammerError("Unhandled certificate error code %r" % errcode) |
1287 | 1287 |
|
1288 | 1288 |
|
1289 |
class LUClusterVerify(LogicalUnit):
|
|
1290 |
"""Verifies the cluster status.
|
|
1289 |
class _VerifyErrors(object):
|
|
1290 |
"""Mix-in for cluster/group verify LUs.
|
|
1291 | 1291 |
|
1292 |
""" |
|
1293 |
HPATH = "cluster-verify" |
|
1294 |
HTYPE = constants.HTYPE_CLUSTER |
|
1295 |
REQ_BGL = False |
|
1292 |
It provides _Error and _ErrorIf, and updates the self.bad boolean. (Expects |
|
1293 |
self.op and self._feedback_fn to be available.) |
|
1296 | 1294 |
|
1295 |
""" |
|
1297 | 1296 |
TCLUSTER = "cluster" |
1298 | 1297 |
TNODE = "node" |
1299 | 1298 |
TINSTANCE = "instance" |
... | ... | |
1330 | 1329 |
ETYPE_ERROR = "ERROR" |
1331 | 1330 |
ETYPE_WARNING = "WARNING" |
1332 | 1331 |
|
1332 |
def _Error(self, ecode, item, msg, *args, **kwargs): |
|
1333 |
"""Format an error message. |
|
1334 |
|
|
1335 |
Based on the opcode's error_codes parameter, either format a |
|
1336 |
parseable error code, or a simpler error string. |
|
1337 |
|
|
1338 |
This must be called only from Exec and functions called from Exec. |
|
1339 |
|
|
1340 |
""" |
|
1341 |
ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) |
|
1342 |
itype, etxt = ecode |
|
1343 |
# first complete the msg |
|
1344 |
if args: |
|
1345 |
msg = msg % args |
|
1346 |
# then format the whole message |
|
1347 |
if self.op.error_codes: # This is a mix-in. pylint: disable-msg=E1101 |
|
1348 |
msg = "%s:%s:%s:%s:%s" % (ltype, etxt, itype, item, msg) |
|
1349 |
else: |
|
1350 |
if item: |
|
1351 |
item = " " + item |
|
1352 |
else: |
|
1353 |
item = "" |
|
1354 |
msg = "%s: %s%s: %s" % (ltype, itype, item, msg) |
|
1355 |
# and finally report it via the feedback_fn |
|
1356 |
self._feedback_fn(" - %s" % msg) # Mix-in. pylint: disable-msg=E1101 |
|
1357 |
|
|
1358 |
def _ErrorIf(self, cond, *args, **kwargs): |
|
1359 |
"""Log an error message if the passed condition is True. |
|
1360 |
|
|
1361 |
""" |
|
1362 |
cond = (bool(cond) |
|
1363 |
or self.op.debug_simulate_errors) # pylint: disable-msg=E1101 |
|
1364 |
if cond: |
|
1365 |
self._Error(*args, **kwargs) |
|
1366 |
# do not mark the operation as failed for WARN cases only |
|
1367 |
if kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) == self.ETYPE_ERROR: |
|
1368 |
self.bad = self.bad or cond |
|
1369 |
|
|
1370 |
|
|
1371 |
class LUClusterVerify(LogicalUnit, _VerifyErrors): |
|
1372 |
"""Verifies the cluster status. |
|
1373 |
|
|
1374 |
""" |
|
1375 |
HPATH = "cluster-verify" |
|
1376 |
HTYPE = constants.HTYPE_CLUSTER |
|
1377 |
REQ_BGL = False |
|
1378 |
|
|
1333 | 1379 |
_HOOKS_INDENT_RE = re.compile("^", re.M) |
1334 | 1380 |
|
1335 | 1381 |
class NodeImage(object): |
... | ... | |
1397 | 1443 |
self.my_inst_names = utils.NiceSort(list(self.all_inst_info)) |
1398 | 1444 |
self.my_inst_info = self.all_inst_info |
1399 | 1445 |
|
1400 |
def _Error(self, ecode, item, msg, *args, **kwargs): |
|
1401 |
"""Format an error message. |
|
1402 |
|
|
1403 |
Based on the opcode's error_codes parameter, either format a |
|
1404 |
parseable error code, or a simpler error string. |
|
1405 |
|
|
1406 |
This must be called only from Exec and functions called from Exec. |
|
1407 |
|
|
1408 |
""" |
|
1409 |
ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) |
|
1410 |
itype, etxt = ecode |
|
1411 |
# first complete the msg |
|
1412 |
if args: |
|
1413 |
msg = msg % args |
|
1414 |
# then format the whole message |
|
1415 |
if self.op.error_codes: |
|
1416 |
msg = "%s:%s:%s:%s:%s" % (ltype, etxt, itype, item, msg) |
|
1417 |
else: |
|
1418 |
if item: |
|
1419 |
item = " " + item |
|
1420 |
else: |
|
1421 |
item = "" |
|
1422 |
msg = "%s: %s%s: %s" % (ltype, itype, item, msg) |
|
1423 |
# and finally report it via the feedback_fn |
|
1424 |
self._feedback_fn(" - %s" % msg) |
|
1425 |
|
|
1426 |
def _ErrorIf(self, cond, *args, **kwargs): |
|
1427 |
"""Log an error message if the passed condition is True. |
|
1428 |
|
|
1429 |
""" |
|
1430 |
cond = bool(cond) or self.op.debug_simulate_errors |
|
1431 |
if cond: |
|
1432 |
self._Error(*args, **kwargs) |
|
1433 |
# do not mark the operation as failed for WARN cases only |
|
1434 |
if kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) == self.ETYPE_ERROR: |
|
1435 |
self.bad = self.bad or cond |
|
1436 |
|
|
1437 | 1446 |
def _VerifyNode(self, ninfo, nresult): |
1438 | 1447 |
"""Perform some basic validation on data returned from a node. |
1439 | 1448 |
|
Also available in: Unified diff