Commit 52b5d286 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Support query of node field 'powered'



This field is based on OOB support and is only available if there's oob
support for that node.
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 7ab8b7d7
......@@ -3555,6 +3555,12 @@ class _NodeQuery(_QueryBase):
node_to_primary = None
node_to_secondary = None
if query.NQ_OOB in self.requested_data:
oob_support = dict((name, bool(_SupportsOob(lu.cfg, node)))
for name, node in all_info.iteritems())
else:
oob_support = None
if query.NQ_GROUP in self.requested_data:
groups = lu.cfg.GetAllNodeGroupsInfo()
else:
......@@ -3562,7 +3568,8 @@ class _NodeQuery(_QueryBase):
return query.NodeQueryData([all_info[name] for name in nodenames],
live_data, lu.cfg.GetMasterNode(),
node_to_primary, node_to_secondary, groups)
node_to_primary, node_to_secondary, groups,
oob_support)
class LUQueryNodes(NoHooksLU):
......
......@@ -36,7 +36,8 @@ from ganeti import ht
(NQ_CONFIG,
NQ_INST,
NQ_LIVE,
NQ_GROUP) = range(1, 5)
NQ_GROUP,
NQ_OOB) = range(1, 6)
(IQ_CONFIG,
IQ_LIVE,
......@@ -357,7 +358,7 @@ class NodeQueryData:
"""
def __init__(self, nodes, live_data, master_name, node_to_primary,
node_to_secondary, groups):
node_to_secondary, groups, oob_support):
"""Initializes this class.
"""
......@@ -367,6 +368,7 @@ class NodeQueryData:
self.node_to_primary = node_to_primary
self.node_to_secondary = node_to_secondary
self.groups = groups
self.oob_support = oob_support
# Used for individual rows
self.curlive_data = None
......@@ -429,6 +431,20 @@ def _GetNodeGroup(ctx, node):
return (constants.QRFS_NORMAL, ng.name)
def _GetNodePower(ctx, node):
"""Returns the node powered state
@type ctx: L{NodeQueryData}
@type node: L{objects.Node}
@param node: Node object
"""
if ctx.oob_support[node.name]:
return (constants.QRFS_NORMAL, node.powered)
return (constants.QRFS_UNAVAIL, None)
def _GetLiveNodeField(field, kind, ctx, node):
"""Gets the value of a "live" field from L{NodeQueryData}.
......@@ -483,6 +499,8 @@ def _BuildNodeFields():
(_MakeField("group", "Group", constants.QFT_TEXT), NQ_GROUP, _GetNodeGroup),
(_MakeField("group.uuid", "GroupUUID", constants.QFT_TEXT),
NQ_CONFIG, lambda ctx, node: (constants.QRFS_NORMAL, node.group)),
(_MakeField("powered", "Powered", constants.QFT_BOOL), NQ_OOB,
_GetNodePower),
]
def _GetLength(getter):
......
......@@ -289,7 +289,7 @@ class TestNodeQuery(unittest.TestCase):
objects.Node(name="node3", drained=False),
]
for live_data in [None, dict.fromkeys([node.name for node in nodes], {})]:
nqd = query.NodeQueryData(nodes, live_data, None, None, None, None)
nqd = query.NodeQueryData(nodes, live_data, None, None, None, None, None)
q = self._Create(["name", "drained"])
self.assertEqual(q.RequestedData(), set([query.NQ_CONFIG]))
......@@ -313,7 +313,7 @@ class TestNodeQuery(unittest.TestCase):
q = self._Create(selected)
self.assertEqual(q.RequestedData(),
set([query.NQ_CONFIG, query.NQ_LIVE, query.NQ_INST,
query.NQ_GROUP]))
query.NQ_GROUP, query.NQ_OOB]))
node_names = ["node%s" % i for i in range(20)]
master_name = node_names[3]
......@@ -376,10 +376,13 @@ class TestNodeQuery(unittest.TestCase):
ng_uuid: objects.NodeGroup(name="ng1", uuid=ng_uuid),
}
oob_support = dict((name, False) for name in node_names)
master_node.group = ng_uuid
nqd = query.NodeQueryData(nodes, live_data, master_name,
node_to_primary, node_to_secondary, groups)
node_to_primary, node_to_secondary, groups,
oob_support)
result = q.Query(nqd)
self.assert_(compat.all(len(row) == len(selected) for row in result))
self.assertEqual([row[field_index["name"]] for row in result],
......@@ -442,7 +445,7 @@ class TestNodeQuery(unittest.TestCase):
live_data = dict.fromkeys([node.name for node in nodes], {})
# No data
nqd = query.NodeQueryData(None, None, None, None, None, None)
nqd = query.NodeQueryData(None, None, None, None, None, None, None)
self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER,
nqd, nodes[0]),
(constants.QRFS_NODATA, None))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment