Revision 572a277b

b/lib/cmdlib.py
16095 16095
    """
16096 16096
    do_instances = query.NETQ_INST in self.requested_data
16097 16097
    do_groups = do_instances or (query.NETQ_GROUP in self.requested_data)
16098
    do_stats = query.NETQ_STATS in self.requested_data
16099 16098

  
16100 16099
    network_to_groups = None
16101 16100
    network_to_instances = None
16102
    stats = None
16103 16101

  
16104 16102
    # For NETQ_GROUP, we need to map network->[groups]
16105 16103
    if do_groups:
......
16133 16131
                    network_to_instances[net_uuid].append(instance.name)
16134 16132
                    break
16135 16133

  
16136
    if do_stats:
16137
      stats = {}
16138
      for uuid, net in self._all_networks.items():
16139
        if uuid in self.wanted:
16140
          pool = network.AddressPool(net)
16141
          stats[uuid] = {
16142
            "free_count": pool.GetFreeCount(),
16143
            "reserved_count": pool.GetReservedCount(),
16144
            "map": pool.GetMap(),
16145
            "external_reservations":
16146
              utils.CommaJoin(pool.GetExternalReservations()),
16147
            }
16134
    if query.NETQ_STATS in self.requested_data:
16135
      stats = \
16136
        dict((uuid,
16137
              self._GetStats(network.AddressPool(self._all_networks[uuid])))
16138
             for uuid in self.wanted)
16139
    else:
16140
      stats = None
16148 16141

  
16149 16142
    return query.NetworkQueryData([self._all_networks[uuid]
16150 16143
                                   for uuid in self.wanted],
......
16152 16145
                                   network_to_instances,
16153 16146
                                   stats)
16154 16147

  
16148
  @staticmethod
16149
  def _GetStats(pool):
16150
    """Returns statistics for a network address pool.
16151

  
16152
    """
16153
    return {
16154
      "free_count": pool.GetFreeCount(),
16155
      "reserved_count": pool.GetReservedCount(),
16156
      "map": pool.GetMap(),
16157
      "external_reservations":
16158
        utils.CommaJoin(pool.GetExternalReservations()),
16159
      }
16160

  
16155 16161

  
16156 16162
class LUNetworkQuery(NoHooksLU):
16157 16163
  """Logical unit for querying networks.

Also available in: Unified diff