root / lib / client / gnt_storage.py @ 364c350f
History | View | Annotate | Download (5.5 kB)
1 | b954f097 | Constantinos Venetsanopoulos | #
|
---|---|---|---|
2 | b954f097 | Constantinos Venetsanopoulos | #
|
3 | b954f097 | Constantinos Venetsanopoulos | |
4 | b954f097 | Constantinos Venetsanopoulos | # Copyright (C) 2012 Google Inc.
|
5 | b954f097 | Constantinos Venetsanopoulos | #
|
6 | b954f097 | Constantinos Venetsanopoulos | # This program is free software; you can redistribute it and/or modify
|
7 | b954f097 | Constantinos Venetsanopoulos | # it under the terms of the GNU General Public License as published by
|
8 | b954f097 | Constantinos Venetsanopoulos | # the Free Software Foundation; either version 2 of the License, or
|
9 | b954f097 | Constantinos Venetsanopoulos | # (at your option) any later version.
|
10 | b954f097 | Constantinos Venetsanopoulos | #
|
11 | b954f097 | Constantinos Venetsanopoulos | # This program is distributed in the hope that it will be useful, but
|
12 | b954f097 | Constantinos Venetsanopoulos | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | b954f097 | Constantinos Venetsanopoulos | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | b954f097 | Constantinos Venetsanopoulos | # General Public License for more details.
|
15 | b954f097 | Constantinos Venetsanopoulos | #
|
16 | b954f097 | Constantinos Venetsanopoulos | # You should have received a copy of the GNU General Public License
|
17 | b954f097 | Constantinos Venetsanopoulos | # along with this program; if not, write to the Free Software
|
18 | b954f097 | Constantinos Venetsanopoulos | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | b954f097 | Constantinos Venetsanopoulos | # 02110-1301, USA.
|
20 | b954f097 | Constantinos Venetsanopoulos | |
21 | b954f097 | Constantinos Venetsanopoulos | """External Storage related commands"""
|
22 | b954f097 | Constantinos Venetsanopoulos | |
23 | b954f097 | Constantinos Venetsanopoulos | # pylint: disable=W0401,W0613,W0614,C0103
|
24 | b954f097 | Constantinos Venetsanopoulos | # W0401: Wildcard import ganeti.cli
|
25 | b954f097 | Constantinos Venetsanopoulos | # W0613: Unused argument, since all functions follow the same API
|
26 | b954f097 | Constantinos Venetsanopoulos | # W0614: Unused import %s from wildcard import (since we need cli)
|
27 | b954f097 | Constantinos Venetsanopoulos | # C0103: Invalid name gnt-storage
|
28 | b954f097 | Constantinos Venetsanopoulos | |
29 | b954f097 | Constantinos Venetsanopoulos | from ganeti.cli import * |
30 | b954f097 | Constantinos Venetsanopoulos | from ganeti import opcodes |
31 | b954f097 | Constantinos Venetsanopoulos | from ganeti import utils |
32 | b954f097 | Constantinos Venetsanopoulos | |
33 | b954f097 | Constantinos Venetsanopoulos | |
34 | b954f097 | Constantinos Venetsanopoulos | def ShowExtStorageInfo(opts, args): |
35 | b954f097 | Constantinos Venetsanopoulos | """List detailed information about ExtStorage providers.
|
36 | b954f097 | Constantinos Venetsanopoulos |
|
37 | b954f097 | Constantinos Venetsanopoulos | @param opts: the command line options selected by the user
|
38 | b954f097 | Constantinos Venetsanopoulos | @type args: list
|
39 | b954f097 | Constantinos Venetsanopoulos | @param args: empty list or list of ExtStorage providers' names
|
40 | b954f097 | Constantinos Venetsanopoulos | @rtype: int
|
41 | b954f097 | Constantinos Venetsanopoulos | @return: the desired exit code
|
42 | b954f097 | Constantinos Venetsanopoulos |
|
43 | b954f097 | Constantinos Venetsanopoulos | """
|
44 | b954f097 | Constantinos Venetsanopoulos | op = opcodes.OpExtStorageDiagnose(output_fields=["name", "nodegroup_status", |
45 | b954f097 | Constantinos Venetsanopoulos | "parameters"],
|
46 | b954f097 | Constantinos Venetsanopoulos | names=[]) |
47 | b954f097 | Constantinos Venetsanopoulos | |
48 | b954f097 | Constantinos Venetsanopoulos | result = SubmitOpCode(op, opts=opts) |
49 | b954f097 | Constantinos Venetsanopoulos | |
50 | b954f097 | Constantinos Venetsanopoulos | if not result: |
51 | b954f097 | Constantinos Venetsanopoulos | ToStderr("Can't get the ExtStorage providers list")
|
52 | b954f097 | Constantinos Venetsanopoulos | return 1 |
53 | b954f097 | Constantinos Venetsanopoulos | |
54 | b954f097 | Constantinos Venetsanopoulos | do_filter = bool(args)
|
55 | b954f097 | Constantinos Venetsanopoulos | |
56 | b954f097 | Constantinos Venetsanopoulos | for (name, nodegroup_data, parameters) in result: |
57 | b954f097 | Constantinos Venetsanopoulos | if do_filter:
|
58 | b954f097 | Constantinos Venetsanopoulos | if name not in args: |
59 | b954f097 | Constantinos Venetsanopoulos | continue
|
60 | b954f097 | Constantinos Venetsanopoulos | else:
|
61 | b954f097 | Constantinos Venetsanopoulos | args.remove(name) |
62 | b954f097 | Constantinos Venetsanopoulos | |
63 | b954f097 | Constantinos Venetsanopoulos | nodegroups_valid = [] |
64 | b954f097 | Constantinos Venetsanopoulos | for nodegroup_name, nodegroup_status in nodegroup_data.iteritems(): |
65 | b954f097 | Constantinos Venetsanopoulos | if nodegroup_status:
|
66 | b954f097 | Constantinos Venetsanopoulos | nodegroups_valid.append(nodegroup_name) |
67 | b954f097 | Constantinos Venetsanopoulos | |
68 | b954f097 | Constantinos Venetsanopoulos | ToStdout("%s:", name)
|
69 | b954f097 | Constantinos Venetsanopoulos | |
70 | b954f097 | Constantinos Venetsanopoulos | if nodegroups_valid != []:
|
71 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" - Valid for nodegroups:")
|
72 | b954f097 | Constantinos Venetsanopoulos | for ndgrp in utils.NiceSort(nodegroups_valid): |
73 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" %s", ndgrp)
|
74 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" - Supported parameters:")
|
75 | b954f097 | Constantinos Venetsanopoulos | for pname, pdesc in parameters: |
76 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" %s: %s", pname, pdesc)
|
77 | b954f097 | Constantinos Venetsanopoulos | else:
|
78 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" - Invalid for all nodegroups")
|
79 | b954f097 | Constantinos Venetsanopoulos | |
80 | b954f097 | Constantinos Venetsanopoulos | ToStdout("")
|
81 | b954f097 | Constantinos Venetsanopoulos | |
82 | b954f097 | Constantinos Venetsanopoulos | if args:
|
83 | b954f097 | Constantinos Venetsanopoulos | for name in args: |
84 | b954f097 | Constantinos Venetsanopoulos | ToStdout("%s: Not Found", name)
|
85 | b954f097 | Constantinos Venetsanopoulos | ToStdout("")
|
86 | b954f097 | Constantinos Venetsanopoulos | |
87 | b954f097 | Constantinos Venetsanopoulos | return 0 |
88 | b954f097 | Constantinos Venetsanopoulos | |
89 | b954f097 | Constantinos Venetsanopoulos | |
90 | b954f097 | Constantinos Venetsanopoulos | def _ExtStorageStatus(status, diagnose): |
91 | b954f097 | Constantinos Venetsanopoulos | """Beautifier function for ExtStorage status.
|
92 | b954f097 | Constantinos Venetsanopoulos |
|
93 | b954f097 | Constantinos Venetsanopoulos | @type status: boolean
|
94 | b954f097 | Constantinos Venetsanopoulos | @param status: is the ExtStorage provider valid
|
95 | b954f097 | Constantinos Venetsanopoulos | @type diagnose: string
|
96 | b954f097 | Constantinos Venetsanopoulos | @param diagnose: the error message for invalid ExtStorages
|
97 | b954f097 | Constantinos Venetsanopoulos | @rtype: string
|
98 | b954f097 | Constantinos Venetsanopoulos | @return: a formatted status
|
99 | b954f097 | Constantinos Venetsanopoulos |
|
100 | b954f097 | Constantinos Venetsanopoulos | """
|
101 | b954f097 | Constantinos Venetsanopoulos | if status:
|
102 | b954f097 | Constantinos Venetsanopoulos | return "valid" |
103 | b954f097 | Constantinos Venetsanopoulos | else:
|
104 | b954f097 | Constantinos Venetsanopoulos | return "invalid - %s" % diagnose |
105 | b954f097 | Constantinos Venetsanopoulos | |
106 | b954f097 | Constantinos Venetsanopoulos | |
107 | b954f097 | Constantinos Venetsanopoulos | def DiagnoseExtStorage(opts, args): |
108 | b954f097 | Constantinos Venetsanopoulos | """Analyse all ExtStorage providers.
|
109 | b954f097 | Constantinos Venetsanopoulos |
|
110 | b954f097 | Constantinos Venetsanopoulos | @param opts: the command line options selected by the user
|
111 | b954f097 | Constantinos Venetsanopoulos | @type args: list
|
112 | b954f097 | Constantinos Venetsanopoulos | @param args: should be an empty list
|
113 | b954f097 | Constantinos Venetsanopoulos | @rtype: int
|
114 | b954f097 | Constantinos Venetsanopoulos | @return: the desired exit code
|
115 | b954f097 | Constantinos Venetsanopoulos |
|
116 | b954f097 | Constantinos Venetsanopoulos | """
|
117 | b954f097 | Constantinos Venetsanopoulos | op = opcodes.OpExtStorageDiagnose(output_fields=["name", "node_status", |
118 | b954f097 | Constantinos Venetsanopoulos | "nodegroup_status"],
|
119 | b954f097 | Constantinos Venetsanopoulos | names=[]) |
120 | b954f097 | Constantinos Venetsanopoulos | |
121 | b954f097 | Constantinos Venetsanopoulos | result = SubmitOpCode(op, opts=opts) |
122 | b954f097 | Constantinos Venetsanopoulos | |
123 | b954f097 | Constantinos Venetsanopoulos | if not result: |
124 | b954f097 | Constantinos Venetsanopoulos | ToStderr("Can't get the list of ExtStorage providers")
|
125 | b954f097 | Constantinos Venetsanopoulos | return 1 |
126 | b954f097 | Constantinos Venetsanopoulos | |
127 | b954f097 | Constantinos Venetsanopoulos | for provider_name, node_data, nodegroup_data in result: |
128 | b954f097 | Constantinos Venetsanopoulos | |
129 | b954f097 | Constantinos Venetsanopoulos | nodes_valid = {} |
130 | b954f097 | Constantinos Venetsanopoulos | nodes_bad = {} |
131 | b954f097 | Constantinos Venetsanopoulos | nodegroups_valid = {} |
132 | b954f097 | Constantinos Venetsanopoulos | nodegroups_bad = {} |
133 | b954f097 | Constantinos Venetsanopoulos | |
134 | b954f097 | Constantinos Venetsanopoulos | # Per node diagnose
|
135 | b954f097 | Constantinos Venetsanopoulos | for node_name, node_info in node_data.iteritems(): |
136 | b954f097 | Constantinos Venetsanopoulos | if node_info: # at least one entry in the per-node list |
137 | b954f097 | Constantinos Venetsanopoulos | (fo_path, fo_status, fo_msg, fo_params) = node_info.pop(0)
|
138 | b954f097 | Constantinos Venetsanopoulos | fo_msg = "%s (path: %s)" % (_ExtStorageStatus(fo_status, fo_msg),
|
139 | b954f097 | Constantinos Venetsanopoulos | fo_path) |
140 | b954f097 | Constantinos Venetsanopoulos | if fo_params:
|
141 | b954f097 | Constantinos Venetsanopoulos | fo_msg += (" [parameters: %s]" %
|
142 | b954f097 | Constantinos Venetsanopoulos | utils.CommaJoin([v[0] for v in fo_params])) |
143 | b954f097 | Constantinos Venetsanopoulos | else:
|
144 | b954f097 | Constantinos Venetsanopoulos | fo_msg += " [no parameters]"
|
145 | b954f097 | Constantinos Venetsanopoulos | if fo_status:
|
146 | b954f097 | Constantinos Venetsanopoulos | nodes_valid[node_name] = fo_msg |
147 | b954f097 | Constantinos Venetsanopoulos | else:
|
148 | b954f097 | Constantinos Venetsanopoulos | nodes_bad[node_name] = fo_msg |
149 | b954f097 | Constantinos Venetsanopoulos | else:
|
150 | b954f097 | Constantinos Venetsanopoulos | nodes_bad[node_name] = "ExtStorage provider not found"
|
151 | b954f097 | Constantinos Venetsanopoulos | |
152 | b954f097 | Constantinos Venetsanopoulos | # Per nodegroup diagnose
|
153 | b954f097 | Constantinos Venetsanopoulos | for nodegroup_name, nodegroup_status in nodegroup_data.iteritems(): |
154 | b954f097 | Constantinos Venetsanopoulos | status = nodegroup_status |
155 | b954f097 | Constantinos Venetsanopoulos | if status:
|
156 | b954f097 | Constantinos Venetsanopoulos | nodegroups_valid[nodegroup_name] = "valid"
|
157 | b954f097 | Constantinos Venetsanopoulos | else:
|
158 | b954f097 | Constantinos Venetsanopoulos | nodegroups_bad[nodegroup_name] = "invalid"
|
159 | b954f097 | Constantinos Venetsanopoulos | |
160 | b954f097 | Constantinos Venetsanopoulos | def _OutputPerNodegroupStatus(msg_map): |
161 | b954f097 | Constantinos Venetsanopoulos | map_k = utils.NiceSort(msg_map.keys()) |
162 | b954f097 | Constantinos Venetsanopoulos | for nodegroup in map_k: |
163 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" For nodegroup: %s --> %s", nodegroup,
|
164 | b954f097 | Constantinos Venetsanopoulos | msg_map[nodegroup]) |
165 | b954f097 | Constantinos Venetsanopoulos | |
166 | b954f097 | Constantinos Venetsanopoulos | def _OutputPerNodeStatus(msg_map): |
167 | b954f097 | Constantinos Venetsanopoulos | map_k = utils.NiceSort(msg_map.keys()) |
168 | b954f097 | Constantinos Venetsanopoulos | for node_name in map_k: |
169 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" Node: %s, status: %s", node_name, msg_map[node_name])
|
170 | b954f097 | Constantinos Venetsanopoulos | |
171 | b954f097 | Constantinos Venetsanopoulos | # Print the output
|
172 | b954f097 | Constantinos Venetsanopoulos | st_msg = "Provider: %s" % provider_name
|
173 | b954f097 | Constantinos Venetsanopoulos | ToStdout(st_msg) |
174 | b954f097 | Constantinos Venetsanopoulos | ToStdout("---")
|
175 | b954f097 | Constantinos Venetsanopoulos | _OutputPerNodeStatus(nodes_valid) |
176 | b954f097 | Constantinos Venetsanopoulos | _OutputPerNodeStatus(nodes_bad) |
177 | b954f097 | Constantinos Venetsanopoulos | ToStdout(" --")
|
178 | b954f097 | Constantinos Venetsanopoulos | _OutputPerNodegroupStatus(nodegroups_valid) |
179 | b954f097 | Constantinos Venetsanopoulos | _OutputPerNodegroupStatus(nodegroups_bad) |
180 | b954f097 | Constantinos Venetsanopoulos | ToStdout("")
|
181 | b954f097 | Constantinos Venetsanopoulos | |
182 | b954f097 | Constantinos Venetsanopoulos | return 0 |
183 | b954f097 | Constantinos Venetsanopoulos | |
184 | b954f097 | Constantinos Venetsanopoulos | |
185 | b954f097 | Constantinos Venetsanopoulos | commands = { |
186 | b954f097 | Constantinos Venetsanopoulos | "diagnose": (
|
187 | b954f097 | Constantinos Venetsanopoulos | DiagnoseExtStorage, ARGS_NONE, [PRIORITY_OPT], |
188 | b954f097 | Constantinos Venetsanopoulos | "", "Diagnose all ExtStorage providers"), |
189 | b954f097 | Constantinos Venetsanopoulos | "info": (
|
190 | b954f097 | Constantinos Venetsanopoulos | ShowExtStorageInfo, [ArgOs()], [PRIORITY_OPT], |
191 | b954f097 | Constantinos Venetsanopoulos | "", "Show info about ExtStorage providers"), |
192 | b954f097 | Constantinos Venetsanopoulos | } |
193 | b954f097 | Constantinos Venetsanopoulos | |
194 | b954f097 | Constantinos Venetsanopoulos | |
195 | b954f097 | Constantinos Venetsanopoulos | def Main(): |
196 | b954f097 | Constantinos Venetsanopoulos | return GenericMain(commands) |