+ fields.extend(_GetItemTimestampFields(IQ_CONFIG))
+
+ return _PrepareFieldList(fields)
+
+
+class LockQueryData:
+ """Data container for lock data queries.
+
+ """
+ def __init__(self, lockdata):
+ """Initializes this class.
+
+ """
+ self.lockdata = lockdata
+
+ def __iter__(self):
+ """Iterate over all locks.
+
+ """
+ return iter(self.lockdata)
+
+
+def _GetLockOwners(_, data):
+ """Returns a sorted list of a lock's current owners.
+
+ """
+ (_, _, owners, _) = data
+
+ if owners:
+ owners = utils.NiceSort(owners)
+
+ return (constants.QRFS_NORMAL, owners)
+
+
+def _GetLockPending(_, data):
+ """Returns a sorted list of a lock's pending acquires.
+
+ """
+ (_, _, _, pending) = data
+
+ if pending:
+ pending = [(mode, utils.NiceSort(names))
+ for (mode, names) in pending]
+
+ return (constants.QRFS_NORMAL, pending)
+
+
+def _BuildLockFields():
+ """Builds list of fields for lock queries.
+
+ """
+ return _PrepareFieldList([
+ (_MakeField("name", "Name", constants.QFT_TEXT), None,
+ lambda ctx, (name, mode, owners, pending): (constants.QRFS_NORMAL, name)),
+ (_MakeField("mode", "Mode", constants.QFT_OTHER), LQ_MODE,
+ lambda ctx, (name, mode, owners, pending): (constants.QRFS_NORMAL, mode)),
+ (_MakeField("owner", "Owner", constants.QFT_OTHER), LQ_OWNER,
+ _GetLockOwners),
+ (_MakeField("pending", "Pending", constants.QFT_OTHER), LQ_PENDING,
+ _GetLockPending),
+ ])
+
+
+class GroupQueryData:
+ """Data container for node group data queries.
+
+ """
+ def __init__(self, groups, group_to_nodes, group_to_instances):
+ """Initializes this class.
+
+ @param groups: List of node group objects
+ @type group_to_nodes: dict; group UUID as key
+ @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
+
+ """
+ self.groups = groups
+ self.group_to_nodes = group_to_nodes
+ self.group_to_instances = group_to_instances
+
+ def __iter__(self):
+ """Iterate over all node groups.
+
+ """
+ return iter(self.groups)
+
+
+_GROUP_SIMPLE_FIELDS = {
+ "alloc_policy": ("AllocPolicy", constants.QFT_TEXT),
+ "name": ("Group", constants.QFT_TEXT),
+ "serial_no": ("SerialNo", constants.QFT_NUMBER),
+ "uuid": ("UUID", constants.QFT_TEXT),
+ "ndparams": ("NDParams", constants.QFT_OTHER),
+ }
+
+
+def _BuildGroupFields():
+ """Builds list of fields for node group queries.
+
+ """
+ # Add simple fields
+ fields = [(_MakeField(name, title, kind), GQ_CONFIG, _GetItemAttr(name))
+ for (name, (title, kind)) in _GROUP_SIMPLE_FIELDS.items()]
+
+ def _GetLength(getter):
+ return lambda ctx, group: (constants.QRFS_NORMAL,
+ len(getter(ctx)[group.uuid]))
+
+ def _GetSortedList(getter):
+ return lambda ctx, group: (constants.QRFS_NORMAL,
+ utils.NiceSort(getter(ctx)[group.uuid]))
+
+ group_to_nodes = operator.attrgetter("group_to_nodes")
+ group_to_instances = operator.attrgetter("group_to_instances")
+
+ # Add fields for nodes
+ fields.extend([
+ (_MakeField("node_cnt", "Nodes", constants.QFT_NUMBER),
+ GQ_NODE, _GetLength(group_to_nodes)),
+ (_MakeField("node_list", "NodeList", constants.QFT_OTHER),
+ GQ_NODE, _GetSortedList(group_to_nodes)),
+ ])
+
+ # Add fields for instances
+ fields.extend([
+ (_MakeField("pinst_cnt", "Instances", constants.QFT_NUMBER),
+ GQ_INST, _GetLength(group_to_instances)),
+ (_MakeField("pinst_list", "InstanceList", constants.QFT_OTHER),
+ GQ_INST, _GetSortedList(group_to_instances)),
+ ])
+
+ fields.extend(_GetItemTimestampFields(GQ_CONFIG))