Revision fbdb07b9 scripts/gnt-os
b/scripts/gnt-os | ||
---|---|---|
29 | 29 |
from ganeti import utils |
30 | 30 |
from ganeti import errors |
31 | 31 |
|
32 |
def _GetAllOS(rlist): |
|
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') |
|
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 (path: %s)" % obj.path |
|
79 |
else: |
|
80 |
return "%s (path: %s)" % (obj.args[2], obj.args[1]) |
|
81 |
|
|
82 |
|
|
83 |
def _DiagnoseByOS(rlist): |
|
33 | 84 |
"""Remap an OpDiagnoseOS() return list into an a per-os per-node dictionary |
34 | 85 |
|
35 | 86 |
Args: |
... | ... | |
46 | 97 |
if not nr: |
47 | 98 |
continue |
48 | 99 |
for obj in nr: |
49 |
if _DiagnoseOSValid(obj): |
|
50 |
os_name = obj.name |
|
51 |
else: |
|
52 |
os_name = obj.args[0] |
|
100 |
os_name = _DiagnoseOSName(obj) |
|
53 | 101 |
if os_name not in all_os: |
54 | 102 |
all_os[os_name] = {} |
55 | 103 |
if node_name not in all_os[os_name]: |
... | ... | |
58 | 106 |
|
59 | 107 |
return all_os |
60 | 108 |
|
109 |
|
|
61 | 110 |
def ListOS(opts, args): |
62 | 111 |
"""List the OSes existing on this node. |
63 | 112 |
|
... | ... | |
71 | 120 |
|
72 | 121 |
node_data = result |
73 | 122 |
num_nodes = len(node_data) |
74 |
all_os = _GetAllOS(node_data)
|
|
123 |
all_os = _DiagnoseByOS(node_data)
|
|
75 | 124 |
|
76 | 125 |
valid_os = [] |
77 | 126 |
for os_name, os_node_data in all_os.iteritems(): |
... | ... | |
98 | 147 |
|
99 | 148 |
return 0 |
100 | 149 |
|
101 |
def _DiagnoseOSValid(obj): |
|
102 |
"""Verify whether an OS diagnose object represents a valid OS |
|
103 |
|
|
104 |
Args: |
|
105 |
obj: an diagnostic object as returned by OpDiagnoseOS |
|
106 |
|
|
107 |
Returns: |
|
108 |
bool: OS validity status |
|
109 |
""" |
|
110 |
|
|
111 |
if isinstance(obj, objects.OS): |
|
112 |
return True |
|
113 |
elif isinstance(obj, errors.InvalidOS): |
|
114 |
return False |
|
115 |
else: |
|
116 |
raise errors.ProgrammerError('unknown OS diagnose type') |
|
117 |
|
|
118 |
def _DiagnoseOSStatus(obj): |
|
119 |
"""Generate a status message for an OS diagnose object. |
|
120 |
|
|
121 |
Args: |
|
122 |
obj: an diagnostic object as returned by OpDiagnoseOS |
|
123 |
|
|
124 |
Returns: |
|
125 |
string: a description of the OS status |
|
126 |
""" |
|
127 |
|
|
128 |
if _DiagnoseOSValid(obj): |
|
129 |
return "valid (path: %s)" % obj.path |
|
130 |
else: |
|
131 |
return "%s (path: %s)" % (obj.args[2], obj.args[1]) |
|
132 | 150 |
|
133 | 151 |
def DiagnoseOS(opts, args): |
134 | 152 |
"""Analyse all OSes on this cluster. |
... | ... | |
142 | 160 |
return 1 |
143 | 161 |
|
144 | 162 |
node_data = result |
145 |
all_os = _GetAllOS(node_data)
|
|
163 |
all_os = _DiagnoseByOS(node_data)
|
|
146 | 164 |
|
147 | 165 |
format = "%-*s %-*s %s" |
148 | 166 |
|
Also available in: Unified diff