root / scripts / gnt-node @ 31d97b2a
History | View | Annotate | Download (22.2 kB)
1 |
#!/usr/bin/python |
---|---|
2 |
# |
3 |
|
4 |
# Copyright (C) 2006, 2007, 2008 Google Inc. |
5 |
# |
6 |
# This program is free software; you can redistribute it and/or modify |
7 |
# it under the terms of the GNU General Public License as published by |
8 |
# the Free Software Foundation; either version 2 of the License, or |
9 |
# (at your option) any later version. |
10 |
# |
11 |
# This program is distributed in the hope that it will be useful, but |
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
# General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License |
17 |
# along with this program; if not, write to the Free Software |
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 |
# 02110-1301, USA. |
20 |
|
21 |
"""Node related commands""" |
22 |
|
23 |
# pylint: disable-msg=W0401,W0613,W0614,C0103 |
24 |
# W0401: Wildcard import ganeti.cli |
25 |
# W0613: Unused argument, since all functions follow the same API |
26 |
# W0614: Unused import %s from wildcard import (since we need cli) |
27 |
# C0103: Invalid name gnt-node |
28 |
|
29 |
import sys |
30 |
|
31 |
try: |
32 |
import roman |
33 |
except ImportError: |
34 |
roman = None |
35 |
|
36 |
from ganeti.cli import * |
37 |
from ganeti import opcodes |
38 |
from ganeti import utils |
39 |
from ganeti import constants |
40 |
from ganeti import errors |
41 |
from ganeti import bootstrap |
42 |
|
43 |
|
44 |
#: default list of field for L{ListNodes} |
45 |
_LIST_DEF_FIELDS = [ |
46 |
"name", "dtotal", "dfree", |
47 |
"mtotal", "mnode", "mfree", |
48 |
"pinst_cnt", "sinst_cnt", |
49 |
] |
50 |
|
51 |
|
52 |
#: default list of field for L{ListStorage} |
53 |
_LIST_STOR_DEF_FIELDS = [ |
54 |
constants.SF_NODE, |
55 |
constants.SF_TYPE, |
56 |
constants.SF_NAME, |
57 |
constants.SF_SIZE, |
58 |
constants.SF_USED, |
59 |
constants.SF_FREE, |
60 |
constants.SF_ALLOCATABLE, |
61 |
] |
62 |
|
63 |
|
64 |
#: headers (and full field list for L{ListNodes} |
65 |
_LIST_HEADERS = { |
66 |
"name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst", |
67 |
"pinst_list": "PriInstances", "sinst_list": "SecInstances", |
68 |
"pip": "PrimaryIP", "sip": "SecondaryIP", |
69 |
"dtotal": "DTotal", "dfree": "DFree", |
70 |
"mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree", |
71 |
"bootid": "BootID", |
72 |
"ctotal": "CTotal", "cnodes": "CNodes", "csockets": "CSockets", |
73 |
"tags": "Tags", |
74 |
"serial_no": "SerialNo", |
75 |
"master_candidate": "MasterC", |
76 |
"master": "IsMaster", |
77 |
"offline": "Offline", "drained": "Drained", |
78 |
"role": "Role", |
79 |
"ctime": "CTime", "mtime": "MTime", "uuid": "UUID" |
80 |
} |
81 |
|
82 |
|
83 |
#: headers (and full field list for L{ListStorage} |
84 |
_LIST_STOR_HEADERS = { |
85 |
constants.SF_NODE: "Node", |
86 |
constants.SF_TYPE: "Type", |
87 |
constants.SF_NAME: "Name", |
88 |
constants.SF_SIZE: "Size", |
89 |
constants.SF_USED: "Used", |
90 |
constants.SF_FREE: "Free", |
91 |
constants.SF_ALLOCATABLE: "Allocatable", |
92 |
} |
93 |
|
94 |
|
95 |
#: User-facing storage unit types |
96 |
_USER_STORAGE_TYPE = { |
97 |
constants.ST_FILE: "file", |
98 |
constants.ST_LVM_PV: "lvm-pv", |
99 |
constants.ST_LVM_VG: "lvm-vg", |
100 |
} |
101 |
|
102 |
_STORAGE_TYPE_OPT = \ |
103 |
cli_option("-t", "--storage-type", |
104 |
dest="user_storage_type", |
105 |
choices=_USER_STORAGE_TYPE.keys(), |
106 |
default=None, |
107 |
metavar="STORAGE_TYPE", |
108 |
help=("Storage type (%s)" % |
109 |
utils.CommaJoin(_USER_STORAGE_TYPE.keys()))) |
110 |
|
111 |
_REPAIRABLE_STORAGE_TYPES = \ |
112 |
[st for st, so in constants.VALID_STORAGE_OPERATIONS.iteritems() |
113 |
if constants.SO_FIX_CONSISTENCY in so] |
114 |
|
115 |
_MODIFIABLE_STORAGE_TYPES = constants.MODIFIABLE_STORAGE_FIELDS.keys() |
116 |
|
117 |
|
118 |
def ConvertStorageType(user_storage_type): |
119 |
"""Converts a user storage type to its internal name. |
120 |
|
121 |
""" |
122 |
try: |
123 |
return _USER_STORAGE_TYPE[user_storage_type] |
124 |
except KeyError: |
125 |
raise errors.OpPrereqError("Unknown storage type: %s" % user_storage_type, |
126 |
errors.ECODE_INVAL) |
127 |
|
128 |
|
129 |
@UsesRPC |
130 |
def AddNode(opts, args): |
131 |
"""Add a node to the cluster. |
132 |
|
133 |
@param opts: the command line options selected by the user |
134 |
@type args: list |
135 |
@param args: should contain only one element, the new node name |
136 |
@rtype: int |
137 |
@return: the desired exit code |
138 |
|
139 |
""" |
140 |
cl = GetClient() |
141 |
dns_data = utils.GetHostInfo(utils.HostInfo.NormalizeName(args[0])) |
142 |
node = dns_data.name |
143 |
readd = opts.readd |
144 |
|
145 |
try: |
146 |
output = cl.QueryNodes(names=[node], fields=['name', 'sip'], |
147 |
use_locking=False) |
148 |
node_exists, sip = output[0] |
149 |
except (errors.OpPrereqError, errors.OpExecError): |
150 |
node_exists = "" |
151 |
sip = None |
152 |
|
153 |
if readd: |
154 |
if not node_exists: |
155 |
ToStderr("Node %s not in the cluster" |
156 |
" - please retry without '--readd'", node) |
157 |
return 1 |
158 |
else: |
159 |
if node_exists: |
160 |
ToStderr("Node %s already in the cluster (as %s)" |
161 |
" - please retry with '--readd'", node, node_exists) |
162 |
return 1 |
163 |
sip = opts.secondary_ip |
164 |
|
165 |
# read the cluster name from the master |
166 |
output = cl.QueryConfigValues(['cluster_name']) |
167 |
cluster_name = output[0] |
168 |
|
169 |
if not readd: |
170 |
ToStderr("-- WARNING -- \n" |
171 |
"Performing this operation is going to replace the ssh daemon" |
172 |
" keypair\n" |
173 |
"on the target machine (%s) with the ones of the" |
174 |
" current one\n" |
175 |
"and grant full intra-cluster ssh root access to/from it\n", node) |
176 |
|
177 |
bootstrap.SetupNodeDaemon(cluster_name, node, opts.ssh_key_check) |
178 |
|
179 |
op = opcodes.OpAddNode(node_name=args[0], secondary_ip=sip, |
180 |
readd=opts.readd) |
181 |
SubmitOpCode(op, opts=opts) |
182 |
|
183 |
|
184 |
def ListNodes(opts, args): |
185 |
"""List nodes and their properties. |
186 |
|
187 |
@param opts: the command line options selected by the user |
188 |
@type args: list |
189 |
@param args: should be an empty list |
190 |
@rtype: int |
191 |
@return: the desired exit code |
192 |
|
193 |
""" |
194 |
if opts.output is None: |
195 |
selected_fields = _LIST_DEF_FIELDS |
196 |
elif opts.output.startswith("+"): |
197 |
selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",") |
198 |
else: |
199 |
selected_fields = opts.output.split(",") |
200 |
|
201 |
output = GetClient().QueryNodes(args, selected_fields, opts.do_locking) |
202 |
|
203 |
if not opts.no_headers: |
204 |
headers = _LIST_HEADERS |
205 |
else: |
206 |
headers = None |
207 |
|
208 |
unitfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree"] |
209 |
|
210 |
numfields = ["dtotal", "dfree", |
211 |
"mtotal", "mnode", "mfree", |
212 |
"pinst_cnt", "sinst_cnt", |
213 |
"ctotal", "serial_no"] |
214 |
|
215 |
latinfriendlyfields = ["pinst_cnt", "sinst_cnt", |
216 |
"ctotal", "cnodes", "csockets", |
217 |
"serial_no"] |
218 |
|
219 |
list_type_fields = ("pinst_list", "sinst_list", "tags") |
220 |
# change raw values to nicer strings |
221 |
for row in output: |
222 |
for idx, field in enumerate(selected_fields): |
223 |
val = row[idx] |
224 |
if field in list_type_fields: |
225 |
val = ",".join(val) |
226 |
elif field in ('master', 'master_candidate', 'offline', 'drained'): |
227 |
if val: |
228 |
val = 'Y' |
229 |
else: |
230 |
val = 'N' |
231 |
elif field == "ctime" or field == "mtime": |
232 |
val = utils.FormatTime(val) |
233 |
elif val is None: |
234 |
val = "?" |
235 |
elif (roman is not None and opts.roman_integers |
236 |
and field in latinfriendlyfields): |
237 |
try: |
238 |
val = roman.toRoman(val) |
239 |
except roman.RomanError: |
240 |
pass |
241 |
row[idx] = str(val) |
242 |
|
243 |
data = GenerateTable(separator=opts.separator, headers=headers, |
244 |
fields=selected_fields, unitfields=unitfields, |
245 |
numfields=numfields, data=output, units=opts.units) |
246 |
for line in data: |
247 |
ToStdout(line) |
248 |
|
249 |
return 0 |
250 |
|
251 |
|
252 |
def EvacuateNode(opts, args): |
253 |
"""Relocate all secondary instance from a node. |
254 |
|
255 |
@param opts: the command line options selected by the user |
256 |
@type args: list |
257 |
@param args: should be an empty list |
258 |
@rtype: int |
259 |
@return: the desired exit code |
260 |
|
261 |
""" |
262 |
cl = GetClient() |
263 |
force = opts.force |
264 |
|
265 |
dst_node = opts.dst_node |
266 |
iallocator = opts.iallocator |
267 |
|
268 |
cnt = [dst_node, iallocator].count(None) |
269 |
if cnt != 1: |
270 |
raise errors.OpPrereqError("One and only one of the -n and -I" |
271 |
" options must be passed", errors.ECODE_INVAL) |
272 |
|
273 |
op = opcodes.OpNodeEvacuationStrategy(nodes=args, |
274 |
iallocator=iallocator, |
275 |
remote_node=dst_node) |
276 |
|
277 |
result = SubmitOpCode(op, cl=cl, opts=opts) |
278 |
if not result: |
279 |
# no instances to migrate |
280 |
ToStderr("No secondary instances on node(s) %s, exiting.", |
281 |
utils.CommaJoin(args)) |
282 |
return constants.EXIT_SUCCESS |
283 |
|
284 |
if not force and not AskUser("Relocate instance(s) %s from node(s) %s?" % |
285 |
(",".join("'%s'" % name[0] for name in result), |
286 |
utils.CommaJoin(args))): |
287 |
return constants.EXIT_CONFIRMATION |
288 |
|
289 |
jex = JobExecutor(cl=cl, opts=opts) |
290 |
for row in result: |
291 |
iname = row[0] |
292 |
node = row[1] |
293 |
ToStdout("Will relocate instance %s to node %s", iname, node) |
294 |
op = opcodes.OpReplaceDisks(instance_name=iname, |
295 |
remote_node=node, disks=[], |
296 |
mode=constants.REPLACE_DISK_CHG, |
297 |
early_release=opts.early_release) |
298 |
jex.QueueJob(iname, op) |
299 |
results = jex.GetResults() |
300 |
bad_cnt = len([row for row in results if not row[0]]) |
301 |
if bad_cnt == 0: |
302 |
ToStdout("All %d instance(s) failed over successfully.", len(results)) |
303 |
rcode = constants.EXIT_SUCCESS |
304 |
else: |
305 |
ToStdout("There were errors during the failover:\n" |
306 |
"%d error(s) out of %d instance(s).", bad_cnt, len(results)) |
307 |
rcode = constants.EXIT_FAILURE |
308 |
return rcode |
309 |
|
310 |
|
311 |
def FailoverNode(opts, args): |
312 |
"""Failover all primary instance on a node. |
313 |
|
314 |
@param opts: the command line options selected by the user |
315 |
@type args: list |
316 |
@param args: should be an empty list |
317 |
@rtype: int |
318 |
@return: the desired exit code |
319 |
|
320 |
""" |
321 |
cl = GetClient() |
322 |
force = opts.force |
323 |
selected_fields = ["name", "pinst_list"] |
324 |
|
325 |
# these fields are static data anyway, so it doesn't matter, but |
326 |
# locking=True should be safer |
327 |
result = cl.QueryNodes(names=args, fields=selected_fields, |
328 |
use_locking=False) |
329 |
node, pinst = result[0] |
330 |
|
331 |
if not pinst: |
332 |
ToStderr("No primary instances on node %s, exiting.", node) |
333 |
return 0 |
334 |
|
335 |
pinst = utils.NiceSort(pinst) |
336 |
|
337 |
retcode = 0 |
338 |
|
339 |
if not force and not AskUser("Fail over instance(s) %s?" % |
340 |
(",".join("'%s'" % name for name in pinst))): |
341 |
return 2 |
342 |
|
343 |
jex = JobExecutor(cl=cl, opts=opts) |
344 |
for iname in pinst: |
345 |
op = opcodes.OpFailoverInstance(instance_name=iname, |
346 |
ignore_consistency=opts.ignore_consistency) |
347 |
jex.QueueJob(iname, op) |
348 |
results = jex.GetResults() |
349 |
bad_cnt = len([row for row in results if not row[0]]) |
350 |
if bad_cnt == 0: |
351 |
ToStdout("All %d instance(s) failed over successfully.", len(results)) |
352 |
else: |
353 |
ToStdout("There were errors during the failover:\n" |
354 |
"%d error(s) out of %d instance(s).", bad_cnt, len(results)) |
355 |
return retcode |
356 |
|
357 |
|
358 |
def MigrateNode(opts, args): |
359 |
"""Migrate all primary instance on a node. |
360 |
|
361 |
""" |
362 |
cl = GetClient() |
363 |
force = opts.force |
364 |
selected_fields = ["name", "pinst_list"] |
365 |
|
366 |
result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=False) |
367 |
node, pinst = result[0] |
368 |
|
369 |
if not pinst: |
370 |
ToStdout("No primary instances on node %s, exiting." % node) |
371 |
return 0 |
372 |
|
373 |
pinst = utils.NiceSort(pinst) |
374 |
|
375 |
if not force and not AskUser("Migrate instance(s) %s?" % |
376 |
(",".join("'%s'" % name for name in pinst))): |
377 |
return 2 |
378 |
|
379 |
op = opcodes.OpMigrateNode(node_name=args[0], live=opts.live) |
380 |
SubmitOpCode(op, cl=cl, opts=opts) |
381 |
|
382 |
|
383 |
def ShowNodeConfig(opts, args): |
384 |
"""Show node information. |
385 |
|
386 |
@param opts: the command line options selected by the user |
387 |
@type args: list |
388 |
@param args: should either be an empty list, in which case |
389 |
we show information about all nodes, or should contain |
390 |
a list of nodes to be queried for information |
391 |
@rtype: int |
392 |
@return: the desired exit code |
393 |
|
394 |
""" |
395 |
cl = GetClient() |
396 |
result = cl.QueryNodes(fields=["name", "pip", "sip", |
397 |
"pinst_list", "sinst_list", |
398 |
"master_candidate", "drained", "offline"], |
399 |
names=args, use_locking=False) |
400 |
|
401 |
for (name, primary_ip, secondary_ip, pinst, sinst, |
402 |
is_mc, drained, offline) in result: |
403 |
ToStdout("Node name: %s", name) |
404 |
ToStdout(" primary ip: %s", primary_ip) |
405 |
ToStdout(" secondary ip: %s", secondary_ip) |
406 |
ToStdout(" master candidate: %s", is_mc) |
407 |
ToStdout(" drained: %s", drained) |
408 |
ToStdout(" offline: %s", offline) |
409 |
if pinst: |
410 |
ToStdout(" primary for instances:") |
411 |
for iname in utils.NiceSort(pinst): |
412 |
ToStdout(" - %s", iname) |
413 |
else: |
414 |
ToStdout(" primary for no instances") |
415 |
if sinst: |
416 |
ToStdout(" secondary for instances:") |
417 |
for iname in utils.NiceSort(sinst): |
418 |
ToStdout(" - %s", iname) |
419 |
else: |
420 |
ToStdout(" secondary for no instances") |
421 |
|
422 |
return 0 |
423 |
|
424 |
|
425 |
def RemoveNode(opts, args): |
426 |
"""Remove a node from the cluster. |
427 |
|
428 |
@param opts: the command line options selected by the user |
429 |
@type args: list |
430 |
@param args: should contain only one element, the name of |
431 |
the node to be removed |
432 |
@rtype: int |
433 |
@return: the desired exit code |
434 |
|
435 |
""" |
436 |
op = opcodes.OpRemoveNode(node_name=args[0]) |
437 |
SubmitOpCode(op, opts=opts) |
438 |
return 0 |
439 |
|
440 |
|
441 |
def PowercycleNode(opts, args): |
442 |
"""Remove a node from the cluster. |
443 |
|
444 |
@param opts: the command line options selected by the user |
445 |
@type args: list |
446 |
@param args: should contain only one element, the name of |
447 |
the node to be removed |
448 |
@rtype: int |
449 |
@return: the desired exit code |
450 |
|
451 |
""" |
452 |
node = args[0] |
453 |
if (not opts.confirm and |
454 |
not AskUser("Are you sure you want to hard powercycle node %s?" % node)): |
455 |
return 2 |
456 |
|
457 |
op = opcodes.OpPowercycleNode(node_name=node, force=opts.force) |
458 |
result = SubmitOpCode(op, opts=opts) |
459 |
ToStderr(result) |
460 |
return 0 |
461 |
|
462 |
|
463 |
def ListVolumes(opts, args): |
464 |
"""List logical volumes on node(s). |
465 |
|
466 |
@param opts: the command line options selected by the user |
467 |
@type args: list |
468 |
@param args: should either be an empty list, in which case |
469 |
we list data for all nodes, or contain a list of nodes |
470 |
to display data only for those |
471 |
@rtype: int |
472 |
@return: the desired exit code |
473 |
|
474 |
""" |
475 |
if opts.output is None: |
476 |
selected_fields = ["node", "phys", "vg", |
477 |
"name", "size", "instance"] |
478 |
else: |
479 |
selected_fields = opts.output.split(",") |
480 |
|
481 |
op = opcodes.OpQueryNodeVolumes(nodes=args, output_fields=selected_fields) |
482 |
output = SubmitOpCode(op, opts=opts) |
483 |
|
484 |
if not opts.no_headers: |
485 |
headers = {"node": "Node", "phys": "PhysDev", |
486 |
"vg": "VG", "name": "Name", |
487 |
"size": "Size", "instance": "Instance"} |
488 |
else: |
489 |
headers = None |
490 |
|
491 |
unitfields = ["size"] |
492 |
|
493 |
numfields = ["size"] |
494 |
|
495 |
data = GenerateTable(separator=opts.separator, headers=headers, |
496 |
fields=selected_fields, unitfields=unitfields, |
497 |
numfields=numfields, data=output, units=opts.units) |
498 |
|
499 |
for line in data: |
500 |
ToStdout(line) |
501 |
|
502 |
return 0 |
503 |
|
504 |
|
505 |
def ListStorage(opts, args): |
506 |
"""List physical volumes on node(s). |
507 |
|
508 |
@param opts: the command line options selected by the user |
509 |
@type args: list |
510 |
@param args: should either be an empty list, in which case |
511 |
we list data for all nodes, or contain a list of nodes |
512 |
to display data only for those |
513 |
@rtype: int |
514 |
@return: the desired exit code |
515 |
|
516 |
""" |
517 |
# TODO: Default to ST_FILE if LVM is disabled on the cluster |
518 |
if opts.user_storage_type is None: |
519 |
opts.user_storage_type = constants.ST_LVM_PV |
520 |
|
521 |
storage_type = ConvertStorageType(opts.user_storage_type) |
522 |
|
523 |
if opts.output is None: |
524 |
selected_fields = _LIST_STOR_DEF_FIELDS |
525 |
elif opts.output.startswith("+"): |
526 |
selected_fields = _LIST_STOR_DEF_FIELDS + opts.output[1:].split(",") |
527 |
else: |
528 |
selected_fields = opts.output.split(",") |
529 |
|
530 |
op = opcodes.OpQueryNodeStorage(nodes=args, |
531 |
storage_type=storage_type, |
532 |
output_fields=selected_fields) |
533 |
output = SubmitOpCode(op, opts=opts) |
534 |
|
535 |
if not opts.no_headers: |
536 |
headers = { |
537 |
constants.SF_NODE: "Node", |
538 |
constants.SF_TYPE: "Type", |
539 |
constants.SF_NAME: "Name", |
540 |
constants.SF_SIZE: "Size", |
541 |
constants.SF_USED: "Used", |
542 |
constants.SF_FREE: "Free", |
543 |
constants.SF_ALLOCATABLE: "Allocatable", |
544 |
} |
545 |
else: |
546 |
headers = None |
547 |
|
548 |
unitfields = [constants.SF_SIZE, constants.SF_USED, constants.SF_FREE] |
549 |
numfields = [constants.SF_SIZE, constants.SF_USED, constants.SF_FREE] |
550 |
|
551 |
# change raw values to nicer strings |
552 |
for row in output: |
553 |
for idx, field in enumerate(selected_fields): |
554 |
val = row[idx] |
555 |
if field == constants.SF_ALLOCATABLE: |
556 |
if val: |
557 |
val = "Y" |
558 |
else: |
559 |
val = "N" |
560 |
row[idx] = str(val) |
561 |
|
562 |
data = GenerateTable(separator=opts.separator, headers=headers, |
563 |
fields=selected_fields, unitfields=unitfields, |
564 |
numfields=numfields, data=output, units=opts.units) |
565 |
|
566 |
for line in data: |
567 |
ToStdout(line) |
568 |
|
569 |
return 0 |
570 |
|
571 |
|
572 |
def ModifyStorage(opts, args): |
573 |
"""Modify storage volume on a node. |
574 |
|
575 |
@param opts: the command line options selected by the user |
576 |
@type args: list |
577 |
@param args: should contain 3 items: node name, storage type and volume name |
578 |
@rtype: int |
579 |
@return: the desired exit code |
580 |
|
581 |
""" |
582 |
(node_name, user_storage_type, volume_name) = args |
583 |
|
584 |
storage_type = ConvertStorageType(user_storage_type) |
585 |
|
586 |
changes = {} |
587 |
|
588 |
if opts.allocatable is not None: |
589 |
changes[constants.SF_ALLOCATABLE] = opts.allocatable |
590 |
|
591 |
if changes: |
592 |
op = opcodes.OpModifyNodeStorage(node_name=node_name, |
593 |
storage_type=storage_type, |
594 |
name=volume_name, |
595 |
changes=changes) |
596 |
SubmitOpCode(op, opts=opts) |
597 |
else: |
598 |
ToStderr("No changes to perform, exiting.") |
599 |
|
600 |
|
601 |
def RepairStorage(opts, args): |
602 |
"""Repairs a storage volume on a node. |
603 |
|
604 |
@param opts: the command line options selected by the user |
605 |
@type args: list |
606 |
@param args: should contain 3 items: node name, storage type and volume name |
607 |
@rtype: int |
608 |
@return: the desired exit code |
609 |
|
610 |
""" |
611 |
(node_name, user_storage_type, volume_name) = args |
612 |
|
613 |
storage_type = ConvertStorageType(user_storage_type) |
614 |
|
615 |
op = opcodes.OpRepairNodeStorage(node_name=node_name, |
616 |
storage_type=storage_type, |
617 |
name=volume_name, |
618 |
ignore_consistency=opts.ignore_consistency) |
619 |
SubmitOpCode(op, opts=opts) |
620 |
|
621 |
|
622 |
def SetNodeParams(opts, args): |
623 |
"""Modifies a node. |
624 |
|
625 |
@param opts: the command line options selected by the user |
626 |
@type args: list |
627 |
@param args: should contain only one element, the node name |
628 |
@rtype: int |
629 |
@return: the desired exit code |
630 |
|
631 |
""" |
632 |
if [opts.master_candidate, opts.drained, opts.offline].count(None) == 3: |
633 |
ToStderr("Please give at least one of the parameters.") |
634 |
return 1 |
635 |
|
636 |
op = opcodes.OpSetNodeParams(node_name=args[0], |
637 |
master_candidate=opts.master_candidate, |
638 |
offline=opts.offline, |
639 |
drained=opts.drained, |
640 |
force=opts.force, |
641 |
auto_promote=opts.auto_promote) |
642 |
|
643 |
# even if here we process the result, we allow submit only |
644 |
result = SubmitOrSend(op, opts) |
645 |
|
646 |
if result: |
647 |
ToStdout("Modified node %s", args[0]) |
648 |
for param, data in result: |
649 |
ToStdout(" - %-5s -> %s", param, data) |
650 |
return 0 |
651 |
|
652 |
|
653 |
commands = { |
654 |
'add': ( |
655 |
AddNode, [ArgHost(min=1, max=1)], |
656 |
[SECONDARY_IP_OPT, READD_OPT, NOSSH_KEYCHECK_OPT], |
657 |
"[-s ip] [--readd] [--no-ssh-key-check] <node_name>", |
658 |
"Add a node to the cluster"), |
659 |
'evacuate': ( |
660 |
EvacuateNode, [ArgNode(min=1)], |
661 |
[FORCE_OPT, IALLOCATOR_OPT, NEW_SECONDARY_OPT, EARLY_RELEASE_OPT], |
662 |
"[-f] {-I <iallocator> | -n <dst>} <node>", |
663 |
"Relocate the secondary instances from a node" |
664 |
" to other nodes (only for instances with drbd disk template)"), |
665 |
'failover': ( |
666 |
FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT], |
667 |
"[-f] <node>", |
668 |
"Stops the primary instances on a node and start them on their" |
669 |
" secondary node (only for instances with drbd disk template)"), |
670 |
'migrate': ( |
671 |
MigrateNode, ARGS_ONE_NODE, [FORCE_OPT, NONLIVE_OPT], |
672 |
"[-f] <node>", |
673 |
"Migrate all the primary instance on a node away from it" |
674 |
" (only for instances of type drbd)"), |
675 |
'info': ( |
676 |
ShowNodeConfig, ARGS_MANY_NODES, [], |
677 |
"[<node_name>...]", "Show information about the node(s)"), |
678 |
'list': ( |
679 |
ListNodes, ARGS_MANY_NODES, |
680 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT], |
681 |
"[nodes...]", |
682 |
"Lists the nodes in the cluster. The available fields are (see the man" |
683 |
" page for details): %s. The default field list is (in order): %s." % |
684 |
(utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))), |
685 |
'modify': ( |
686 |
SetNodeParams, ARGS_ONE_NODE, |
687 |
[FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT, |
688 |
AUTO_PROMOTE_OPT], |
689 |
"<node_name>", "Alters the parameters of a node"), |
690 |
'powercycle': ( |
691 |
PowercycleNode, ARGS_ONE_NODE, |
692 |
[FORCE_OPT, CONFIRM_OPT], |
693 |
"<node_name>", "Tries to forcefully powercycle a node"), |
694 |
'remove': ( |
695 |
RemoveNode, ARGS_ONE_NODE, [], |
696 |
"<node_name>", "Removes a node from the cluster"), |
697 |
'volumes': ( |
698 |
ListVolumes, [ArgNode()], |
699 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT], |
700 |
"[<node_name>...]", "List logical volumes on node(s)"), |
701 |
'list-storage': ( |
702 |
ListStorage, ARGS_MANY_NODES, |
703 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, _STORAGE_TYPE_OPT], |
704 |
"[<node_name>...]", "List physical volumes on node(s). The available" |
705 |
" fields are (see the man page for details): %s." % |
706 |
(utils.CommaJoin(_LIST_STOR_HEADERS))), |
707 |
'modify-storage': ( |
708 |
ModifyStorage, |
709 |
[ArgNode(min=1, max=1), |
710 |
ArgChoice(min=1, max=1, choices=_MODIFIABLE_STORAGE_TYPES), |
711 |
ArgFile(min=1, max=1)], |
712 |
[ALLOCATABLE_OPT], |
713 |
"<node_name> <storage_type> <name>", "Modify storage volume on a node"), |
714 |
'repair-storage': ( |
715 |
RepairStorage, |
716 |
[ArgNode(min=1, max=1), |
717 |
ArgChoice(min=1, max=1, choices=_REPAIRABLE_STORAGE_TYPES), |
718 |
ArgFile(min=1, max=1)], |
719 |
[IGNORE_CONSIST_OPT], |
720 |
"<node_name> <storage_type> <name>", |
721 |
"Repairs a storage volume on a node"), |
722 |
'list-tags': ( |
723 |
ListTags, ARGS_ONE_NODE, [], |
724 |
"<node_name>", "List the tags of the given node"), |
725 |
'add-tags': ( |
726 |
AddTags, [ArgNode(min=1, max=1), ArgUnknown()], [TAG_SRC_OPT], |
727 |
"<node_name> tag...", "Add tags to the given node"), |
728 |
'remove-tags': ( |
729 |
RemoveTags, [ArgNode(min=1, max=1), ArgUnknown()], [TAG_SRC_OPT], |
730 |
"<node_name> tag...", "Remove tags from the given node"), |
731 |
} |
732 |
|
733 |
|
734 |
if __name__ == '__main__': |
735 |
sys.exit(GenericMain(commands, override={"tag_type": constants.TAG_NODE})) |