Commit 2c758845 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

query: Expose diskparamters through query


Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent f9bbf32b
......@@ -13841,7 +13841,8 @@ class _GroupQuery(_QueryBase):
return query.GroupQueryData(self._cluster,
[self._all_groups[uuid]
for uuid in self.wanted],
group_to_nodes, group_to_instances)
group_to_nodes, group_to_instances,
query.GQ_DISKPARAMS in self.requested_data)
 
 
class LUGroupQuery(NoHooksLU):
......
......@@ -93,7 +93,8 @@ from ganeti.constants import (QFT_UNKNOWN, QFT_TEXT, QFT_BOOL, QFT_NUMBER,
(GQ_CONFIG,
GQ_NODE,
GQ_INST) = range(200, 203)
GQ_INST,
GQ_DISKPARAMS) = range(200, 204)
(CQ_CONFIG,
CQ_QUEUE_DRAINED,
......@@ -2002,7 +2003,8 @@ class GroupQueryData:
"""Data container for node group data queries.
"""
def __init__(self, cluster, groups, group_to_nodes, group_to_instances):
def __init__(self, cluster, groups, group_to_nodes, group_to_instances,
want_diskparams):
"""Initializes this class.
@param cluster: Cluster object
......@@ -2011,16 +2013,20 @@ class GroupQueryData:
@param group_to_nodes: Per-group list of nodes
@type group_to_instances: dict; group UUID as key
@param group_to_instances: Per-group list of (primary) instances
@type want_diskparams: bool
@param want_diskparams: Whether diskparamters should be calculated
"""
self.groups = groups
self.group_to_nodes = group_to_nodes
self.group_to_instances = group_to_instances
self.cluster = cluster
self.want_diskparams = want_diskparams
# Used for individual rows
self.group_ipolicy = None
self.ndparams = None
self.group_dp = None
def __iter__(self):
"""Iterate over all node groups.
......@@ -2032,6 +2038,10 @@ class GroupQueryData:
for group in self.groups:
self.group_ipolicy = self.cluster.SimpleFillIPolicy(group.ipolicy)
self.ndparams = self.cluster.SimpleFillND(group.ndparams)
if self.want_diskparams:
self.group_dp = self.cluster.SimpleFillDP(group.diskparams)
else:
self.group_dp = None
yield group
......@@ -2095,6 +2105,12 @@ def _BuildGroupFields():
(_MakeField("ndparams", "NDParams", QFT_OTHER,
"Node parameters"),
GQ_CONFIG, 0, lambda ctx, _: ctx.ndparams),
(_MakeField("diskparams", "DiskParameters", QFT_OTHER,
"Disk parameters (merged)"),
GQ_DISKPARAMS, 0, lambda ctx, _: ctx.group_dp),
(_MakeField("custom_diskparams", "CustomDiskParameters", QFT_OTHER,
"Custom disk parameters"),
GQ_CONFIG, 0, _GetItemAttr("diskparams")),
])
# ND parameters
......
......@@ -961,12 +961,14 @@ class TestGroupQuery(unittest.TestCase):
alloc_policy=constants.ALLOC_POLICY_PREFERRED,
ipolicy=objects.MakeEmptyIPolicy(),
ndparams={},
diskparams={},
),
objects.NodeGroup(name="restricted",
uuid="d2a40a74-18e7-11e0-9143-001d0904baeb",
alloc_policy=constants.ALLOC_POLICY_LAST_RESORT,
ipolicy=objects.MakeEmptyIPolicy(),
ndparams={}
ndparams={},
diskparams={},
),
]
self.cluster = objects.Cluster(cluster_name="testcluster",
......@@ -979,6 +981,7 @@ class TestGroupQuery(unittest.TestCase):
},
ndparams=constants.NDC_DEFAULTS,
ipolicy=constants.IPOLICY_DEFAULTS,
diskparams=constants.DISK_DT_DEFAULTS,
)
def _Create(self, selected):
......@@ -986,7 +989,7 @@ class TestGroupQuery(unittest.TestCase):
def testSimple(self):
q = self._Create(["name", "uuid", "alloc_policy"])
gqd = query.GroupQueryData(self.cluster, self.groups, None, None)
gqd = query.GroupQueryData(self.cluster, self.groups, None, None, False)
self.assertEqual(q.RequestedData(), set([query.GQ_CONFIG]))
......@@ -1008,7 +1011,8 @@ class TestGroupQuery(unittest.TestCase):
}
q = self._Create(["name", "node_cnt", "node_list"])
gqd = query.GroupQueryData(self.cluster, self.groups, groups_to_nodes, None)
gqd = query.GroupQueryData(self.cluster, self.groups, groups_to_nodes, None,
False)
self.assertEqual(q.RequestedData(), set([query.GQ_CONFIG, query.GQ_NODE]))
......@@ -1031,7 +1035,7 @@ class TestGroupQuery(unittest.TestCase):
q = self._Create(["pinst_cnt", "pinst_list"])
gqd = query.GroupQueryData(self.cluster, self.groups, None,
groups_to_instances)
groups_to_instances, False)
self.assertEqual(q.RequestedData(), set([query.GQ_INST]))
......
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