Revision 8fa42c7c scripts/gnt-os

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