Revision 216fe2f3 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): |
|
33 |
"""Remap an OpDiagnoseOS() return list into an a per-os per-node dictionary |
|
34 |
|
|
35 |
Args: |
|
36 |
rlist: a map with nodes as keys and diagnoseobjects as values |
|
37 |
|
|
38 |
Returns: |
|
39 |
map: a map with osnames as keys and as value another map, with nodes as |
|
40 |
keys and diagnoseobjects as values |
|
41 |
e.g. {"debian-etch": {"node1": <object>, "node2": <object>}} |
|
42 |
""" |
|
43 |
|
|
44 |
all_os = {} |
|
45 |
for node_name, nr in rlist.iteritems(): |
|
46 |
if not nr: |
|
47 |
continue |
|
48 |
for obj in nr: |
|
49 |
if _DiagnoseOSValid(obj): |
|
50 |
os_name = obj.name |
|
51 |
else: |
|
52 |
os_name = obj.args[0] |
|
53 |
if os_name not in all_os: |
|
54 |
all_os[os_name] = {} |
|
55 |
if node_name not in all_os[os_name]: |
|
56 |
all_os[os_name][node_name] = [] |
|
57 |
all_os[os_name][node_name].append(obj) |
|
58 |
|
|
59 |
return all_os |
|
60 |
|
|
32 | 61 |
def ListOS(opts, args): |
33 | 62 |
"""List the OSes existing on this node. |
34 | 63 |
|
... | ... | |
40 | 69 |
logger.ToStdout("Can't get the OS list") |
41 | 70 |
return 1 |
42 | 71 |
|
43 |
# filter non-valid OS-es |
|
44 |
oses = {} |
|
45 |
for node_name in result: |
|
46 |
oses[node_name] = [obj for obj in result[node_name] |
|
47 |
if isinstance(obj, objects.OS)] |
|
48 |
|
|
49 |
# Get intersection of all OSes |
|
50 |
fnode = oses.keys()[0] |
|
51 |
os_set = set([os_inst.name for os_inst in oses[fnode]]) |
|
52 |
del oses[fnode] |
|
53 |
for node in oses: |
|
54 |
os_set &= set([os_inst.name for os_inst in oses[node]]) |
|
72 |
node_data = result |
|
73 |
num_nodes = len(node_data) |
|
74 |
all_os = _GetAllOS(node_data) |
|
75 |
|
|
76 |
valid_os = [] |
|
77 |
for os_name, os_node_data in all_os.iteritems(): |
|
78 |
if len(os_node_data) != num_nodes: |
|
79 |
continue |
|
80 |
valid = True |
|
81 |
for l in os_node_data.values(): |
|
82 |
if not _DiagnoseOSValid(l[0]): |
|
83 |
valid = False |
|
84 |
break |
|
85 |
if valid: |
|
86 |
valid_os.append(os_name) |
|
55 | 87 |
|
56 | 88 |
if not opts.no_headers: |
57 | 89 |
headers = {"name": "Name"} |
... | ... | |
59 | 91 |
headers = None |
60 | 92 |
|
61 | 93 |
data = GenerateTable(separator=None, headers=headers, fields=["name"], |
62 |
data=[[os] for os in os_set])
|
|
94 |
data=[[os] for os in valid_os])
|
|
63 | 95 |
|
64 | 96 |
for line in data: |
65 | 97 |
logger.ToStdout(line) |
... | ... | |
109 | 141 |
logger.ToStdout("Can't get the OS list") |
110 | 142 |
return 1 |
111 | 143 |
|
112 |
format = "%-*s %-*s %s" |
|
113 |
|
|
114 | 144 |
node_data = result |
115 |
all_os = {} |
|
116 |
for node_name in node_data: |
|
117 |
nr = node_data[node_name] |
|
118 |
if nr: |
|
119 |
for obj in nr: |
|
120 |
if isinstance(obj, objects.OS): |
|
121 |
os_name = obj.name |
|
122 |
else: |
|
123 |
os_name = obj.args[0] |
|
124 |
if os_name not in all_os: |
|
125 |
all_os[os_name] = {} |
|
126 |
if node_name not in all_os[os_name]: |
|
127 |
all_os[os_name][node_name] = [] |
|
128 |
all_os[os_name][node_name].append(obj) |
|
145 |
all_os = _GetAllOS(node_data) |
|
146 |
|
|
147 |
format = "%-*s %-*s %s" |
|
129 | 148 |
|
130 | 149 |
max_name = len('Name') |
131 | 150 |
if all_os: |
Also available in: Unified diff