def DiagnoseOS(top_dirs=None):
"""Compute the validity for all OSes.
- For each name in all the given top directories (if not given defaults
- to constants.OS_SEARCH_PATH) it will return an object. If this is a valid
- os, the object will be an instance of the object.OS class. If not,
- it will be an instance of errors.InvalidOS and this signifies that
- this name does not correspond to a valid OS.
+ Returns an OS object for each name in all the given top directories
+ (if not given defaults to constants.OS_SEARCH_PATH)
Returns:
- list of objects
+ list of OS objects
"""
if top_dirs is None:
os_inst = OSFromDisk(name, base_dir=dir)
result.append(os_inst)
except errors.InvalidOS, err:
- result.append(err)
+ result.append(objects.OS.FromInvalidOS(err))
return result
script)
- return objects.OS(name=name, path=os_dir,
+ return objects.OS(name=name, path=os_dir, status=constants.OS_VALID_STATUS,
create_script=os_scripts['create'],
export_script=os_scripts['export'],
import_script=os_scripts['import'],
from ganeti import errors
-def _DiagnoseOSValid(obj):
- """Verify whether an OS diagnose object represents a valid OS
-
- Args:
- obj: an diagnostic object as returned by OpDiagnoseOS
-
- Returns:
- bool: OS validity status
-
- """
- if isinstance(obj, objects.OS):
- return True
- elif isinstance(obj, errors.InvalidOS):
- return False
- else:
- raise errors.ProgrammerError("unknown OS diagnose type: '%s'" % type(obj))
-
-
-def _DiagnoseOSName(obj):
- """Generate a status message for an OS diagnose object.
-
- Args:
- obj: an diagnostic object as returned by OpDiagnoseOS
-
- Returns:
- string: the name of the OS in question
-
- """
- if _DiagnoseOSValid(obj):
- return obj.name
- else:
- return obj.args[0]
-
-
-def _DiagnoseOSStatus(obj):
- """Generate a status message for an OS diagnose object.
-
- Args:
- obj: an diagnostic object as returned by OpDiagnoseOS
-
- Returns:
- string: a description of the OS status
-
- """
- if _DiagnoseOSValid(obj):
- return "valid"
- else:
- return obj.args[2]
-
-
-def _DiagnoseOSPath(obj):
- """Get the path out of an OS diagnose object.
-
- Args:
- obj: an diagnostic object as returned by OpDiagnoseOS
-
- Returns:
- string: the OS path
-
- """
- if _DiagnoseOSValid(obj):
- return obj.path
- else:
- return obj.args[1]
-
-
def _DiagnoseByOS(rlist):
"""Remap an OpDiagnoseOS() return list into an a per-os per-node dictionary
for node_name, nr in rlist.iteritems():
if not nr:
continue
- for obj in nr:
- os_name = _DiagnoseOSName(obj)
- if os_name not in all_os:
- all_os[os_name] = {}
- if node_name not in all_os[os_name]:
- all_os[os_name][node_name] = []
- all_os[os_name][node_name].append(obj)
+ for os in nr:
+ if os.name not in all_os:
+ all_os[os.name] = {}
+ if node_name not in all_os[os.name]:
+ all_os[os.name][node_name] = []
+ all_os[os.name][node_name].append(os)
return all_os
if len(os_node_data) != num_nodes:
continue
- if utils.all(os_node_data.values(), lambda l: _DiagnoseOSValid(l[0])):
+ if utils.all(os_node_data.values(), lambda l: l[0]):
valid_os.append(os_name)
if not opts.no_headers:
if node_name in all_os[os_name]:
first_os = all_os[os_name][node_name].pop(0)
first_os_msg = ("%s (path: %s)" %
- (_DiagnoseOSStatus(first_os),
- _DiagnoseOSPath(first_os)))
- if _DiagnoseOSValid(first_os):
+ (first_os.status, first_os.path))
+ if first_os:
nodes_valid[node_name] = first_os_msg
else:
nodes_bad[node_name] = first_os_msg
def _OutputNodeHiddenOSStatus(dobj_list):
for dobj in dobj_list:
logger.ToStdout(" [hidden] path: %s, status: %s" %
- (_DiagnoseOSPath(dobj), _DiagnoseOSStatus(dobj)))
+ (dobj.path, dobj.status))
def _OutputPerNodeOSStatus(msg_map):
map_k = utils.NiceSort(msg_map.keys())