Revision 8fa42c7c

b/lib/backend.py
995 995
def DiagnoseOS(top_dirs=None):
996 996
  """Compute the validity for all OSes.
997 997

  
998
  For each name in all the given top directories (if not given defaults
999
  to constants.OS_SEARCH_PATH) it will return an object. If this is a valid
1000
  os, the object will be an instance of the object.OS class. If not,
1001
  it will be an instance of errors.InvalidOS and this signifies that
1002
  this name does not correspond to a valid OS.
998
  Returns an OS object for each name in all the given top directories
999
  (if not given defaults to constants.OS_SEARCH_PATH)
1003 1000

  
1004 1001
  Returns:
1005
    list of objects
1002
    list of OS objects
1006 1003

  
1007 1004
  """
1008 1005
  if top_dirs is None:
......
1021 1018
          os_inst = OSFromDisk(name, base_dir=dir)
1022 1019
          result.append(os_inst)
1023 1020
        except errors.InvalidOS, err:
1024
          result.append(err)
1021
          result.append(objects.OS.FromInvalidOS(err))
1025 1022

  
1026 1023
  return result
1027 1024

  
......
1075 1072
                             script)
1076 1073

  
1077 1074

  
1078
  return objects.OS(name=name, path=os_dir,
1075
  return objects.OS(name=name, path=os_dir, status=constants.OS_VALID_STATUS,
1079 1076
                    create_script=os_scripts['create'],
1080 1077
                    export_script=os_scripts['export'],
1081 1078
                    import_script=os_scripts['import'],
b/scripts/gnt-os
30 30
from ganeti import errors
31 31

  
32 32

  
33
def _DiagnoseOSValid(obj):
34
  """Verify whether an OS diagnose object represents a valid OS
35

  
36
    Args:
37
      obj: an diagnostic object as returned by OpDiagnoseOS
38

  
39
    Returns:
40
      bool: OS validity status
41

  
42
  """
43
  if isinstance(obj, objects.OS):
44
    return True
45
  elif isinstance(obj, errors.InvalidOS):
46
    return False
47
  else:
48
    raise errors.ProgrammerError("unknown OS diagnose type: '%s'" % type(obj))
49

  
50

  
51
def _DiagnoseOSName(obj):
52
  """Generate a status message for an OS diagnose object.
53

  
54
    Args:
55
      obj: an diagnostic object as returned by OpDiagnoseOS
56

  
57
    Returns:
58
      string: the name of the OS in question
59

  
60
  """
61
  if _DiagnoseOSValid(obj):
62
    return obj.name
63
  else:
64
    return obj.args[0]
65

  
66

  
67
def _DiagnoseOSStatus(obj):
68
  """Generate a status message for an OS diagnose object.
69

  
70
    Args:
71
      obj: an diagnostic object as returned by OpDiagnoseOS
72

  
73
    Returns:
74
      string: a description of the OS status
75

  
76
  """
77
  if _DiagnoseOSValid(obj):
78
    return "valid"
79
  else:
80
    return obj.args[2]
81

  
82

  
83
def _DiagnoseOSPath(obj):
84
  """Get the path out of an OS diagnose object.
85

  
86
    Args:
87
      obj: an diagnostic object as returned by OpDiagnoseOS
88

  
89
    Returns:
90
      string: the OS path
91

  
92
  """
93
  if _DiagnoseOSValid(obj):
94
    return obj.path
95
  else:
96
    return obj.args[1]
97

  
98

  
99 33
def _DiagnoseByOS(rlist):
100 34
  """Remap an OpDiagnoseOS() return list into an a per-os per-node dictionary
101 35

  
......
112 46
  for node_name, nr in rlist.iteritems():
113 47
    if not nr:
114 48
      continue
115
    for obj in nr:
116
      os_name = _DiagnoseOSName(obj)
117
      if os_name not in all_os:
118
        all_os[os_name] = {}
119
      if node_name not in all_os[os_name]:
120
        all_os[os_name][node_name] = []
121
      all_os[os_name][node_name].append(obj)
49
    for os in nr:
50
      if os.name not in all_os:
51
        all_os[os.name] = {}
52
      if node_name not in all_os[os.name]:
53
        all_os[os.name][node_name] = []
54
      all_os[os.name][node_name].append(os)
122 55

  
123 56
  return all_os
124 57

  
......
143 76
    if len(os_node_data) != num_nodes:
144 77
      continue
145 78

  
146
    if utils.all(os_node_data.values(), lambda l: _DiagnoseOSValid(l[0])):
79
    if utils.all(os_node_data.values(), lambda l: l[0]):
147 80
      valid_os.append(os_name)
148 81

  
149 82
  if not opts.no_headers:
......
183 116
      if node_name in all_os[os_name]:
184 117
        first_os = all_os[os_name][node_name].pop(0)
185 118
        first_os_msg = ("%s (path: %s)" %
186
                        (_DiagnoseOSStatus(first_os),
187
                         _DiagnoseOSPath(first_os)))
188
        if _DiagnoseOSValid(first_os):
119
                        (first_os.status, first_os.path))
120
        if first_os:
189 121
          nodes_valid[node_name] = first_os_msg
190 122
        else:
191 123
          nodes_bad[node_name] = first_os_msg
......
204 136
    def _OutputNodeHiddenOSStatus(dobj_list):
205 137
      for dobj in dobj_list:
206 138
        logger.ToStdout("    [hidden] path: %s, status: %s" %
207
                        (_DiagnoseOSPath(dobj), _DiagnoseOSStatus(dobj)))
139
                        (dobj.path, dobj.status))
208 140

  
209 141
    def _OutputPerNodeOSStatus(msg_map):
210 142
      map_k = utils.NiceSort(msg_map.keys())

Also available in: Unified diff