Revision fab9573b lib/query.py

b/lib/query.py
83 83
(IQ_CONFIG,
84 84
 IQ_LIVE,
85 85
 IQ_DISKUSAGE,
86
 IQ_CONSOLE) = range(100, 104)
86
 IQ_CONSOLE,
87
 IQ_NODES) = range(100, 105)
87 88

  
88 89
(LQ_MODE,
89 90
 LQ_OWNER,
......
1223 1224

  
1224 1225
  """
1225 1226
  def __init__(self, instances, cluster, disk_usage, offline_nodes, bad_nodes,
1226
               live_data, wrongnode_inst, console):
1227
               live_data, wrongnode_inst, console, nodes, groups):
1227 1228
    """Initializes this class.
1228 1229

  
1229 1230
    @param instances: List of instance objects
......
1240 1241
    @param wrongnode_inst: Set of instances running on wrong node(s)
1241 1242
    @type console: dict; instance name as key
1242 1243
    @param console: Per-instance console information
1244
    @type nodes: dict; node name as key
1245
    @param nodes: Node objects
1243 1246

  
1244 1247
    """
1245 1248
    assert len(set(bad_nodes) & set(offline_nodes)) == len(offline_nodes), \
......
1255 1258
    self.live_data = live_data
1256 1259
    self.wrongnode_inst = wrongnode_inst
1257 1260
    self.console = console
1261
    self.nodes = nodes
1262
    self.groups = groups
1258 1263

  
1259 1264
    # Used for individual rows
1260 1265
    self.inst_hvparams = None
......
1701 1706
  }
1702 1707

  
1703 1708

  
1709
def _GetInstNodeGroup(ctx, default, node_name):
1710
  """Gets group UUID of an instance node.
1711

  
1712
  @type ctx: L{InstanceQueryData}
1713
  @param default: Default value
1714
  @type node_name: string
1715
  @param node_name: Node name
1716

  
1717
  """
1718
  try:
1719
    node = ctx.nodes[node_name]
1720
  except KeyError:
1721
    return default
1722
  else:
1723
    return node.group
1724

  
1725

  
1726
def _GetInstNodeGroupName(ctx, default, node_name):
1727
  """Gets group name of an instance node.
1728

  
1729
  @type ctx: L{InstanceQueryData}
1730
  @param default: Default value
1731
  @type node_name: string
1732
  @param node_name: Node name
1733

  
1734
  """
1735
  try:
1736
    node = ctx.nodes[node_name]
1737
  except KeyError:
1738
    return default
1739

  
1740
  try:
1741
    group = ctx.groups[node.group]
1742
  except KeyError:
1743
    return default
1744

  
1745
  return group.name
1746

  
1747

  
1704 1748
def _BuildInstanceFields():
1705 1749
  """Builds list of fields for instance queries.
1706 1750

  
......
1708 1752
  fields = [
1709 1753
    (_MakeField("pnode", "Primary_node", QFT_TEXT, "Primary node"),
1710 1754
     IQ_CONFIG, QFF_HOSTNAME, _GetItemAttr("primary_node")),
1755
    (_MakeField("pnode.group", "PrimaryNodeGroup", QFT_TEXT,
1756
                "Primary node's group"),
1757
     IQ_NODES, 0,
1758
     lambda ctx, inst: _GetInstNodeGroupName(ctx, _FS_UNAVAIL,
1759
                                             inst.primary_node)),
1760
    (_MakeField("pnode.group.uuid", "PrimaryNodeGroupUUID", QFT_TEXT,
1761
                "Primary node's group UUID"),
1762
     IQ_NODES, 0,
1763
     lambda ctx, inst: _GetInstNodeGroup(ctx, _FS_UNAVAIL, inst.primary_node)),
1711 1764
    # TODO: Allow filtering by secondary node as hostname
1712 1765
    (_MakeField("snodes", "Secondary_Nodes", QFT_OTHER,
1713 1766
                "Secondary nodes; usually this will just be one node"),
1714 1767
     IQ_CONFIG, 0, lambda ctx, inst: list(inst.secondary_nodes)),
1768
    (_MakeField("snodes.group", "SecondaryNodesGroups", QFT_OTHER,
1769
                "Node groups of secondary nodes"),
1770
     IQ_NODES, 0,
1771
     lambda ctx, inst: map(compat.partial(_GetInstNodeGroupName, ctx, None),
1772
                           inst.secondary_nodes)),
1773
    (_MakeField("snodes.group.uuid", "SecondaryNodesGroupsUUID", QFT_OTHER,
1774
                "Node group UUIDs of secondary nodes"),
1775
     IQ_NODES, 0,
1776
     lambda ctx, inst: map(compat.partial(_GetInstNodeGroup, ctx, None),
1777
                           inst.secondary_nodes)),
1715 1778
    (_MakeField("admin_state", "Autostart", QFT_BOOL,
1716 1779
                "Desired state of instance (if set, the instance should be"
1717 1780
                " up)"),

Also available in: Unified diff