Revision a5bc662a scripts/gnt-node
b/scripts/gnt-node | ||
---|---|---|
94 | 94 |
return 0 |
95 | 95 |
|
96 | 96 |
|
97 |
def EvacuateNode(opts, args): |
|
98 |
"""Relocate all secondary instance from a node. |
|
99 |
|
|
100 |
""" |
|
101 |
force = opts.force |
|
102 |
selected_fields = ["name", "sinst_list"] |
|
103 |
src_node, dst_node = args |
|
104 |
|
|
105 |
op = opcodes.OpQueryNodes(output_fields=selected_fields, names=[src_node]) |
|
106 |
result = SubmitOpCode(op) |
|
107 |
src_node, sinst = result[0] |
|
108 |
op = opcodes.OpQueryNodes(output_fields=["name"], names=[dst_node]) |
|
109 |
result = SubmitOpCode(op) |
|
110 |
dst_node = result[0][0] |
|
111 |
|
|
112 |
if src_node == dst_node: |
|
113 |
raise errors.OpPrereqError("Evacuate node needs different source and" |
|
114 |
" target nodes (node %s given twice)" % |
|
115 |
src_node) |
|
116 |
|
|
117 |
if not sinst: |
|
118 |
logger.ToStderr("No secondary instances on node %s, exiting." % src_node) |
|
119 |
return constants.EXIT_SUCCESS |
|
120 |
|
|
121 |
sinst = utils.NiceSort(sinst) |
|
122 |
|
|
123 |
retcode = constants.EXIT_SUCCESS |
|
124 |
|
|
125 |
if not force and not AskUser("Relocate instance(s) %s from node\n" |
|
126 |
" %s to node\n %s?" % |
|
127 |
(",".join("'%s'" % name for name in sinst), |
|
128 |
src_node, dst_node)): |
|
129 |
return constants.EXIT_CONFIRMATION |
|
130 |
|
|
131 |
good_cnt = bad_cnt = 0 |
|
132 |
for iname in sinst: |
|
133 |
op = opcodes.OpReplaceDisks(instance_name=iname, |
|
134 |
remote_node=dst_node) |
|
135 |
try: |
|
136 |
logger.ToStdout("Replacing disks for instance %s" % iname) |
|
137 |
SubmitOpCode(op) |
|
138 |
logger.ToStdout("Instance %s has been relocated" % iname) |
|
139 |
good_cnt += 1 |
|
140 |
except errors.GenericError, err: |
|
141 |
nret, msg = FormatError(err) |
|
142 |
retcode |= nret |
|
143 |
logger.ToStderr("Error replacing disks for instance %s: %s" % |
|
144 |
(iname, msg)) |
|
145 |
bad_cnt += 1 |
|
146 |
|
|
147 |
if retcode == constants.EXIT_SUCCESS: |
|
148 |
logger.ToStdout("All %d instance(s) relocated successfully." % good_cnt) |
|
149 |
else: |
|
150 |
logger.ToStdout("There were errors during the relocation:\n" |
|
151 |
"%d error(s) out of %d instance(s)." % |
|
152 |
(bad_cnt, good_cnt + bad_cnt)) |
|
153 |
return retcode |
|
154 |
|
|
155 |
|
|
97 | 156 |
def FailoverNode(opts, args): |
98 | 157 |
"""Failover all primary instance on a node. |
99 | 158 |
|
... | ... | |
220 | 279 |
help="Specify the secondary ip for the node", |
221 | 280 |
metavar="ADDRESS", default=None),], |
222 | 281 |
"<node_name>", "Add a node to the cluster"), |
282 |
'evacuate': (EvacuateNode, ARGS_FIXED(2), |
|
283 |
[DEBUG_OPT, FORCE_OPT], |
|
284 |
"[-f] <src_node> <dst_node>", |
|
285 |
"Relocate the secondary instances from the first node" |
|
286 |
" to the second one (only for instances of type remote_raid1)"), |
|
223 | 287 |
'failover': (FailoverNode, ARGS_ONE, |
224 | 288 |
[DEBUG_OPT, FORCE_OPT, |
225 | 289 |
make_option("--ignore-consistency", dest="ignore_consistency", |
Also available in: Unified diff