Commit 85661274 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Node query: maintain order as requested

If the client requests certain names, their order should be maintained.
This is already done for instance queries. Moving this part into a
separate function allows sharing code.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarAdeodato Simo <>
parent 89ce4acc
...@@ -508,6 +508,35 @@ class _QueryBase: ...@@ -508,6 +508,35 @@ class _QueryBase:
self.query = query.Query(self.FIELDS, fields) self.query = query.Query(self.FIELDS, fields)
self.requested_data = self.query.RequestedData() self.requested_data = self.query.RequestedData()
self.do_locking = None
self.wanted = None
def _GetNames(self, lu, all_names, lock_level):
"""Helper function to determine names asked for in the query.
if self.do_locking:
names = lu.acquired_locks[lock_level]
names = all_names
if self.wanted == locking.ALL_SET:
assert not self.names
# caller didn't specify names, so ordering is not important
return utils.NiceSort(names)
# caller specified names and we must keep the same order
assert self.names
assert not self.do_locking or lu.acquired_locks[lock_level]
missing = set(self.wanted).difference(names)
if missing:
raise errors.OpExecError("Some items were removed before retrieving"
" their data: %s" % missing)
# Return expanded names
return self.wanted
@classmethod @classmethod
def FieldsQuery(cls, fields): def FieldsQuery(cls, fields):
"""Returns list of available fields. """Returns list of available fields.
...@@ -3521,18 +3550,7 @@ class _NodeQuery(_QueryBase): ...@@ -3521,18 +3550,7 @@ class _NodeQuery(_QueryBase):
""" """
all_info = lu.cfg.GetAllNodesInfo() all_info = lu.cfg.GetAllNodesInfo()
if self.do_locking: nodenames = self._GetNames(lu, all_info.keys(), locking.LEVEL_NODE)
nodenames = lu.acquired_locks[locking.LEVEL_NODE]
elif self.wanted != locking.ALL_SET:
nodenames = self.wanted
missing = set(nodenames).difference(all_info.keys())
if missing:
raise errors.OpExecError("Some nodes were removed before retrieving"
" their data: %s" % missing)
nodenames = all_info.keys()
nodenames = utils.NiceSort(nodenames)
# Gather data as requested # Gather data as requested
if query.NQ_LIVE in self.requested_data: if query.NQ_LIVE in self.requested_data:
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