Revision 96431562 lib/cmdlib/group.py
b/lib/cmdlib/group.py | ||
---|---|---|
28 | 28 |
from ganeti import errors |
29 | 29 |
from ganeti import locking |
30 | 30 |
from ganeti import objects |
31 |
from ganeti import qlang |
|
32 | 31 |
from ganeti import query |
33 | 32 |
from ganeti import utils |
34 | 33 |
from ganeti.masterd import iallocator |
... | ... | |
289 | 288 |
FIELDS = query.GROUP_FIELDS |
290 | 289 |
|
291 | 290 |
def ExpandNames(self, lu): |
292 |
lu.needed_locks = {} |
|
293 |
|
|
294 |
self._all_groups = lu.cfg.GetAllNodeGroupsInfo() |
|
295 |
self._cluster = lu.cfg.GetClusterInfo() |
|
296 |
name_to_uuid = dict((g.name, g.uuid) for g in self._all_groups.values()) |
|
297 |
|
|
298 |
if not self.names: |
|
299 |
self.wanted = [name_to_uuid[name] |
|
300 |
for name in utils.NiceSort(name_to_uuid.keys())] |
|
301 |
else: |
|
302 |
# Accept names to be either names or UUIDs. |
|
303 |
missing = [] |
|
304 |
self.wanted = [] |
|
305 |
all_uuid = frozenset(self._all_groups.keys()) |
|
306 |
|
|
307 |
for name in self.names: |
|
308 |
if name in all_uuid: |
|
309 |
self.wanted.append(name) |
|
310 |
elif name in name_to_uuid: |
|
311 |
self.wanted.append(name_to_uuid[name]) |
|
312 |
else: |
|
313 |
missing.append(name) |
|
314 |
|
|
315 |
if missing: |
|
316 |
raise errors.OpPrereqError("Some groups do not exist: %s" % |
|
317 |
utils.CommaJoin(missing), |
|
318 |
errors.ECODE_NOENT) |
|
291 |
raise NotImplementedError |
|
319 | 292 |
|
320 | 293 |
def DeclareLocks(self, lu, level): |
321 | 294 |
pass |
322 | 295 |
|
323 | 296 |
def _GetQueryData(self, lu): |
324 |
"""Computes the list of node groups and their attributes. |
|
325 |
|
|
326 |
""" |
|
327 |
do_nodes = query.GQ_NODE in self.requested_data |
|
328 |
do_instances = query.GQ_INST in self.requested_data |
|
329 |
|
|
330 |
group_to_nodes = None |
|
331 |
group_to_instances = None |
|
332 |
|
|
333 |
# For GQ_NODE, we need to map group->[nodes], and group->[instances] for |
|
334 |
# GQ_INST. The former is attainable with just GetAllNodesInfo(), but for the |
|
335 |
# latter GetAllInstancesInfo() is not enough, for we have to go through |
|
336 |
# instance->node. Hence, we will need to process nodes even if we only need |
|
337 |
# instance information. |
|
338 |
if do_nodes or do_instances: |
|
339 |
all_nodes = lu.cfg.GetAllNodesInfo() |
|
340 |
group_to_nodes = dict((uuid, []) for uuid in self.wanted) |
|
341 |
node_to_group = {} |
|
342 |
|
|
343 |
for node in all_nodes.values(): |
|
344 |
if node.group in group_to_nodes: |
|
345 |
group_to_nodes[node.group].append(node.uuid) |
|
346 |
node_to_group[node.uuid] = node.group |
|
347 |
|
|
348 |
if do_instances: |
|
349 |
all_instances = lu.cfg.GetAllInstancesInfo() |
|
350 |
group_to_instances = dict((uuid, []) for uuid in self.wanted) |
|
351 |
|
|
352 |
for instance in all_instances.values(): |
|
353 |
node = instance.primary_node |
|
354 |
if node in node_to_group: |
|
355 |
group_to_instances[node_to_group[node]].append(instance.uuid) |
|
356 |
|
|
357 |
if not do_nodes: |
|
358 |
# Do not pass on node information if it was not requested. |
|
359 |
group_to_nodes = None |
|
360 |
|
|
361 |
return query.GroupQueryData(self._cluster, |
|
362 |
[self._all_groups[uuid] |
|
363 |
for uuid in self.wanted], |
|
364 |
group_to_nodes, group_to_instances, |
|
365 |
query.GQ_DISKPARAMS in self.requested_data) |
|
297 |
raise NotImplementedError |
|
366 | 298 |
|
367 | 299 |
|
368 | 300 |
class LUGroupQuery(NoHooksLU): |
... | ... | |
372 | 304 |
REQ_BGL = False |
373 | 305 |
|
374 | 306 |
def CheckArguments(self): |
375 |
self.gq = GroupQuery(qlang.MakeSimpleFilter("name", self.op.names), |
|
376 |
self.op.output_fields, False) |
|
307 |
raise NotImplementedError |
|
377 | 308 |
|
378 | 309 |
def ExpandNames(self): |
379 |
self.gq.ExpandNames(self)
|
|
310 |
raise NotImplementedError
|
|
380 | 311 |
|
381 | 312 |
def DeclareLocks(self, level): |
382 |
self.gq.DeclareLocks(self, level)
|
|
313 |
raise NotImplementedError
|
|
383 | 314 |
|
384 | 315 |
def Exec(self, feedback_fn): |
385 |
return self.gq.OldStyleQuery(self)
|
|
316 |
raise NotImplementedError
|
|
386 | 317 |
|
387 | 318 |
|
388 | 319 |
class LUGroupSetParams(LogicalUnit): |
Also available in: Unified diff