Revision c4ed32cb scripts/gnt-node
b/scripts/gnt-node | ||
---|---|---|
27 | 27 |
from optparse import make_option |
28 | 28 |
|
29 | 29 |
from ganeti.cli import * |
30 |
from ganeti import cli |
|
30 | 31 |
from ganeti import opcodes |
31 | 32 |
from ganeti import utils |
32 | 33 |
from ganeti import constants |
... | ... | |
169 | 170 |
""" |
170 | 171 |
cl = GetClient() |
171 | 172 |
force = opts.force |
173 |
|
|
174 |
dst_node = opts.dst_node |
|
175 |
iallocator = opts.iallocator |
|
176 |
|
|
177 |
cnt = [dst_node, iallocator].count(None) |
|
178 |
if cnt != 1: |
|
179 |
raise errors.OpPrereqError("One and only one of the -n and -i" |
|
180 |
" options must be passed") |
|
181 |
|
|
172 | 182 |
selected_fields = ["name", "sinst_list"] |
173 |
src_node, dst_node = args
|
|
183 |
src_node = args[0]
|
|
174 | 184 |
|
175 | 185 |
op = opcodes.OpQueryNodes(output_fields=selected_fields, names=[src_node]) |
176 |
result = SubmitOpCode(op, cl=cl)
|
|
186 |
result = cl.QueryNodes(names=[src_node], fields=selected_fields)
|
|
177 | 187 |
src_node, sinst = result[0] |
178 |
op = opcodes.OpQueryNodes(output_fields=["name"], names=[dst_node]) |
|
179 |
result = SubmitOpCode(op, cl=cl) |
|
180 |
dst_node = result[0][0] |
|
181 |
|
|
182 |
if src_node == dst_node: |
|
183 |
raise errors.OpPrereqError("Evacuate node needs different source and" |
|
184 |
" target nodes (node %s given twice)" % |
|
185 |
src_node) |
|
186 | 188 |
|
187 | 189 |
if not sinst: |
188 | 190 |
ToStderr("No secondary instances on node %s, exiting.", src_node) |
189 | 191 |
return constants.EXIT_SUCCESS |
190 | 192 |
|
193 |
if dst_node is not None: |
|
194 |
result = cl.QueryNodes(names=[dst_node], fields=["name"]) |
|
195 |
dst_node = result[0][0] |
|
196 |
|
|
197 |
if src_node == dst_node: |
|
198 |
raise errors.OpPrereqError("Evacuate node needs different source and" |
|
199 |
" target nodes (node %s given twice)" % |
|
200 |
src_node) |
|
201 |
txt_msg = "to node %s" % dst_node |
|
202 |
else: |
|
203 |
txt_msg = "using iallocator %s" % iallocator |
|
204 |
|
|
191 | 205 |
sinst = utils.NiceSort(sinst) |
192 | 206 |
|
193 | 207 |
if not force and not AskUser("Relocate instance(s) %s from node\n" |
194 |
" %s to node\n %s?" %
|
|
208 |
" %s %s?" % |
|
195 | 209 |
(",".join("'%s'" % name for name in sinst), |
196 |
src_node, dst_node)):
|
|
210 |
src_node, txt_msg)):
|
|
197 | 211 |
return constants.EXIT_CONFIRMATION |
198 | 212 |
|
199 |
jex = JobExecutor()
|
|
213 |
ops = []
|
|
200 | 214 |
for iname in sinst: |
201 | 215 |
op = opcodes.OpReplaceDisks(instance_name=iname, |
202 | 216 |
remote_node=dst_node, |
203 | 217 |
mode=constants.REPLACE_DISK_CHG, |
218 |
iallocator=iallocator, |
|
204 | 219 |
disks=[]) |
205 |
jex.QueueJob(iname, op)
|
|
220 |
ops.append(op)
|
|
206 | 221 |
|
207 |
results = jex.GetResults() |
|
208 |
|
|
209 |
bad_cnt = len([row for row in results if not row[0]]) |
|
210 |
if bad_cnt == 0: |
|
211 |
ToStdout("All %d instance(s) relocated successfully.", len(results)) |
|
212 |
retcode = constants.EXIT_SUCCESS |
|
213 |
else: |
|
214 |
ToStdout("There were errors during the relocation:\n" |
|
215 |
"%d error(s) out of %d instance(s).", bad_cnt, len(results)) |
|
216 |
retcode = constants.EXIT_FAILURE |
|
217 |
return retcode |
|
222 |
job_id = cli.SendJob(ops, cl=cl) |
|
223 |
cli.PollJob(job_id, cl=cl) |
|
218 | 224 |
|
219 | 225 |
|
220 | 226 |
def FailoverNode(opts, args): |
... | ... | |
448 | 454 |
], |
449 | 455 |
"[-s ip] [--readd] [--no-ssh-key-check] <node_name>", |
450 | 456 |
"Add a node to the cluster"), |
451 |
'evacuate': (EvacuateNode, ARGS_FIXED(2), |
|
452 |
[DEBUG_OPT, FORCE_OPT], |
|
453 |
"[-f] <src> <dst>", |
|
454 |
"Relocate the secondary instances from the first node" |
|
455 |
" to the second one (only for instances with drbd disk template" |
|
456 |
), |
|
457 |
'evacuate': (EvacuateNode, ARGS_ONE, |
|
458 |
[DEBUG_OPT, FORCE_OPT, |
|
459 |
make_option("-n", "--new-secondary", dest="dst_node", |
|
460 |
help="New secondary node", metavar="NODE", |
|
461 |
default=None), |
|
462 |
make_option("-i", "--iallocator", metavar="<NAME>", |
|
463 |
help="Select new secondary for the instance" |
|
464 |
" automatically using the" |
|
465 |
" <NAME> iallocator plugin", |
|
466 |
default=None, type="string"), |
|
467 |
], |
|
468 |
"[-f] {-i <iallocator> | -n <dst>} <node>", |
|
469 |
"Relocate the secondary instances from a node" |
|
470 |
" to other nodes (only for instances with drbd disk template)"), |
|
457 | 471 |
'failover': (FailoverNode, ARGS_ONE, |
458 | 472 |
[DEBUG_OPT, FORCE_OPT, |
459 | 473 |
make_option("--ignore-consistency", dest="ignore_consistency", |
Also available in: Unified diff