Revision 5d28cb6f lib/cmdlib.py

b/lib/cmdlib.py
3868 3868
    """Computes the list of instances and their attributes.
3869 3869

  
3870 3870
    """
3871
    cluster = lu.cfg.GetClusterInfo()
3871 3872
    all_info = lu.cfg.GetAllInstancesInfo()
3872 3873

  
3873 3874
    instance_names = self._GetNames(lu, all_info.keys(), locking.LEVEL_INSTANCE)
......
3881 3882
    wrongnode_inst = set()
3882 3883

  
3883 3884
    # Gather data as requested
3884
    if query.IQ_LIVE in self.requested_data:
3885
    if self.requested_data & set([query.IQ_LIVE, query.IQ_CONSOLE]):
3885 3886
      live_data = {}
3886 3887
      node_data = lu.rpc.call_all_instances_info(nodes, hv_list)
3887 3888
      for name in nodes:
......
3911 3912
    else:
3912 3913
      disk_usage = None
3913 3914

  
3915
    if query.IQ_CONSOLE in self.requested_data:
3916
      consinfo = {}
3917
      for inst in instance_list:
3918
        if inst.name in live_data:
3919
          # Instance is running
3920
          consinfo[inst.name] = _GetInstanceConsole(cluster, inst)
3921
        else:
3922
          consinfo[inst.name] = None
3923
      assert set(consinfo.keys()) == set(instance_names)
3924
    else:
3925
      consinfo = None
3926

  
3914 3927
    return query.InstanceQueryData(instance_list, lu.cfg.GetClusterInfo(),
3915 3928
                                   disk_usage, offline_nodes, bad_nodes,
3916
                                   live_data, wrongnode_inst)
3929
                                   live_data, wrongnode_inst, consinfo)
3917 3930

  
3918 3931

  
3919 3932
class LUQuery(NoHooksLU):
......
7804 7817

  
7805 7818
    logging.debug("Connecting to console of %s on %s", instance.name, node)
7806 7819

  
7807
    hyper = hypervisor.GetHypervisor(instance.hypervisor)
7808
    cluster = self.cfg.GetClusterInfo()
7809
    # beparams and hvparams are passed separately, to avoid editing the
7810
    # instance and then saving the defaults in the instance itself.
7811
    hvparams = cluster.FillHV(instance)
7812
    beparams = cluster.FillBE(instance)
7813
    console = hyper.GetInstanceConsole(instance, hvparams, beparams)
7820
    return _GetInstanceConsole(self.cfg.GetClusterInfo(), instance)
7821

  
7822

  
7823
def _GetInstanceConsole(cluster, instance):
7824
  """Returns console information for an instance.
7825

  
7826
  @type cluster: L{objects.Cluster}
7827
  @type instance: L{objects.Instance}
7828
  @rtype: dict
7829

  
7830
  """
7831
  hyper = hypervisor.GetHypervisor(instance.hypervisor)
7832
  # beparams and hvparams are passed separately, to avoid editing the
7833
  # instance and then saving the defaults in the instance itself.
7834
  hvparams = cluster.FillHV(instance)
7835
  beparams = cluster.FillBE(instance)
7836
  console = hyper.GetInstanceConsole(instance, hvparams, beparams)
7814 7837

  
7815
    assert console.instance == instance.name
7816
    assert console.Validate()
7838
  assert console.instance == instance.name
7839
  assert console.Validate()
7817 7840

  
7818
    return console.ToDict()
7841
  return console.ToDict()
7819 7842

  
7820 7843

  
7821 7844
class LUInstanceReplaceDisks(LogicalUnit):

Also available in: Unified diff