Revision 1e288a26 lib/cmdlib.py

b/lib/cmdlib.py
2145 2145
  _OP_REQP = ["output_fields", "names"]
2146 2146
  REQ_BGL = False
2147 2147
  _FIELDS_STATIC = utils.FieldSet()
2148
  _FIELDS_DYNAMIC = utils.FieldSet("name", "valid", "node_status")
2148
  _FIELDS_DYNAMIC = utils.FieldSet("name", "valid", "node_status", "variants")
2149
  # Fields that need calculation of global os validity
2150
  _FIELDS_NEEDVALID = frozenset(["valid", "variants"])
2149 2151

  
2150 2152
  def ExpandNames(self):
2151 2153
    if self.op.names:
......
2211 2213
    node_data = self.rpc.call_os_diagnose(valid_nodes)
2212 2214
    pol = self._DiagnoseByOS(valid_nodes, node_data)
2213 2215
    output = []
2216
    calc_valid = self._FIELDS_NEEDVALID.intersection(self.op.output_fields)
2217
    calc_variants = "variants" in self.op.output_fields
2218

  
2214 2219
    for os_name, os_data in pol.items():
2215 2220
      row = []
2221
      if calc_valid:
2222
        valid = True
2223
        variants = None
2224
        for osl in os_data.values():
2225
          valid = valid and osl and osl[0][1]
2226
          if not valid:
2227
            variants = None
2228
            break
2229
          if calc_variants:
2230
            node_variants = osl[0][3]
2231
            if variants is None:
2232
              variants = node_variants
2233
            else:
2234
              variants = [v for v in variants if v in node_variants]
2235

  
2216 2236
      for field in self.op.output_fields:
2217 2237
        if field == "name":
2218 2238
          val = os_name
2219 2239
        elif field == "valid":
2220
          val = utils.all([osl and osl[0][1] for osl in os_data.values()])
2240
          val = valid
2221 2241
        elif field == "node_status":
2222 2242
          # this is just a copy of the dict
2223 2243
          val = {}
2224 2244
          for node_name, nos_list in os_data.items():
2225 2245
            val[node_name] = nos_list
2246
        elif field == "variants":
2247
          val =  variants
2226 2248
        else:
2227 2249
          raise errors.ParameterError(field)
2228 2250
        row.append(val)

Also available in: Unified diff