Revision 52b5d286
b/lib/cmdlib.py | ||
---|---|---|
3555 | 3555 |
node_to_primary = None |
3556 | 3556 |
node_to_secondary = None |
3557 | 3557 |
|
3558 |
if query.NQ_OOB in self.requested_data: |
|
3559 |
oob_support = dict((name, bool(_SupportsOob(lu.cfg, node))) |
|
3560 |
for name, node in all_info.iteritems()) |
|
3561 |
else: |
|
3562 |
oob_support = None |
|
3563 |
|
|
3558 | 3564 |
if query.NQ_GROUP in self.requested_data: |
3559 | 3565 |
groups = lu.cfg.GetAllNodeGroupsInfo() |
3560 | 3566 |
else: |
... | ... | |
3562 | 3568 |
|
3563 | 3569 |
return query.NodeQueryData([all_info[name] for name in nodenames], |
3564 | 3570 |
live_data, lu.cfg.GetMasterNode(), |
3565 |
node_to_primary, node_to_secondary, groups) |
|
3571 |
node_to_primary, node_to_secondary, groups, |
|
3572 |
oob_support) |
|
3566 | 3573 |
|
3567 | 3574 |
|
3568 | 3575 |
class LUQueryNodes(NoHooksLU): |
b/lib/query.py | ||
---|---|---|
36 | 36 |
(NQ_CONFIG, |
37 | 37 |
NQ_INST, |
38 | 38 |
NQ_LIVE, |
39 |
NQ_GROUP) = range(1, 5) |
|
39 |
NQ_GROUP, |
|
40 |
NQ_OOB) = range(1, 6) |
|
40 | 41 |
|
41 | 42 |
(IQ_CONFIG, |
42 | 43 |
IQ_LIVE, |
... | ... | |
357 | 358 |
|
358 | 359 |
""" |
359 | 360 |
def __init__(self, nodes, live_data, master_name, node_to_primary, |
360 |
node_to_secondary, groups): |
|
361 |
node_to_secondary, groups, oob_support):
|
|
361 | 362 |
"""Initializes this class. |
362 | 363 |
|
363 | 364 |
""" |
... | ... | |
367 | 368 |
self.node_to_primary = node_to_primary |
368 | 369 |
self.node_to_secondary = node_to_secondary |
369 | 370 |
self.groups = groups |
371 |
self.oob_support = oob_support |
|
370 | 372 |
|
371 | 373 |
# Used for individual rows |
372 | 374 |
self.curlive_data = None |
... | ... | |
429 | 431 |
return (constants.QRFS_NORMAL, ng.name) |
430 | 432 |
|
431 | 433 |
|
434 |
def _GetNodePower(ctx, node): |
|
435 |
"""Returns the node powered state |
|
436 |
|
|
437 |
@type ctx: L{NodeQueryData} |
|
438 |
@type node: L{objects.Node} |
|
439 |
@param node: Node object |
|
440 |
|
|
441 |
""" |
|
442 |
if ctx.oob_support[node.name]: |
|
443 |
return (constants.QRFS_NORMAL, node.powered) |
|
444 |
|
|
445 |
return (constants.QRFS_UNAVAIL, None) |
|
446 |
|
|
447 |
|
|
432 | 448 |
def _GetLiveNodeField(field, kind, ctx, node): |
433 | 449 |
"""Gets the value of a "live" field from L{NodeQueryData}. |
434 | 450 |
|
... | ... | |
483 | 499 |
(_MakeField("group", "Group", constants.QFT_TEXT), NQ_GROUP, _GetNodeGroup), |
484 | 500 |
(_MakeField("group.uuid", "GroupUUID", constants.QFT_TEXT), |
485 | 501 |
NQ_CONFIG, lambda ctx, node: (constants.QRFS_NORMAL, node.group)), |
502 |
(_MakeField("powered", "Powered", constants.QFT_BOOL), NQ_OOB, |
|
503 |
_GetNodePower), |
|
486 | 504 |
] |
487 | 505 |
|
488 | 506 |
def _GetLength(getter): |
b/test/ganeti.query_unittest.py | ||
---|---|---|
289 | 289 |
objects.Node(name="node3", drained=False), |
290 | 290 |
] |
291 | 291 |
for live_data in [None, dict.fromkeys([node.name for node in nodes], {})]: |
292 |
nqd = query.NodeQueryData(nodes, live_data, None, None, None, None) |
|
292 |
nqd = query.NodeQueryData(nodes, live_data, None, None, None, None, None)
|
|
293 | 293 |
|
294 | 294 |
q = self._Create(["name", "drained"]) |
295 | 295 |
self.assertEqual(q.RequestedData(), set([query.NQ_CONFIG])) |
... | ... | |
313 | 313 |
q = self._Create(selected) |
314 | 314 |
self.assertEqual(q.RequestedData(), |
315 | 315 |
set([query.NQ_CONFIG, query.NQ_LIVE, query.NQ_INST, |
316 |
query.NQ_GROUP])) |
|
316 |
query.NQ_GROUP, query.NQ_OOB]))
|
|
317 | 317 |
|
318 | 318 |
node_names = ["node%s" % i for i in range(20)] |
319 | 319 |
master_name = node_names[3] |
... | ... | |
376 | 376 |
ng_uuid: objects.NodeGroup(name="ng1", uuid=ng_uuid), |
377 | 377 |
} |
378 | 378 |
|
379 |
oob_support = dict((name, False) for name in node_names) |
|
380 |
|
|
379 | 381 |
master_node.group = ng_uuid |
380 | 382 |
|
381 | 383 |
nqd = query.NodeQueryData(nodes, live_data, master_name, |
382 |
node_to_primary, node_to_secondary, groups) |
|
384 |
node_to_primary, node_to_secondary, groups, |
|
385 |
oob_support) |
|
383 | 386 |
result = q.Query(nqd) |
384 | 387 |
self.assert_(compat.all(len(row) == len(selected) for row in result)) |
385 | 388 |
self.assertEqual([row[field_index["name"]] for row in result], |
... | ... | |
442 | 445 |
live_data = dict.fromkeys([node.name for node in nodes], {}) |
443 | 446 |
|
444 | 447 |
# No data |
445 |
nqd = query.NodeQueryData(None, None, None, None, None, None) |
|
448 |
nqd = query.NodeQueryData(None, None, None, None, None, None, None)
|
|
446 | 449 |
self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER, |
447 | 450 |
nqd, nodes[0]), |
448 | 451 |
(constants.QRFS_NODATA, None)) |
Also available in: Unified diff