Revision bad78e66 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
2738 | 2738 |
_OP_REQP = ["output_fields", "names"] |
2739 | 2739 |
REQ_BGL = False |
2740 | 2740 |
_FIELDS_STATIC = utils.FieldSet() |
2741 |
_FIELDS_DYNAMIC = utils.FieldSet("name", "valid", "node_status", "variants") |
|
2742 |
# Fields that need calculation of global os validity |
|
2743 |
_FIELDS_NEEDVALID = frozenset(["valid", "variants"]) |
|
2741 |
_FIELDS_DYNAMIC = utils.FieldSet("name", "valid", "node_status", "variants", |
|
2742 |
"parameters", "api_versions") |
|
2744 | 2743 |
|
2745 | 2744 |
def ExpandNames(self): |
2746 | 2745 |
if self.op.names: |
... | ... | |
2772 | 2771 |
@rtype: dict |
2773 | 2772 |
@return: a dictionary with osnames as keys and as value another |
2774 | 2773 |
map, with nodes as keys and tuples of (path, status, diagnose, |
2775 |
variants, parameters) as values, eg:: |
|
2774 |
variants, parameters, api_versions) as values, eg::
|
|
2776 | 2775 |
|
2777 | 2776 |
{"debian-etch": {"node1": [(/usr/lib/..., True, "", [], []), |
2778 | 2777 |
(/srv/..., False, "invalid api")], |
... | ... | |
2789 | 2788 |
for node_name, nr in rlist.items(): |
2790 | 2789 |
if nr.fail_msg or not nr.payload: |
2791 | 2790 |
continue |
2792 |
for name, path, status, diagnose, variants, params in nr.payload: |
|
2791 |
for (name, path, status, diagnose, variants, |
|
2792 |
params, api_versions) in nr.payload: |
|
2793 | 2793 |
if name not in all_os: |
2794 | 2794 |
# build a list of nodes for this os containing empty lists |
2795 | 2795 |
# for each node in node_list |
2796 | 2796 |
all_os[name] = {} |
2797 | 2797 |
for nname in good_nodes: |
2798 | 2798 |
all_os[name][nname] = [] |
2799 |
# convert params from [name, help] to (name, help) |
|
2800 |
params = [tuple(v) for v in params] |
|
2799 | 2801 |
all_os[name][node_name].append((path, status, diagnose, |
2800 |
variants, params)) |
|
2802 |
variants, params, api_versions))
|
|
2801 | 2803 |
return all_os |
2802 | 2804 |
|
2803 | 2805 |
def Exec(self, feedback_fn): |
... | ... | |
2808 | 2810 |
node_data = self.rpc.call_os_diagnose(valid_nodes) |
2809 | 2811 |
pol = self._DiagnoseByOS(node_data) |
2810 | 2812 |
output = [] |
2811 |
calc_valid = self._FIELDS_NEEDVALID.intersection(self.op.output_fields) |
|
2812 |
calc_variants = "variants" in self.op.output_fields |
|
2813 | 2813 |
|
2814 | 2814 |
for os_name, os_data in pol.items(): |
2815 | 2815 |
row = [] |
2816 |
if calc_valid: |
|
2817 |
valid = True |
|
2818 |
variants = None |
|
2819 |
for osl in os_data.values(): |
|
2820 |
valid = bool(valid and osl and osl[0][1]) |
|
2821 |
if not valid: |
|
2822 |
variants = set() |
|
2823 |
break |
|
2824 |
if calc_variants: |
|
2825 |
node_variants = osl[0][3] |
|
2826 |
if variants is None: |
|
2827 |
variants = set(node_variants) |
|
2828 |
else: |
|
2829 |
variants.intersection_update(node_variants) |
|
2816 |
valid = True |
|
2817 |
(variants, params, api_versions) = null_state = (set(), set(), set()) |
|
2818 |
for idx, osl in enumerate(os_data.values()): |
|
2819 |
valid = bool(valid and osl and osl[0][1]) |
|
2820 |
if not valid: |
|
2821 |
(variants, params, api_versions) = null_state |
|
2822 |
break |
|
2823 |
node_variants, node_params, node_api = osl[0][3:6] |
|
2824 |
if idx == 0: # first entry |
|
2825 |
variants = set(node_variants) |
|
2826 |
params = set(node_params) |
|
2827 |
api_versions = set(node_api) |
|
2828 |
else: # keep consistency |
|
2829 |
variants.intersection_update(node_variants) |
|
2830 |
params.intersection_update(node_params) |
|
2831 |
api_versions.intersection_update(node_api) |
|
2830 | 2832 |
|
2831 | 2833 |
for field in self.op.output_fields: |
2832 | 2834 |
if field == "name": |
... | ... | |
2840 | 2842 |
val[node_name] = nos_list |
2841 | 2843 |
elif field == "variants": |
2842 | 2844 |
val = list(variants) |
2845 |
elif field == "parameters": |
|
2846 |
val = list(params) |
|
2847 |
elif field == "api_versions": |
|
2848 |
val = list(api_versions) |
|
2843 | 2849 |
else: |
2844 | 2850 |
raise errors.ParameterError(field) |
2845 | 2851 |
row.append(val) |
Also available in: Unified diff