1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 """External Storage related commands"""
31
32
33
34
35
36
37
38 from ganeti.cli import *
39 from ganeti import opcodes
40 from ganeti import utils
41
42
44 """List detailed information about ExtStorage providers.
45
46 @param opts: the command line options selected by the user
47 @type args: list
48 @param args: empty list or list of ExtStorage providers' names
49 @rtype: int
50 @return: the desired exit code
51
52 """
53 op = opcodes.OpExtStorageDiagnose(output_fields=["name", "nodegroup_status",
54 "parameters"],
55 names=[])
56
57 result = SubmitOpCode(op, opts=opts)
58
59 if not result:
60 ToStderr("Can't get the ExtStorage providers list")
61 return 1
62
63 do_filter = bool(args)
64
65 for (name, nodegroup_data, parameters) in result:
66 if do_filter:
67 if name not in args:
68 continue
69 else:
70 args.remove(name)
71
72 nodegroups_valid = []
73 for nodegroup_name, nodegroup_status in nodegroup_data.iteritems():
74 if nodegroup_status:
75 nodegroups_valid.append(nodegroup_name)
76
77 ToStdout("%s:", name)
78
79 if nodegroups_valid != []:
80 ToStdout(" - Valid for nodegroups:")
81 for ndgrp in utils.NiceSort(nodegroups_valid):
82 ToStdout(" %s", ndgrp)
83 ToStdout(" - Supported parameters:")
84 for pname, pdesc in parameters:
85 ToStdout(" %s: %s", pname, pdesc)
86 else:
87 ToStdout(" - Invalid for all nodegroups")
88
89 ToStdout("")
90
91 if args:
92 for name in args:
93 ToStdout("%s: Not Found", name)
94 ToStdout("")
95
96 return 0
97
98
100 """Beautifier function for ExtStorage status.
101
102 @type status: boolean
103 @param status: is the ExtStorage provider valid
104 @type diagnose: string
105 @param diagnose: the error message for invalid ExtStorages
106 @rtype: string
107 @return: a formatted status
108
109 """
110 if status:
111 return "valid"
112 else:
113 return "invalid - %s" % diagnose
114
115
117 """Analyse all ExtStorage providers.
118
119 @param opts: the command line options selected by the user
120 @type args: list
121 @param args: should be an empty list
122 @rtype: int
123 @return: the desired exit code
124
125 """
126 op = opcodes.OpExtStorageDiagnose(output_fields=["name", "node_status",
127 "nodegroup_status"],
128 names=[])
129
130 result = SubmitOpCode(op, opts=opts)
131
132 if not result:
133 ToStderr("Can't get the list of ExtStorage providers")
134 return 1
135
136 for provider_name, node_data, nodegroup_data in result:
137
138 nodes_valid = {}
139 nodes_bad = {}
140 nodegroups_valid = {}
141 nodegroups_bad = {}
142
143
144 for node_name, node_info in node_data.iteritems():
145 if node_info:
146 (fo_path, fo_status, fo_msg, fo_params) = node_info.pop(0)
147 fo_msg = "%s (path: %s)" % (_ExtStorageStatus(fo_status, fo_msg),
148 fo_path)
149 if fo_params:
150 fo_msg += (" [parameters: %s]" %
151 utils.CommaJoin([v[0] for v in fo_params]))
152 else:
153 fo_msg += " [no parameters]"
154 if fo_status:
155 nodes_valid[node_name] = fo_msg
156 else:
157 nodes_bad[node_name] = fo_msg
158 else:
159 nodes_bad[node_name] = "ExtStorage provider not found"
160
161
162 for nodegroup_name, nodegroup_status in nodegroup_data.iteritems():
163 status = nodegroup_status
164 if status:
165 nodegroups_valid[nodegroup_name] = "valid"
166 else:
167 nodegroups_bad[nodegroup_name] = "invalid"
168
169 def _OutputPerNodegroupStatus(msg_map):
170 map_k = utils.NiceSort(msg_map.keys())
171 for nodegroup in map_k:
172 ToStdout(" For nodegroup: %s --> %s", nodegroup,
173 msg_map[nodegroup])
174
175 def _OutputPerNodeStatus(msg_map):
176 map_k = utils.NiceSort(msg_map.keys())
177 for node_name in map_k:
178 ToStdout(" Node: %s, status: %s", node_name, msg_map[node_name])
179
180
181 st_msg = "Provider: %s" % provider_name
182 ToStdout(st_msg)
183 ToStdout("---")
184 _OutputPerNodeStatus(nodes_valid)
185 _OutputPerNodeStatus(nodes_bad)
186 ToStdout(" --")
187 _OutputPerNodegroupStatus(nodegroups_valid)
188 _OutputPerNodegroupStatus(nodegroups_bad)
189 ToStdout("")
190
191 return 0
192
193
194 commands = {
195 "diagnose": (
196 DiagnoseExtStorage, ARGS_NONE, [PRIORITY_OPT],
197 "", "Diagnose all ExtStorage providers"),
198 "info": (
199 ShowExtStorageInfo, [ArgOs()], [PRIORITY_OPT],
200 "", "Show info about ExtStorage providers"),
201 }
202
203
206