root / scripts / gnt-cluster @ 207a6c74
History | View | Annotate | Download (15.1 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 | ce7151ae | Iustin Pop | sstore = ssconf.SimpleStore() |
131 | ce7151ae | Iustin Pop | print sstore.GetMasterNode() |
132 | a8083063 | Iustin Pop | return 0 |
133 | a8083063 | Iustin Pop | |
134 | a8083063 | Iustin Pop | |
135 | a8083063 | Iustin Pop | def ShowClusterConfig(opts, args): |
136 | a8083063 | Iustin Pop | """Shows cluster information. |
137 | a8083063 | Iustin Pop | |
138 | a8083063 | Iustin Pop | """ |
139 | a8083063 | Iustin Pop | op = opcodes.OpQueryClusterInfo() |
140 | a8083063 | Iustin Pop | result = SubmitOpCode(op) |
141 | a8083063 | Iustin Pop | |
142 | a8083063 | Iustin Pop | print ("Cluster name: %s" % result["name"]) |
143 | a8083063 | Iustin Pop | |
144 | a8083063 | Iustin Pop | print ("Master node: %s" % result["master"]) |
145 | a8083063 | Iustin Pop | |
146 | 59322403 | Iustin Pop | print ("Architecture (this node): %s (%s)" % |
147 | 59322403 | Iustin Pop | (result["architecture"][0], result["architecture"][1])) |
148 | a8083063 | Iustin Pop | |
149 | 8a12ce45 | Iustin Pop | print ("Cluster hypervisor: %s" % result["hypervisor_type"]) |
150 | 8a12ce45 | Iustin Pop | |
151 | a8083063 | Iustin Pop | return 0 |
152 | a8083063 | Iustin Pop | |
153 | a8083063 | Iustin Pop | |
154 | a8083063 | Iustin Pop | def ClusterCopyFile(opts, args): |
155 | a8083063 | Iustin Pop | """Copy a file from master to some nodes. |
156 | a8083063 | Iustin Pop | |
157 | a8083063 | Iustin Pop | Args: |
158 | a8083063 | Iustin Pop | opts - class with options as members |
159 | a8083063 | Iustin Pop | args - list containing a single element, the file name |
160 | a8083063 | Iustin Pop | Opts used: |
161 | a8083063 | Iustin Pop | nodes - list containing the name of target nodes; if empty, all nodes |
162 | a8083063 | Iustin Pop | |
163 | a8083063 | Iustin Pop | """ |
164 | b3989551 | Iustin Pop | filename = args[0] |
165 | b3989551 | Iustin Pop | if not os.path.exists(filename): |
166 | b3989551 | Iustin Pop | raise errors.OpPrereqError("No such filename '%s'" % filename) |
167 | b3989551 | Iustin Pop | |
168 | b3989551 | Iustin Pop | myname = utils.HostInfo().name |
169 | b3989551 | Iustin Pop | |
170 | b3989551 | Iustin Pop | op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) |
171 | b3989551 | Iustin Pop | results = [row[0] for row in SubmitOpCode(op) if row[0] != myname] |
172 | b3989551 | Iustin Pop | srun = ssh.SshRunner() |
173 | b3989551 | Iustin Pop | for node in results: |
174 | b3989551 | Iustin Pop | if not srun.CopyFileToNode(node, filename): |
175 | b3989551 | Iustin Pop | print >> sys.stderr, ("Copy of file %s to node %s failed" % |
176 | b3989551 | Iustin Pop | (filename, node)) |
177 | b3989551 | Iustin Pop | |
178 | a8083063 | Iustin Pop | return 0 |
179 | a8083063 | Iustin Pop | |
180 | a8083063 | Iustin Pop | |
181 | a8083063 | Iustin Pop | def RunClusterCommand(opts, args): |
182 | a8083063 | Iustin Pop | """Run a command on some nodes. |
183 | a8083063 | Iustin Pop | |
184 | a8083063 | Iustin Pop | Args: |
185 | a8083063 | Iustin Pop | opts - class with options as members |
186 | a8083063 | Iustin Pop | args - the command list as a list |
187 | a8083063 | Iustin Pop | Opts used: |
188 | a8083063 | Iustin Pop | nodes: list containing the name of target nodes; if empty, all nodes |
189 | a8083063 | Iustin Pop | |
190 | a8083063 | Iustin Pop | """ |
191 | a8083063 | Iustin Pop | command = " ".join(args) |
192 | b3989551 | Iustin Pop | op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) |
193 | b3989551 | Iustin Pop | nodes = [row[0] for row in SubmitOpCode(op)] |
194 | b3989551 | Iustin Pop | |
195 | b3989551 | Iustin Pop | sstore = ssconf.SimpleStore() |
196 | b3989551 | Iustin Pop | master_node = sstore.GetMasterNode() |
197 | b3989551 | Iustin Pop | srun = ssh.SshRunner(sstore=sstore) |
198 | b3989551 | Iustin Pop | |
199 | b3989551 | Iustin Pop | if master_node in nodes: |
200 | b3989551 | Iustin Pop | nodes.remove(master_node) |
201 | b3989551 | Iustin Pop | nodes.append(master_node) |
202 | b3989551 | Iustin Pop | |
203 | b3989551 | Iustin Pop | for name in nodes: |
204 | b3989551 | Iustin Pop | result = srun.Run(name, "root", command) |
205 | a8083063 | Iustin Pop | print ("------------------------------------------------") |
206 | b3989551 | Iustin Pop | print ("node: %s" % name) |
207 | b3989551 | Iustin Pop | print ("%s" % result.output) |
208 | b3989551 | Iustin Pop | print ("return code = %s" % result.exit_code) |
209 | b3989551 | Iustin Pop | |
210 | b3989551 | Iustin Pop | return 0 |
211 | a8083063 | Iustin Pop | |
212 | a8083063 | Iustin Pop | |
213 | a8083063 | Iustin Pop | def VerifyCluster(opts, args): |
214 | a8083063 | Iustin Pop | """Verify integrity of cluster, performing various test on nodes. |
215 | a8083063 | Iustin Pop | |
216 | a8083063 | Iustin Pop | Args: |
217 | a8083063 | Iustin Pop | opts - class with options as members |
218 | a8083063 | Iustin Pop | |
219 | a8083063 | Iustin Pop | """ |
220 | 8d59409f | Iustin Pop | skip_checks = [] |
221 | e54c4c5e | Guido Trotter | if opts.skip_nplusone_mem: |
222 | e54c4c5e | Guido Trotter | skip_checks.append(constants.VERIFY_NPLUSONE_MEM) |
223 | e54c4c5e | Guido Trotter | op = opcodes.OpVerifyCluster(skip_checks=skip_checks) |
224 | 34290825 | Michael Hanselmann | if SubmitOpCode(op): |
225 | 34290825 | Michael Hanselmann | return 0 |
226 | 34290825 | Michael Hanselmann | else: |
227 | 34290825 | Michael Hanselmann | return 1 |
228 | a8083063 | Iustin Pop | |
229 | a8083063 | Iustin Pop | |
230 | f4d4e184 | Iustin Pop | def VerifyDisks(opts, args): |
231 | f4d4e184 | Iustin Pop | """Verify integrity of cluster disks. |
232 | f4d4e184 | Iustin Pop | |
233 | f4d4e184 | Iustin Pop | Args: |
234 | f4d4e184 | Iustin Pop | opts - class with options as members |
235 | f4d4e184 | Iustin Pop | |
236 | f4d4e184 | Iustin Pop | """ |
237 | f4d4e184 | Iustin Pop | op = opcodes.OpVerifyDisks() |
238 | f4d4e184 | Iustin Pop | result = SubmitOpCode(op) |
239 | dcde0241 | Guido Trotter | if not isinstance(result, (list, tuple)) or len(result) != 4: |
240 | f4d4e184 | Iustin Pop | raise errors.ProgrammerError("Unknown result type for OpVerifyDisks") |
241 | f4d4e184 | Iustin Pop | |
242 | b63ed789 | Iustin Pop | nodes, nlvm, instances, missing = result |
243 | b63ed789 | Iustin Pop | |
244 | f4d4e184 | Iustin Pop | if nodes: |
245 | f4d4e184 | Iustin Pop | print "Nodes unreachable or with bad data:" |
246 | f4d4e184 | Iustin Pop | for name in nodes: |
247 | f4d4e184 | Iustin Pop | print "\t%s" % name |
248 | f4d4e184 | Iustin Pop | retcode = constants.EXIT_SUCCESS |
249 | b63ed789 | Iustin Pop | |
250 | b63ed789 | Iustin Pop | if nlvm: |
251 | b63ed789 | Iustin Pop | for node, text in nlvm.iteritems(): |
252 | b63ed789 | Iustin Pop | print ("Error on node %s: LVM error: %s" % |
253 | b63ed789 | Iustin Pop | (node, text[-400:].encode('string_escape'))) |
254 | b63ed789 | Iustin Pop | retcode |= 1 |
255 | b63ed789 | Iustin Pop | print "You need to fix these nodes first before fixing instances" |
256 | b63ed789 | Iustin Pop | |
257 | f4d4e184 | Iustin Pop | if instances: |
258 | f4d4e184 | Iustin Pop | for iname in instances: |
259 | b63ed789 | Iustin Pop | if iname in missing: |
260 | b63ed789 | Iustin Pop | continue |
261 | f4d4e184 | Iustin Pop | op = opcodes.OpActivateInstanceDisks(instance_name=iname) |
262 | f4d4e184 | Iustin Pop | try: |
263 | f4d4e184 | Iustin Pop | print "Activating disks for instance '%s'" % iname |
264 | f4d4e184 | Iustin Pop | SubmitOpCode(op) |
265 | f4d4e184 | Iustin Pop | except errors.GenericError, err: |
266 | f4d4e184 | Iustin Pop | nret, msg = FormatError(err) |
267 | f4d4e184 | Iustin Pop | retcode |= nret |
268 | b63ed789 | Iustin Pop | print >> sys.stderr, ("Error activating disks for instance %s: %s" % |
269 | b63ed789 | Iustin Pop | (iname, msg)) |
270 | b63ed789 | Iustin Pop | |
271 | b63ed789 | Iustin Pop | if missing: |
272 | b63ed789 | Iustin Pop | for iname, ival in missing.iteritems(): |
273 | b63ed789 | Iustin Pop | all_missing = utils.all(ival, lambda x: x[0] in nlvm) |
274 | b63ed789 | Iustin Pop | if all_missing: |
275 | b63ed789 | Iustin Pop | print ("Instance %s cannot be verified as it lives on" |
276 | b63ed789 | Iustin Pop | " broken nodes" % iname) |
277 | b63ed789 | Iustin Pop | else: |
278 | b63ed789 | Iustin Pop | print "Instance %s has missing logical volumes:" % iname |
279 | b63ed789 | Iustin Pop | ival.sort() |
280 | b63ed789 | Iustin Pop | for node, vol in ival: |
281 | b63ed789 | Iustin Pop | if node in nlvm: |
282 | b63ed789 | Iustin Pop | print ("\tbroken node %s /dev/xenvg/%s" % (node, vol)) |
283 | b63ed789 | Iustin Pop | else: |
284 | b63ed789 | Iustin Pop | print ("\t%s /dev/xenvg/%s" % (node, vol)) |
285 | b63ed789 | Iustin Pop | print ("You need to run replace_disks for all the above" |
286 | b63ed789 | Iustin Pop | " instances, if this message persist after fixing nodes.") |
287 | b63ed789 | Iustin Pop | retcode |= 1 |
288 | f4d4e184 | Iustin Pop | |
289 | f4d4e184 | Iustin Pop | return retcode |
290 | f4d4e184 | Iustin Pop | |
291 | f4d4e184 | Iustin Pop | |
292 | a8083063 | Iustin Pop | def MasterFailover(opts, args): |
293 | a8083063 | Iustin Pop | """Failover the master node. |
294 | a8083063 | Iustin Pop | |
295 | a8083063 | Iustin Pop | This command, when run on a non-master node, will cause the current |
296 | a8083063 | Iustin Pop | master to cease being master, and the non-master to become new |
297 | a8083063 | Iustin Pop | master. |
298 | a8083063 | Iustin Pop | |
299 | a8083063 | Iustin Pop | """ |
300 | b1b6ea87 | Iustin Pop | return bootstrap.MasterFailover() |
301 | a8083063 | Iustin Pop | |
302 | a8083063 | Iustin Pop | |
303 | 73415719 | Iustin Pop | def SearchTags(opts, args): |
304 | 73415719 | Iustin Pop | """Searches the tags on all the cluster. |
305 | 73415719 | Iustin Pop | |
306 | 73415719 | Iustin Pop | """ |
307 | 73415719 | Iustin Pop | op = opcodes.OpSearchTags(pattern=args[0]) |
308 | 73415719 | Iustin Pop | result = SubmitOpCode(op) |
309 | 73415719 | Iustin Pop | if not result: |
310 | 73415719 | Iustin Pop | return 1 |
311 | 73415719 | Iustin Pop | result = list(result) |
312 | 73415719 | Iustin Pop | result.sort() |
313 | 73415719 | Iustin Pop | for path, tag in result: |
314 | 73415719 | Iustin Pop | print "%s %s" % (path, tag) |
315 | 73415719 | Iustin Pop | |
316 | 73415719 | Iustin Pop | |
317 | 90b6aa3a | Manuel Franceschini | def SetClusterParams(opts, args): |
318 | 90b6aa3a | Manuel Franceschini | """Modify the cluster. |
319 | 90b6aa3a | Manuel Franceschini | |
320 | 90b6aa3a | Manuel Franceschini | Args: |
321 | 90b6aa3a | Manuel Franceschini | opts - class with options as members |
322 | 90b6aa3a | Manuel Franceschini | |
323 | 90b6aa3a | Manuel Franceschini | """ |
324 | 90b6aa3a | Manuel Franceschini | if not (not opts.lvm_storage or opts.vg_name): |
325 | 90b6aa3a | Manuel Franceschini | print "Please give at least one of the parameters." |
326 | 90b6aa3a | Manuel Franceschini | return 1 |
327 | 90b6aa3a | Manuel Franceschini | |
328 | 90b6aa3a | Manuel Franceschini | vg_name = opts.vg_name |
329 | 90b6aa3a | Manuel Franceschini | if not opts.lvm_storage and opts.vg_name: |
330 | 90b6aa3a | Manuel Franceschini | print ("Options --no-lvm-storage and --vg-name conflict.") |
331 | 90b6aa3a | Manuel Franceschini | return 1 |
332 | 90b6aa3a | Manuel Franceschini | |
333 | 90b6aa3a | Manuel Franceschini | op = opcodes.OpSetClusterParams(vg_name=opts.vg_name) |
334 | 90b6aa3a | Manuel Franceschini | SubmitOpCode(op) |
335 | 90b6aa3a | Manuel Franceschini | return 0 |
336 | 90b6aa3a | Manuel Franceschini | |
337 | 90b6aa3a | Manuel Franceschini | |
338 | a8083063 | Iustin Pop | # this is an option common to more than one command, so we declare |
339 | a8083063 | Iustin Pop | # it here and reuse it |
340 | a8083063 | Iustin Pop | node_option = make_option("-n", "--node", action="append", dest="nodes", |
341 | f4bc1f2c | Michael Hanselmann | help="Node to copy to (if not given, all nodes)," |
342 | f4bc1f2c | Michael Hanselmann | " can be given multiple times", |
343 | f4bc1f2c | Michael Hanselmann | metavar="<node>", default=[]) |
344 | a8083063 | Iustin Pop | |
345 | a8083063 | Iustin Pop | commands = { |
346 | a8083063 | Iustin Pop | 'init': (InitCluster, ARGS_ONE, |
347 | a8083063 | Iustin Pop | [DEBUG_OPT, |
348 | a8083063 | Iustin Pop | make_option("-s", "--secondary-ip", dest="secondary_ip", |
349 | a8083063 | Iustin Pop | help="Specify the secondary ip for this node;" |
350 | a8083063 | Iustin Pop | " if given, the entire cluster must have secondary" |
351 | a8083063 | Iustin Pop | " addresses", |
352 | a8083063 | Iustin Pop | metavar="ADDRESS", default=None), |
353 | a8083063 | Iustin Pop | make_option("-t", "--hypervisor-type", dest="hypervisor_type", |
354 | 2a6469d5 | Alexander Schreiber | help="Specify the hypervisor type " |
355 | 7a151789 | Guido Trotter | "(xen-3.0, kvm, fake, xen-hvm-3.1)", |
356 | 2a6469d5 | Alexander Schreiber | metavar="TYPE", choices=["xen-3.0", |
357 | 7a151789 | Guido Trotter | "kvm", |
358 | 2a6469d5 | Alexander Schreiber | "fake", |
359 | 2a6469d5 | Alexander Schreiber | "xen-hvm-3.1"], |
360 | a8083063 | Iustin Pop | default="xen-3.0",), |
361 | a8083063 | Iustin Pop | make_option("-m", "--mac-prefix", dest="mac_prefix", |
362 | a8083063 | Iustin Pop | help="Specify the mac prefix for the instance IP" |
363 | a8083063 | Iustin Pop | " addresses, in the format XX:XX:XX", |
364 | a8083063 | Iustin Pop | metavar="PREFIX", |
365 | a8083063 | Iustin Pop | default="aa:00:00",), |
366 | a8083063 | Iustin Pop | make_option("-g", "--vg-name", dest="vg_name", |
367 | a8083063 | Iustin Pop | help="Specify the volume group name " |
368 | a8083063 | Iustin Pop | " (cluster-wide) for disk allocation [xenvg]", |
369 | a8083063 | Iustin Pop | metavar="VG", |
370 | 90b6aa3a | Manuel Franceschini | default=None,), |
371 | a8083063 | Iustin Pop | make_option("-b", "--bridge", dest="def_bridge", |
372 | a8083063 | Iustin Pop | help="Specify the default bridge name (cluster-wide)" |
373 | cf62a272 | Michael Hanselmann | " to connect the instances to [%s]" % |
374 | cf62a272 | Michael Hanselmann | constants.DEFAULT_BRIDGE, |
375 | a8083063 | Iustin Pop | metavar="BRIDGE", |
376 | cf62a272 | Michael Hanselmann | default=constants.DEFAULT_BRIDGE,), |
377 | 880478f8 | Iustin Pop | make_option("--master-netdev", dest="master_netdev", |
378 | 880478f8 | Iustin Pop | help="Specify the node interface (cluster-wide)" |
379 | cf62a272 | Michael Hanselmann | " on which the master IP address will be added " |
380 | cf62a272 | Michael Hanselmann | " [%s]" % constants.DEFAULT_BRIDGE, |
381 | 880478f8 | Iustin Pop | metavar="NETDEV", |
382 | cf62a272 | Michael Hanselmann | default=constants.DEFAULT_BRIDGE,), |
383 | 79e82404 | Manuel Franceschini | make_option("--file-storage-dir", dest="file_storage_dir", |
384 | 79e82404 | Manuel Franceschini | help="Specify the default directory (cluster-wide)" |
385 | 79e82404 | Manuel Franceschini | " for storing the file-based disks [%s]" % |
386 | 79e82404 | Manuel Franceschini | constants.DEFAULT_FILE_STORAGE_DIR, |
387 | 79e82404 | Manuel Franceschini | metavar="DIR", |
388 | 79e82404 | Manuel Franceschini | default=constants.DEFAULT_FILE_STORAGE_DIR,), |
389 | 90b6aa3a | Manuel Franceschini | make_option("--no-lvm-storage", dest="lvm_storage", |
390 | 90b6aa3a | Manuel Franceschini | help="No support for lvm based instances" |
391 | 90b6aa3a | Manuel Franceschini | " (cluster-wide)", |
392 | 90b6aa3a | Manuel Franceschini | action="store_false", default=True,), |
393 | a8083063 | Iustin Pop | ], |
394 | 9a033156 | Iustin Pop | "[opts...] <cluster_name>", |
395 | a8083063 | Iustin Pop | "Initialises a new cluster configuration"), |
396 | a8083063 | Iustin Pop | 'destroy': (DestroyCluster, ARGS_NONE, |
397 | a8083063 | Iustin Pop | [DEBUG_OPT, |
398 | a8083063 | Iustin Pop | make_option("--yes-do-it", dest="yes_do_it", |
399 | a8083063 | Iustin Pop | help="Destroy cluster", |
400 | a8083063 | Iustin Pop | action="store_true"), |
401 | a8083063 | Iustin Pop | ], |
402 | 9a033156 | Iustin Pop | "", "Destroy cluster"), |
403 | 07bd8a51 | Iustin Pop | 'rename': (RenameCluster, ARGS_ONE, [DEBUG_OPT, FORCE_OPT], |
404 | 9a033156 | Iustin Pop | "<new_name>", |
405 | 07bd8a51 | Iustin Pop | "Renames the cluster"), |
406 | e54c4c5e | Guido Trotter | 'verify': (VerifyCluster, ARGS_NONE, [DEBUG_OPT, |
407 | e54c4c5e | Guido Trotter | make_option("--no-nplus1-mem", dest="skip_nplusone_mem", |
408 | e54c4c5e | Guido Trotter | help="Skip N+1 memory redundancy tests", |
409 | e54c4c5e | Guido Trotter | action="store_true", |
410 | e54c4c5e | Guido Trotter | default=False,), |
411 | e54c4c5e | Guido Trotter | ], |
412 | 9a033156 | Iustin Pop | "", "Does a check on the cluster configuration"), |
413 | f4d4e184 | Iustin Pop | 'verify-disks': (VerifyDisks, ARGS_NONE, [DEBUG_OPT], |
414 | 9a033156 | Iustin Pop | "", "Does a check on the cluster disk status"), |
415 | a8083063 | Iustin Pop | 'masterfailover': (MasterFailover, ARGS_NONE, [DEBUG_OPT], |
416 | 9a033156 | Iustin Pop | "", "Makes the current node the master"), |
417 | a8083063 | Iustin Pop | 'version': (ShowClusterVersion, ARGS_NONE, [DEBUG_OPT], |
418 | 9a033156 | Iustin Pop | "", "Shows the cluster version"), |
419 | a8083063 | Iustin Pop | 'getmaster': (ShowClusterMaster, ARGS_NONE, [DEBUG_OPT], |
420 | 9a033156 | Iustin Pop | "", "Shows the cluster master"), |
421 | a8083063 | Iustin Pop | 'copyfile': (ClusterCopyFile, ARGS_ONE, [DEBUG_OPT, node_option], |
422 | 9a033156 | Iustin Pop | "[-n node...] <filename>", |
423 | a8083063 | Iustin Pop | "Copies a file to all (or only some) nodes"), |
424 | a8083063 | Iustin Pop | 'command': (RunClusterCommand, ARGS_ATLEAST(1), [DEBUG_OPT, node_option], |
425 | 9a033156 | Iustin Pop | "[-n node...] <command>", |
426 | a8083063 | Iustin Pop | "Runs a command on all (or only some) nodes"), |
427 | a8083063 | Iustin Pop | 'info': (ShowClusterConfig, ARGS_NONE, [DEBUG_OPT], |
428 | 9a033156 | Iustin Pop | "", "Show cluster configuration"), |
429 | 846baef9 | Iustin Pop | 'list-tags': (ListTags, ARGS_NONE, |
430 | 9a033156 | Iustin Pop | [DEBUG_OPT], "", "List the tags of the cluster"), |
431 | 810c50b7 | Iustin Pop | 'add-tags': (AddTags, ARGS_ANY, [DEBUG_OPT, TAG_SRC_OPT], |
432 | 9a033156 | Iustin Pop | "tag...", "Add tags to the cluster"), |
433 | 810c50b7 | Iustin Pop | 'remove-tags': (RemoveTags, ARGS_ANY, [DEBUG_OPT, TAG_SRC_OPT], |
434 | 9a033156 | Iustin Pop | "tag...", "Remove tags from the cluster"), |
435 | 73415719 | Iustin Pop | 'search-tags': (SearchTags, ARGS_ONE, |
436 | 9a033156 | Iustin Pop | [DEBUG_OPT], "", "Searches the tags on all objects on" |
437 | 73415719 | Iustin Pop | " the cluster for a given pattern (regex)"), |
438 | 90b6aa3a | Manuel Franceschini | 'modify': (SetClusterParams, ARGS_NONE, |
439 | 90b6aa3a | Manuel Franceschini | [DEBUG_OPT, |
440 | 90b6aa3a | Manuel Franceschini | make_option("-g", "--vg-name", dest="vg_name", |
441 | 90b6aa3a | Manuel Franceschini | help="Specify the volume group name " |
442 | 90b6aa3a | Manuel Franceschini | " (cluster-wide) for disk allocation " |
443 | 90b6aa3a | Manuel Franceschini | "and enable lvm based storage", |
444 | 90b6aa3a | Manuel Franceschini | metavar="VG",), |
445 | 90b6aa3a | Manuel Franceschini | make_option("--no-lvm-storage", dest="lvm_storage", |
446 | 90b6aa3a | Manuel Franceschini | help="Disable support for lvm based instances" |
447 | 90b6aa3a | Manuel Franceschini | " (cluster-wide)", |
448 | 90b6aa3a | Manuel Franceschini | action="store_false", default=True,), |
449 | 90b6aa3a | Manuel Franceschini | ], |
450 | 90b6aa3a | Manuel Franceschini | "[opts...]", |
451 | 90b6aa3a | Manuel Franceschini | "Alters the parameters of the cluster"), |
452 | a8083063 | Iustin Pop | } |
453 | a8083063 | Iustin Pop | |
454 | a8083063 | Iustin Pop | if __name__ == '__main__': |
455 | 846baef9 | Iustin Pop | sys.exit(GenericMain(commands, override={"tag_type": constants.TAG_CLUSTER})) |