-
-
-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
-
- Args:
- rlist: a map with nodes as keys and diagnoseobjects as values
-
- Returns:
- map: a map with osnames as keys and as value another map, with nodes as
- keys and diagnoseobjects as values
- e.g. {"debian-etch": {"node1": <object>, "node2": <object>}}
-
- """
- all_os = {}
- 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)
-
- return all_os