Revision 479636a3 scripts/gnt-node
b/scripts/gnt-node | ||
---|---|---|
167 | 167 |
@return: the desired exit code |
168 | 168 |
|
169 | 169 |
""" |
170 |
cl = GetClient() |
|
170 | 171 |
force = opts.force |
171 | 172 |
selected_fields = ["name", "sinst_list"] |
172 | 173 |
src_node, dst_node = args |
173 | 174 |
|
174 | 175 |
op = opcodes.OpQueryNodes(output_fields=selected_fields, names=[src_node]) |
175 |
result = SubmitOpCode(op) |
|
176 |
result = SubmitOpCode(op, cl=cl)
|
|
176 | 177 |
src_node, sinst = result[0] |
177 | 178 |
op = opcodes.OpQueryNodes(output_fields=["name"], names=[dst_node]) |
178 |
result = SubmitOpCode(op) |
|
179 |
result = SubmitOpCode(op, cl=cl)
|
|
179 | 180 |
dst_node = result[0][0] |
180 | 181 |
|
181 | 182 |
if src_node == dst_node: |
... | ... | |
189 | 190 |
|
190 | 191 |
sinst = utils.NiceSort(sinst) |
191 | 192 |
|
192 |
retcode = constants.EXIT_SUCCESS |
|
193 |
|
|
194 | 193 |
if not force and not AskUser("Relocate instance(s) %s from node\n" |
195 | 194 |
" %s to node\n %s?" % |
196 | 195 |
(",".join("'%s'" % name for name in sinst), |
197 | 196 |
src_node, dst_node)): |
198 | 197 |
return constants.EXIT_CONFIRMATION |
199 | 198 |
|
200 |
good_cnt = bad_cnt = 0
|
|
199 |
jex = JobExecutor()
|
|
201 | 200 |
for iname in sinst: |
202 | 201 |
op = opcodes.OpReplaceDisks(instance_name=iname, |
203 | 202 |
remote_node=dst_node, |
204 |
mode=constants.REPLACE_DISK_ALL, |
|
205 |
disks=["sda", "sdb"]) |
|
206 |
try: |
|
207 |
ToStdout("Replacing disks for instance %s", iname) |
|
208 |
SubmitOpCode(op) |
|
209 |
ToStdout("Instance %s has been relocated", iname) |
|
210 |
good_cnt += 1 |
|
211 |
except errors.GenericError, err: |
|
212 |
nret, msg = FormatError(err) |
|
213 |
retcode |= nret |
|
214 |
ToStderr("Error replacing disks for instance %s: %s", iname, msg) |
|
215 |
bad_cnt += 1 |
|
216 |
|
|
217 |
if retcode == constants.EXIT_SUCCESS: |
|
218 |
ToStdout("All %d instance(s) relocated successfully.", good_cnt) |
|
203 |
mode=constants.REPLACE_DISK_CHG, |
|
204 |
disks=[]) |
|
205 |
jex.QueueJob(iname, op) |
|
206 |
|
|
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 |
|
219 | 213 |
else: |
220 | 214 |
ToStdout("There were errors during the relocation:\n" |
221 |
"%d error(s) out of %d instance(s).", bad_cnt, good_cnt + bad_cnt) |
|
215 |
"%d error(s) out of %d instance(s).", bad_cnt, len(results)) |
|
216 |
retcode = constants.EXIT_FAILURE |
|
222 | 217 |
return retcode |
223 | 218 |
|
224 | 219 |
|
... | ... | |
232 | 227 |
@return: the desired exit code |
233 | 228 |
|
234 | 229 |
""" |
230 |
cl = GetClient() |
|
235 | 231 |
force = opts.force |
236 | 232 |
selected_fields = ["name", "pinst_list"] |
237 | 233 |
|
238 | 234 |
op = opcodes.OpQueryNodes(output_fields=selected_fields, names=args) |
239 |
result = SubmitOpCode(op) |
|
235 |
result = SubmitOpCode(op, cl=cl)
|
|
240 | 236 |
node, pinst = result[0] |
241 | 237 |
|
242 | 238 |
if not pinst: |
... | ... | |
251 | 247 |
(",".join("'%s'" % name for name in pinst))): |
252 | 248 |
return 2 |
253 | 249 |
|
254 |
good_cnt = bad_cnt = 0
|
|
250 |
jex = JobExecutor(cl=cl)
|
|
255 | 251 |
for iname in pinst: |
256 | 252 |
op = opcodes.OpFailoverInstance(instance_name=iname, |
257 | 253 |
ignore_consistency=opts.ignore_consistency) |
258 |
try: |
|
259 |
ToStdout("Failing over instance %s", iname) |
|
260 |
SubmitOpCode(op) |
|
261 |
ToStdout("Instance %s has been failed over", iname) |
|
262 |
good_cnt += 1 |
|
263 |
except errors.GenericError, err: |
|
264 |
nret, msg = FormatError(err) |
|
265 |
retcode |= nret |
|
266 |
ToStderr("Error failing over instance %s: %s", iname, msg) |
|
267 |
bad_cnt += 1 |
|
268 |
|
|
269 |
if retcode == 0: |
|
270 |
ToStdout("All %d instance(s) failed over successfully.", good_cnt) |
|
254 |
jex.QueueJob(iname, op) |
|
255 |
results = jex.GetResults() |
|
256 |
bad_cnt = len([row for row in results if not row[0]]) |
|
257 |
if bad_cnt == 0: |
|
258 |
ToStdout("All %d instance(s) failed over successfully.", len(results)) |
|
271 | 259 |
else: |
272 | 260 |
ToStdout("There were errors during the failover:\n" |
273 |
"%d error(s) out of %d instance(s).", bad_cnt, good_cnt + bad_cnt)
|
|
261 |
"%d error(s) out of %d instance(s).", bad_cnt, len(results))
|
|
274 | 262 |
return retcode |
275 | 263 |
|
276 | 264 |
|
Also available in: Unified diff