root / scripts / gnt-cluster @ 5d672980
History | View | Annotate | Download (15.4 kB)
1 | a8083063 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | a8083063 | Iustin Pop | # |
3 | a8083063 | Iustin Pop | |
4 | a8083063 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc. |
5 | a8083063 | Iustin Pop | # |
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify |
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by |
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or |
9 | a8083063 | Iustin Pop | # (at your option) any later version. |
10 | a8083063 | Iustin Pop | # |
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but |
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | a8083063 | Iustin Pop | # General Public License for more details. |
15 | a8083063 | Iustin Pop | # |
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License |
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software |
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | a8083063 | Iustin Pop | # 02110-1301, USA. |
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | import sys |
23 | a8083063 | Iustin Pop | from optparse import make_option |
24 | a8083063 | Iustin Pop | import pprint |
25 | b3989551 | Iustin Pop | import os.path |
26 | a8083063 | Iustin Pop | |
27 | a8083063 | Iustin Pop | from ganeti.cli import * |
28 | a8083063 | Iustin Pop | from ganeti import opcodes |
29 | c2a62a33 | Michael Hanselmann | from ganeti import constants |
30 | f4d4e184 | Iustin Pop | from ganeti import errors |
31 | b63ed789 | Iustin Pop | from ganeti import utils |
32 | a0c9f010 | Michael Hanselmann | from ganeti import bootstrap |
33 | b3989551 | Iustin Pop | from ganeti import ssh |
34 | b3989551 | Iustin Pop | from ganeti import ssconf |
35 | a8083063 | Iustin Pop | |
36 | a8083063 | Iustin Pop | |
37 | a8083063 | Iustin Pop | def InitCluster(opts, args): |
38 | a8083063 | Iustin Pop | """Initialize the cluster. |
39 | a8083063 | Iustin Pop | |
40 | a8083063 | Iustin Pop | Args: |
41 | a8083063 | Iustin Pop | opts - class with options as members |
42 | a8083063 | Iustin Pop | args - list of arguments, expected to be [clustername] |
43 | a8083063 | Iustin Pop | |
44 | a8083063 | Iustin Pop | """ |
45 | 90b6aa3a | Manuel Franceschini | if not opts.lvm_storage and opts.vg_name: |
46 | 90b6aa3a | Manuel Franceschini | print ("Options --no-lvm-storage and --vg-name conflict.") |
47 | 90b6aa3a | Manuel Franceschini | return 1 |
48 | 90b6aa3a | Manuel Franceschini | |
49 | 90b6aa3a | Manuel Franceschini | vg_name = opts.vg_name |
50 | 90b6aa3a | Manuel Franceschini | if opts.lvm_storage and not opts.vg_name: |
51 | 90b6aa3a | Manuel Franceschini | vg_name = constants.DEFAULT_VG |
52 | 90b6aa3a | Manuel Franceschini | |
53 | a0c9f010 | Michael Hanselmann | bootstrap.InitCluster(cluster_name=args[0], |
54 | a0c9f010 | Michael Hanselmann | secondary_ip=opts.secondary_ip, |
55 | a0c9f010 | Michael Hanselmann | hypervisor_type=opts.hypervisor_type, |
56 | a0c9f010 | Michael Hanselmann | vg_name=vg_name, |
57 | a0c9f010 | Michael Hanselmann | mac_prefix=opts.mac_prefix, |
58 | a0c9f010 | Michael Hanselmann | def_bridge=opts.def_bridge, |
59 | a0c9f010 | Michael Hanselmann | master_netdev=opts.master_netdev, |
60 | a0c9f010 | Michael Hanselmann | file_storage_dir=opts.file_storage_dir) |
61 | a8083063 | Iustin Pop | return 0 |
62 | a8083063 | Iustin Pop | |
63 | a8083063 | Iustin Pop | |
64 | a8083063 | Iustin Pop | def DestroyCluster(opts, args): |
65 | a8083063 | Iustin Pop | """Destroy the cluster. |
66 | a8083063 | Iustin Pop | |
67 | a8083063 | Iustin Pop | Args: |
68 | a8083063 | Iustin Pop | opts - class with options as members |
69 | 098c0958 | Michael Hanselmann | |
70 | a8083063 | Iustin Pop | """ |
71 | a8083063 | Iustin Pop | if not opts.yes_do_it: |
72 | a8083063 | Iustin Pop | print ("Destroying a cluster is irreversibly. If you really want destroy" |
73 | 79f7be7b | Iustin Pop | " this cluster, supply the --yes-do-it option.") |
74 | a8083063 | Iustin Pop | return 1 |
75 | a8083063 | Iustin Pop | |
76 | a8083063 | Iustin Pop | op = opcodes.OpDestroyCluster() |
77 | 140aa4a8 | Iustin Pop | master = SubmitOpCode(op) |
78 | 140aa4a8 | Iustin Pop | # if we reached this, the opcode didn't fail; we can proceed to |
79 | 140aa4a8 | Iustin Pop | # shutdown all the daemons |
80 | 140aa4a8 | Iustin Pop | bootstrap.FinalizeClusterDestroy(master) |
81 | a8083063 | Iustin Pop | return 0 |
82 | a8083063 | Iustin Pop | |
83 | a8083063 | Iustin Pop | |
84 | 07bd8a51 | Iustin Pop | def RenameCluster(opts, args): |
85 | 07bd8a51 | Iustin Pop | """Rename the cluster. |
86 | 07bd8a51 | Iustin Pop | |
87 | 07bd8a51 | Iustin Pop | Args: |
88 | 07bd8a51 | Iustin Pop | opts - class with options as members, we use force only |
89 | 07bd8a51 | Iustin Pop | args - list of arguments, expected to be [new_name] |
90 | 07bd8a51 | Iustin Pop | |
91 | 07bd8a51 | Iustin Pop | """ |
92 | 07bd8a51 | Iustin Pop | name = args[0] |
93 | 07bd8a51 | Iustin Pop | if not opts.force: |
94 | 07bd8a51 | Iustin Pop | usertext = ("This will rename the cluster to '%s'. If you are connected" |
95 | 07bd8a51 | Iustin Pop | " over the network to the cluster name, the operation is very" |
96 | 07bd8a51 | Iustin Pop | " dangerous as the IP address will be removed from the node" |
97 | 07bd8a51 | Iustin Pop | " and the change may not go through. Continue?") % name |
98 | 47988778 | Iustin Pop | if not AskUser(usertext): |
99 | 07bd8a51 | Iustin Pop | return 1 |
100 | 07bd8a51 | Iustin Pop | |
101 | 07bd8a51 | Iustin Pop | op = opcodes.OpRenameCluster(name=name) |
102 | 07bd8a51 | Iustin Pop | SubmitOpCode(op) |
103 | 07bd8a51 | Iustin Pop | return 0 |
104 | 07bd8a51 | Iustin Pop | |
105 | 07bd8a51 | Iustin Pop | |
106 | a8083063 | Iustin Pop | def ShowClusterVersion(opts, args): |
107 | a8083063 | Iustin Pop | """Write version of ganeti software to the standard output. |
108 | a8083063 | Iustin Pop | |
109 | a8083063 | Iustin Pop | Args: |
110 | a8083063 | Iustin Pop | opts - class with options as members |
111 | a8083063 | Iustin Pop | |
112 | a8083063 | Iustin Pop | """ |
113 | a8083063 | Iustin Pop | op = opcodes.OpQueryClusterInfo() |
114 | a8083063 | Iustin Pop | result = SubmitOpCode(op) |
115 | a8083063 | Iustin Pop | print ("Software version: %s" % result["software_version"]) |
116 | a8083063 | Iustin Pop | print ("Internode protocol: %s" % result["protocol_version"]) |
117 | a8083063 | Iustin Pop | print ("Configuration format: %s" % result["config_version"]) |
118 | a8083063 | Iustin Pop | print ("OS api version: %s" % result["os_api_version"]) |
119 | a8083063 | Iustin Pop | print ("Export interface: %s" % result["export_version"]) |
120 | a8083063 | Iustin Pop | return 0 |
121 | a8083063 | Iustin Pop | |
122 | a8083063 | Iustin Pop | |
123 | a8083063 | Iustin Pop | def ShowClusterMaster(opts, args): |
124 | a8083063 | Iustin Pop | """Write name of master node to the standard output. |
125 | a8083063 | Iustin Pop | |
126 | a8083063 | Iustin Pop | Args: |
127 | a8083063 | Iustin Pop | opts - class with options as members |
128 | a8083063 | Iustin Pop | |
129 | a8083063 | Iustin Pop | """ |
130 | e00ea635 | Michael Hanselmann | print GetClient().QueryConfigValues(["master_node"])[0] |
131 | a8083063 | Iustin Pop | return 0 |
132 | a8083063 | Iustin Pop | |
133 | a8083063 | Iustin Pop | |
134 | a8083063 | Iustin Pop | def ShowClusterConfig(opts, args): |
135 | a8083063 | Iustin Pop | """Shows cluster information. |
136 | a8083063 | Iustin Pop | |
137 | a8083063 | Iustin Pop | """ |
138 | a8083063 | Iustin Pop | op = opcodes.OpQueryClusterInfo() |
139 | a8083063 | Iustin Pop | result = SubmitOpCode(op) |
140 | a8083063 | Iustin Pop | |
141 | a8083063 | Iustin Pop | print ("Cluster name: %s" % result["name"]) |
142 | a8083063 | Iustin Pop | |
143 | a8083063 | Iustin Pop | print ("Master node: %s" % result["master"]) |
144 | a8083063 | Iustin Pop | |
145 | 59322403 | Iustin Pop | print ("Architecture (this node): %s (%s)" % |
146 | 59322403 | Iustin Pop | (result["architecture"][0], result["architecture"][1])) |
147 | a8083063 | Iustin Pop | |
148 | 8a12ce45 | Iustin Pop | print ("Cluster hypervisor: %s" % result["hypervisor_type"]) |
149 | 8a12ce45 | Iustin Pop | |
150 | a8083063 | Iustin Pop | return 0 |
151 | a8083063 | Iustin Pop | |
152 | a8083063 | Iustin Pop | |
153 | a8083063 | Iustin Pop | def ClusterCopyFile(opts, args): |
154 | a8083063 | Iustin Pop | """Copy a file from master to some nodes. |
155 | a8083063 | Iustin Pop | |
156 | a8083063 | Iustin Pop | Args: |
157 | a8083063 | Iustin Pop | opts - class with options as members |
158 | a8083063 | Iustin Pop | args - list containing a single element, the file name |
159 | a8083063 | Iustin Pop | Opts used: |
160 | a8083063 | Iustin Pop | nodes - list containing the name of target nodes; if empty, all nodes |
161 | a8083063 | Iustin Pop | |
162 | a8083063 | Iustin Pop | """ |
163 | b3989551 | Iustin Pop | filename = args[0] |
164 | b3989551 | Iustin Pop | if not os.path.exists(filename): |
165 | b3989551 | Iustin Pop | raise errors.OpPrereqError("No such filename '%s'" % filename) |
166 | b3989551 | Iustin Pop | |
167 | 56bece1f | Iustin Pop | cl = GetClient() |
168 | 56bece1f | Iustin Pop | |
169 | b3989551 | Iustin Pop | myname = utils.HostInfo().name |
170 | b3989551 | Iustin Pop | |
171 | 56bece1f | Iustin Pop | cluster_name = cl.QueryConfigValues(["cluster_name"])[0] |
172 | 56bece1f | Iustin Pop | |
173 | b3989551 | Iustin Pop | op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) |
174 | 56bece1f | Iustin Pop | results = [row[0] for row in SubmitOpCode(op, cl=cl) if row[0] != myname] |
175 | e00ea635 | Michael Hanselmann | |
176 | 56bece1f | Iustin Pop | srun = ssh.SshRunner(cluster_name=cluster_name) |
177 | b3989551 | Iustin Pop | for node in results: |
178 | b3989551 | Iustin Pop | if not srun.CopyFileToNode(node, filename): |
179 | b3989551 | Iustin Pop | print >> sys.stderr, ("Copy of file %s to node %s failed" % |
180 | b3989551 | Iustin Pop | (filename, node)) |
181 | b3989551 | Iustin Pop | |
182 | a8083063 | Iustin Pop | return 0 |
183 | a8083063 | Iustin Pop | |
184 | a8083063 | Iustin Pop | |
185 | a8083063 | Iustin Pop | def RunClusterCommand(opts, args): |
186 | a8083063 | Iustin Pop | """Run a command on some nodes. |
187 | a8083063 | Iustin Pop | |
188 | a8083063 | Iustin Pop | Args: |
189 | a8083063 | Iustin Pop | opts - class with options as members |
190 | a8083063 | Iustin Pop | args - the command list as a list |
191 | a8083063 | Iustin Pop | Opts used: |
192 | a8083063 | Iustin Pop | nodes: list containing the name of target nodes; if empty, all nodes |
193 | a8083063 | Iustin Pop | |
194 | a8083063 | Iustin Pop | """ |
195 | 56bece1f | Iustin Pop | cl = GetClient() |
196 | 7688d0d3 | Michael Hanselmann | |
197 | a8083063 | Iustin Pop | command = " ".join(args) |
198 | b3989551 | Iustin Pop | op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) |
199 | 56bece1f | Iustin Pop | nodes = [row[0] for row in SubmitOpCode(op, cl=cl)] |
200 | 56bece1f | Iustin Pop | |
201 | 56bece1f | Iustin Pop | cluster_name, master_node = cl.QueryConfigValues(["cluster_name", |
202 | 56bece1f | Iustin Pop | "master_node"]) |
203 | b3989551 | Iustin Pop | |
204 | 56bece1f | Iustin Pop | srun = ssh.SshRunner(cluster_name=cluster_name) |
205 | b3989551 | Iustin Pop | |
206 | 7688d0d3 | Michael Hanselmann | # Make sure master node is at list end |
207 | b3989551 | Iustin Pop | if master_node in nodes: |
208 | b3989551 | Iustin Pop | nodes.remove(master_node) |
209 | b3989551 | Iustin Pop | nodes.append(master_node) |
210 | b3989551 | Iustin Pop | |
211 | b3989551 | Iustin Pop | for name in nodes: |
212 | b3989551 | Iustin Pop | result = srun.Run(name, "root", command) |
213 | a8083063 | Iustin Pop | print ("------------------------------------------------") |
214 | b3989551 | Iustin Pop | print ("node: %s" % name) |
215 | b3989551 | Iustin Pop | print ("%s" % result.output) |
216 | b3989551 | Iustin Pop | print ("return code = %s" % result.exit_code) |
217 | b3989551 | Iustin Pop | |
218 | b3989551 | Iustin Pop | return 0 |
219 | a8083063 | Iustin Pop | |
220 | a8083063 | Iustin Pop | |
221 | a8083063 | Iustin Pop | def VerifyCluster(opts, args): |
222 | a8083063 | Iustin Pop | """Verify integrity of cluster, performing various test on nodes. |
223 | a8083063 | Iustin Pop | |
224 | a8083063 | Iustin Pop | Args: |
225 | a8083063 | Iustin Pop | opts - class with options as members |
226 | a8083063 | Iustin Pop | |
227 | a8083063 | Iustin Pop | """ |
228 | 8d59409f | Iustin Pop | skip_checks = [] |
229 | e54c4c5e | Guido Trotter | if opts.skip_nplusone_mem: |
230 | e54c4c5e | Guido Trotter | skip_checks.append(constants.VERIFY_NPLUSONE_MEM) |
231 | e54c4c5e | Guido Trotter | op = opcodes.OpVerifyCluster(skip_checks=skip_checks) |
232 | 34290825 | Michael Hanselmann | if SubmitOpCode(op): |
233 | 34290825 | Michael Hanselmann | return 0 |
234 | 34290825 | Michael Hanselmann | else: |
235 | 34290825 | Michael Hanselmann | return 1 |
236 | a8083063 | Iustin Pop | |
237 | a8083063 | Iustin Pop | |
238 | f4d4e184 | Iustin Pop | def VerifyDisks(opts, args): |
239 | f4d4e184 | Iustin Pop | """Verify integrity of cluster disks. |
240 | f4d4e184 | Iustin Pop | |
241 | f4d4e184 | Iustin Pop | Args: |
242 | f4d4e184 | Iustin Pop | opts - class with options as members |
243 | f4d4e184 | Iustin Pop | |
244 | f4d4e184 | Iustin Pop | """ |
245 | f4d4e184 | Iustin Pop | op = opcodes.OpVerifyDisks() |
246 | f4d4e184 | Iustin Pop | result = SubmitOpCode(op) |
247 | dcde0241 | Guido Trotter | if not isinstance(result, (list, tuple)) or len(result) != 4: |
248 | f4d4e184 | Iustin Pop | raise errors.ProgrammerError("Unknown result type for OpVerifyDisks") |
249 | f4d4e184 | Iustin Pop | |
250 | b63ed789 | Iustin Pop | nodes, nlvm, instances, missing = result |
251 | b63ed789 | Iustin Pop | |
252 | f4d4e184 | Iustin Pop | if nodes: |
253 | f4d4e184 | Iustin Pop | print "Nodes unreachable or with bad data:" |
254 | f4d4e184 | Iustin Pop | for name in nodes: |
255 | f4d4e184 | Iustin Pop | print "\t%s" % name |
256 | f4d4e184 | Iustin Pop | retcode = constants.EXIT_SUCCESS |
257 | b63ed789 | Iustin Pop | |
258 | b63ed789 | Iustin Pop | if nlvm: |
259 | b63ed789 | Iustin Pop | for node, text in nlvm.iteritems(): |
260 | b63ed789 | Iustin Pop | print ("Error on node %s: LVM error: %s" % |
261 | b63ed789 | Iustin Pop | (node, text[-400:].encode('string_escape'))) |
262 | b63ed789 | Iustin Pop | retcode |= 1 |
263 | b63ed789 | Iustin Pop | print "You need to fix these nodes first before fixing instances" |
264 | b63ed789 | Iustin Pop | |
265 | f4d4e184 | Iustin Pop | if instances: |
266 | f4d4e184 | Iustin Pop | for iname in instances: |
267 | b63ed789 | Iustin Pop | if iname in missing: |
268 | b63ed789 | Iustin Pop | continue |
269 | f4d4e184 | Iustin Pop | op = opcodes.OpActivateInstanceDisks(instance_name=iname) |
270 | f4d4e184 | Iustin Pop | try: |
271 | f4d4e184 | Iustin Pop | print "Activating disks for instance '%s'" % iname |
272 | f4d4e184 | Iustin Pop | SubmitOpCode(op) |
273 | f4d4e184 | Iustin Pop | except errors.GenericError, err: |
274 | f4d4e184 | Iustin Pop | nret, msg = FormatError(err) |
275 | f4d4e184 | Iustin Pop | retcode |= nret |
276 | b63ed789 | Iustin Pop | print >> sys.stderr, ("Error activating disks for instance %s: %s" % |
277 | b63ed789 | Iustin Pop | (iname, msg)) |
278 | b63ed789 | Iustin Pop | |
279 | b63ed789 | Iustin Pop | if missing: |
280 | b63ed789 | Iustin Pop | for iname, ival in missing.iteritems(): |
281 | b63ed789 | Iustin Pop | all_missing = utils.all(ival, lambda x: x[0] in nlvm) |
282 | b63ed789 | Iustin Pop | if all_missing: |
283 | b63ed789 | Iustin Pop | print ("Instance %s cannot be verified as it lives on" |
284 | b63ed789 | Iustin Pop | " broken nodes" % iname) |
285 | b63ed789 | Iustin Pop | else: |
286 | b63ed789 | Iustin Pop | print "Instance %s has missing logical volumes:" % iname |
287 | b63ed789 | Iustin Pop | ival.sort() |
288 | b63ed789 | Iustin Pop | for node, vol in ival: |
289 | b63ed789 | Iustin Pop | if node in nlvm: |
290 | b63ed789 | Iustin Pop | print ("\tbroken node %s /dev/xenvg/%s" % (node, vol)) |
291 | b63ed789 | Iustin Pop | else: |
292 | b63ed789 | Iustin Pop | print ("\t%s /dev/xenvg/%s" % (node, vol)) |
293 | b63ed789 | Iustin Pop | print ("You need to run replace_disks for all the above" |
294 | b63ed789 | Iustin Pop | " instances, if this message persist after fixing nodes.") |
295 | b63ed789 | Iustin Pop | retcode |= 1 |
296 | f4d4e184 | Iustin Pop | |
297 | f4d4e184 | Iustin Pop | return retcode |
298 | f4d4e184 | Iustin Pop | |
299 | f4d4e184 | Iustin Pop | |
300 | a8083063 | Iustin Pop | def MasterFailover(opts, args): |
301 | a8083063 | Iustin Pop | """Failover the master node. |
302 | a8083063 | Iustin Pop | |
303 | a8083063 | Iustin Pop | This command, when run on a non-master node, will cause the current |
304 | a8083063 | Iustin Pop | master to cease being master, and the non-master to become new |
305 | a8083063 | Iustin Pop | master. |
306 | a8083063 | Iustin Pop | |
307 | a8083063 | Iustin Pop | """ |
308 | b1b6ea87 | Iustin Pop | return bootstrap.MasterFailover() |
309 | a8083063 | Iustin Pop | |
310 | a8083063 | Iustin Pop | |
311 | 73415719 | Iustin Pop | def SearchTags(opts, args): |
312 | 73415719 | Iustin Pop | """Searches the tags on all the cluster. |
313 | 73415719 | Iustin Pop | |
314 | 73415719 | Iustin Pop | """ |
315 | 73415719 | Iustin Pop | op = opcodes.OpSearchTags(pattern=args[0]) |
316 | 73415719 | Iustin Pop | result = SubmitOpCode(op) |
317 | 73415719 | Iustin Pop | if not result: |
318 | 73415719 | Iustin Pop | return 1 |
319 | 73415719 | Iustin Pop | result = list(result) |
320 | 73415719 | Iustin Pop | result.sort() |
321 | 73415719 | Iustin Pop | for path, tag in result: |
322 | 73415719 | Iustin Pop | print "%s %s" % (path, tag) |
323 | 73415719 | Iustin Pop | |
324 | 73415719 | Iustin Pop | |
325 | 90b6aa3a | Manuel Franceschini | def SetClusterParams(opts, args): |
326 | 90b6aa3a | Manuel Franceschini | """Modify the cluster. |
327 | 90b6aa3a | Manuel Franceschini | |
328 | 90b6aa3a | Manuel Franceschini | Args: |
329 | 90b6aa3a | Manuel Franceschini | opts - class with options as members |
330 | 90b6aa3a | Manuel Franceschini | |
331 | 90b6aa3a | Manuel Franceschini | """ |
332 | 90b6aa3a | Manuel Franceschini | if not (not opts.lvm_storage or opts.vg_name): |
333 | 90b6aa3a | Manuel Franceschini | print "Please give at least one of the parameters." |
334 | 90b6aa3a | Manuel Franceschini | return 1 |
335 | 90b6aa3a | Manuel Franceschini | |
336 | 90b6aa3a | Manuel Franceschini | vg_name = opts.vg_name |
337 | 90b6aa3a | Manuel Franceschini | if not opts.lvm_storage and opts.vg_name: |
338 | 90b6aa3a | Manuel Franceschini | print ("Options --no-lvm-storage and --vg-name conflict.") |
339 | 90b6aa3a | Manuel Franceschini | return 1 |
340 | 90b6aa3a | Manuel Franceschini | |
341 | 90b6aa3a | Manuel Franceschini | op = opcodes.OpSetClusterParams(vg_name=opts.vg_name) |
342 | 90b6aa3a | Manuel Franceschini | SubmitOpCode(op) |
343 | 90b6aa3a | Manuel Franceschini | return 0 |
344 | 90b6aa3a | Manuel Franceschini | |
345 | 90b6aa3a | Manuel Franceschini | |
346 | a8083063 | Iustin Pop | # this is an option common to more than one command, so we declare |
347 | a8083063 | Iustin Pop | # it here and reuse it |
348 | a8083063 | Iustin Pop | node_option = make_option("-n", "--node", action="append", dest="nodes", |
349 | f4bc1f2c | Michael Hanselmann | help="Node to copy to (if not given, all nodes)," |
350 | f4bc1f2c | Michael Hanselmann | " can be given multiple times", |
351 | f4bc1f2c | Michael Hanselmann | metavar="<node>", default=[]) |
352 | a8083063 | Iustin Pop | |
353 | a8083063 | Iustin Pop | commands = { |
354 | a8083063 | Iustin Pop | 'init': (InitCluster, ARGS_ONE, |
355 | a8083063 | Iustin Pop | [DEBUG_OPT, |
356 | a8083063 | Iustin Pop | make_option("-s", "--secondary-ip", dest="secondary_ip", |
357 | a8083063 | Iustin Pop | help="Specify the secondary ip for this node;" |
358 | a8083063 | Iustin Pop | " if given, the entire cluster must have secondary" |
359 | a8083063 | Iustin Pop | " addresses", |
360 | a8083063 | Iustin Pop | metavar="ADDRESS", default=None), |
361 | a8083063 | Iustin Pop | make_option("-t", "--hypervisor-type", dest="hypervisor_type", |
362 | 2a6469d5 | Alexander Schreiber | help="Specify the hypervisor type " |
363 | e49099a4 | Alexander Schreiber | "(xen-pvm, kvm, fake, xen-hvm)", |
364 | e49099a4 | Alexander Schreiber | metavar="TYPE", choices=["xen-pvm", |
365 | 7a151789 | Guido Trotter | "kvm", |
366 | 2a6469d5 | Alexander Schreiber | "fake", |
367 | e49099a4 | Alexander Schreiber | "xen-hvm"], |
368 | e49099a4 | Alexander Schreiber | default="xen-pvm",), |
369 | a8083063 | Iustin Pop | make_option("-m", "--mac-prefix", dest="mac_prefix", |
370 | a8083063 | Iustin Pop | help="Specify the mac prefix for the instance IP" |
371 | a8083063 | Iustin Pop | " addresses, in the format XX:XX:XX", |
372 | a8083063 | Iustin Pop | metavar="PREFIX", |
373 | a8083063 | Iustin Pop | default="aa:00:00",), |
374 | a8083063 | Iustin Pop | make_option("-g", "--vg-name", dest="vg_name", |
375 | a8083063 | Iustin Pop | help="Specify the volume group name " |
376 | a8083063 | Iustin Pop | " (cluster-wide) for disk allocation [xenvg]", |
377 | a8083063 | Iustin Pop | metavar="VG", |
378 | 90b6aa3a | Manuel Franceschini | default=None,), |
379 | a8083063 | Iustin Pop | make_option("-b", "--bridge", dest="def_bridge", |
380 | a8083063 | Iustin Pop | help="Specify the default bridge name (cluster-wide)" |
381 | cf62a272 | Michael Hanselmann | " to connect the instances to [%s]" % |
382 | cf62a272 | Michael Hanselmann | constants.DEFAULT_BRIDGE, |
383 | a8083063 | Iustin Pop | metavar="BRIDGE", |
384 | cf62a272 | Michael Hanselmann | default=constants.DEFAULT_BRIDGE,), |
385 | 880478f8 | Iustin Pop | make_option("--master-netdev", dest="master_netdev", |
386 | 880478f8 | Iustin Pop | help="Specify the node interface (cluster-wide)" |
387 | cf62a272 | Michael Hanselmann | " on which the master IP address will be added " |
388 | cf62a272 | Michael Hanselmann | " [%s]" % constants.DEFAULT_BRIDGE, |
389 | 880478f8 | Iustin Pop | metavar="NETDEV", |
390 | cf62a272 | Michael Hanselmann | default=constants.DEFAULT_BRIDGE,), |
391 | 79e82404 | Manuel Franceschini | make_option("--file-storage-dir", dest="file_storage_dir", |
392 | 79e82404 | Manuel Franceschini | help="Specify the default directory (cluster-wide)" |
393 | 79e82404 | Manuel Franceschini | " for storing the file-based disks [%s]" % |
394 | 79e82404 | Manuel Franceschini | constants.DEFAULT_FILE_STORAGE_DIR, |
395 | 79e82404 | Manuel Franceschini | metavar="DIR", |
396 | 79e82404 | Manuel Franceschini | default=constants.DEFAULT_FILE_STORAGE_DIR,), |
397 | 90b6aa3a | Manuel Franceschini | make_option("--no-lvm-storage", dest="lvm_storage", |
398 | 90b6aa3a | Manuel Franceschini | help="No support for lvm based instances" |
399 | 90b6aa3a | Manuel Franceschini | " (cluster-wide)", |
400 | 90b6aa3a | Manuel Franceschini | action="store_false", default=True,), |
401 | a8083063 | Iustin Pop | ], |
402 | 9a033156 | Iustin Pop | "[opts...] <cluster_name>", |
403 | a8083063 | Iustin Pop | "Initialises a new cluster configuration"), |
404 | a8083063 | Iustin Pop | 'destroy': (DestroyCluster, ARGS_NONE, |
405 | a8083063 | Iustin Pop | [DEBUG_OPT, |
406 | a8083063 | Iustin Pop | make_option("--yes-do-it", dest="yes_do_it", |
407 | a8083063 | Iustin Pop | help="Destroy cluster", |
408 | a8083063 | Iustin Pop | action="store_true"), |
409 | a8083063 | Iustin Pop | ], |
410 | 9a033156 | Iustin Pop | "", "Destroy cluster"), |
411 | 07bd8a51 | Iustin Pop | 'rename': (RenameCluster, ARGS_ONE, [DEBUG_OPT, FORCE_OPT], |
412 | 9a033156 | Iustin Pop | "<new_name>", |
413 | 07bd8a51 | Iustin Pop | "Renames the cluster"), |
414 | e54c4c5e | Guido Trotter | 'verify': (VerifyCluster, ARGS_NONE, [DEBUG_OPT, |
415 | e54c4c5e | Guido Trotter | make_option("--no-nplus1-mem", dest="skip_nplusone_mem", |
416 | e54c4c5e | Guido Trotter | help="Skip N+1 memory redundancy tests", |
417 | e54c4c5e | Guido Trotter | action="store_true", |
418 | e54c4c5e | Guido Trotter | default=False,), |
419 | e54c4c5e | Guido Trotter | ], |
420 | 9a033156 | Iustin Pop | "", "Does a check on the cluster configuration"), |
421 | f4d4e184 | Iustin Pop | 'verify-disks': (VerifyDisks, ARGS_NONE, [DEBUG_OPT], |
422 | 9a033156 | Iustin Pop | "", "Does a check on the cluster disk status"), |
423 | a8083063 | Iustin Pop | 'masterfailover': (MasterFailover, ARGS_NONE, [DEBUG_OPT], |
424 | 9a033156 | Iustin Pop | "", "Makes the current node the master"), |
425 | a8083063 | Iustin Pop | 'version': (ShowClusterVersion, ARGS_NONE, [DEBUG_OPT], |
426 | 9a033156 | Iustin Pop | "", "Shows the cluster version"), |
427 | a8083063 | Iustin Pop | 'getmaster': (ShowClusterMaster, ARGS_NONE, [DEBUG_OPT], |
428 | 9a033156 | Iustin Pop | "", "Shows the cluster master"), |
429 | a8083063 | Iustin Pop | 'copyfile': (ClusterCopyFile, ARGS_ONE, [DEBUG_OPT, node_option], |
430 | 9a033156 | Iustin Pop | "[-n node...] <filename>", |
431 | a8083063 | Iustin Pop | "Copies a file to all (or only some) nodes"), |
432 | a8083063 | Iustin Pop | 'command': (RunClusterCommand, ARGS_ATLEAST(1), [DEBUG_OPT, node_option], |
433 | 9a033156 | Iustin Pop | "[-n node...] <command>", |
434 | a8083063 | Iustin Pop | "Runs a command on all (or only some) nodes"), |
435 | a8083063 | Iustin Pop | 'info': (ShowClusterConfig, ARGS_NONE, [DEBUG_OPT], |
436 | 9a033156 | Iustin Pop | "", "Show cluster configuration"), |
437 | 846baef9 | Iustin Pop | 'list-tags': (ListTags, ARGS_NONE, |
438 | 9a033156 | Iustin Pop | [DEBUG_OPT], "", "List the tags of the cluster"), |
439 | 810c50b7 | Iustin Pop | 'add-tags': (AddTags, ARGS_ANY, [DEBUG_OPT, TAG_SRC_OPT], |
440 | 9a033156 | Iustin Pop | "tag...", "Add tags to the cluster"), |
441 | 810c50b7 | Iustin Pop | 'remove-tags': (RemoveTags, ARGS_ANY, [DEBUG_OPT, TAG_SRC_OPT], |
442 | 9a033156 | Iustin Pop | "tag...", "Remove tags from the cluster"), |
443 | 73415719 | Iustin Pop | 'search-tags': (SearchTags, ARGS_ONE, |
444 | 9a033156 | Iustin Pop | [DEBUG_OPT], "", "Searches the tags on all objects on" |
445 | 73415719 | Iustin Pop | " the cluster for a given pattern (regex)"), |
446 | 90b6aa3a | Manuel Franceschini | 'modify': (SetClusterParams, ARGS_NONE, |
447 | 90b6aa3a | Manuel Franceschini | [DEBUG_OPT, |
448 | 90b6aa3a | Manuel Franceschini | make_option("-g", "--vg-name", dest="vg_name", |
449 | 90b6aa3a | Manuel Franceschini | help="Specify the volume group name " |
450 | 90b6aa3a | Manuel Franceschini | " (cluster-wide) for disk allocation " |
451 | 90b6aa3a | Manuel Franceschini | "and enable lvm based storage", |
452 | 90b6aa3a | Manuel Franceschini | metavar="VG",), |
453 | 90b6aa3a | Manuel Franceschini | make_option("--no-lvm-storage", dest="lvm_storage", |
454 | 90b6aa3a | Manuel Franceschini | help="Disable support for lvm based instances" |
455 | 90b6aa3a | Manuel Franceschini | " (cluster-wide)", |
456 | 90b6aa3a | Manuel Franceschini | action="store_false", default=True,), |
457 | 90b6aa3a | Manuel Franceschini | ], |
458 | 90b6aa3a | Manuel Franceschini | "[opts...]", |
459 | 90b6aa3a | Manuel Franceschini | "Alters the parameters of the cluster"), |
460 | a8083063 | Iustin Pop | } |
461 | a8083063 | Iustin Pop | |
462 | a8083063 | Iustin Pop | if __name__ == '__main__': |
463 | 846baef9 | Iustin Pop | sys.exit(GenericMain(commands, override={"tag_type": constants.TAG_CLUSTER})) |