Commit 1b7761fd authored by Apollon Oikonomopoulos's avatar Apollon Oikonomopoulos Committed by Iustin Pop

CLI changes to facilitate shared storage migration/failover

Add DST_NODE_OPT to cli.py to use for directly specifying the target node
during migration/failover.

gnt-instance failover/migrate also get passed an iallocator option.

gnt-node failover/migrate get only a target_node option.
Signed-off-by: default avatarApollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 8eb34306
...@@ -69,6 +69,7 @@ __all__ = [ ...@@ -69,6 +69,7 @@ __all__ = [
"DRAINED_OPT", "DRAINED_OPT",
"DRY_RUN_OPT", "DRY_RUN_OPT",
"DRBD_HELPER_OPT", "DRBD_HELPER_OPT",
"DST_NODE_OPT",
"EARLY_RELEASE_OPT", "EARLY_RELEASE_OPT",
"ENABLED_HV_OPT", "ENABLED_HV_OPT",
"ERROR_CODES_OPT", "ERROR_CODES_OPT",
...@@ -839,6 +840,11 @@ REMOVE_INSTANCE_OPT = cli_option("--remove-instance", dest="remove_instance", ...@@ -839,6 +840,11 @@ REMOVE_INSTANCE_OPT = cli_option("--remove-instance", dest="remove_instance",
action="store_true", default=False, action="store_true", default=False,
help="Remove the instance from the cluster") help="Remove the instance from the cluster")
DST_NODE_OPT = cli_option("-n", "--target-node", dest="dst_node",
help="Specifies the new node for the instance",
metavar="NODE", default=None,
completion_suggest=OPT_COMPL_ONE_NODE)
NEW_SECONDARY_OPT = cli_option("-n", "--new-secondary", dest="dst_node", NEW_SECONDARY_OPT = cli_option("-n", "--new-secondary", dest="dst_node",
help="Specifies the new secondary node", help="Specifies the new secondary node",
metavar="NODE", default=None, metavar="NODE", default=None,
......
...@@ -755,6 +755,12 @@ def FailoverInstance(opts, args): ...@@ -755,6 +755,12 @@ def FailoverInstance(opts, args):
cl = GetClient() cl = GetClient()
instance_name = args[0] instance_name = args[0]
force = opts.force force = opts.force
iallocator = opts.iallocator
target_node = opts.dst_node
if iallocator and target_node:
raise errors.OpPrereqError("Specify either an iallocator (-I), or a target"
" node (-n) but not both", errors.ECODE_INVAL)
if not force: if not force:
_EnsureInstancesExist(cl, [instance_name]) _EnsureInstancesExist(cl, [instance_name])
...@@ -767,7 +773,9 @@ def FailoverInstance(opts, args): ...@@ -767,7 +773,9 @@ def FailoverInstance(opts, args):
op = opcodes.OpInstanceFailover(instance_name=instance_name, op = opcodes.OpInstanceFailover(instance_name=instance_name,
ignore_consistency=opts.ignore_consistency, ignore_consistency=opts.ignore_consistency,
shutdown_timeout=opts.shutdown_timeout) shutdown_timeout=opts.shutdown_timeout,
iallocator=iallocator,
target_node=target_node)
SubmitOrSend(op, opts, cl=cl) SubmitOrSend(op, opts, cl=cl)
return 0 return 0
...@@ -787,6 +795,12 @@ def MigrateInstance(opts, args): ...@@ -787,6 +795,12 @@ def MigrateInstance(opts, args):
cl = GetClient() cl = GetClient()
instance_name = args[0] instance_name = args[0]
force = opts.force force = opts.force
iallocator = opts.iallocator
target_node = opts.dst_node
if iallocator and target_node:
raise errors.OpPrereqError("Specify either an iallocator (-I), or a target"
" node (-n) but not both", errors.ECODE_INVAL)
if not force: if not force:
_EnsureInstancesExist(cl, [instance_name]) _EnsureInstancesExist(cl, [instance_name])
...@@ -814,7 +828,8 @@ def MigrateInstance(opts, args): ...@@ -814,7 +828,8 @@ def MigrateInstance(opts, args):
mode = opts.migration_mode mode = opts.migration_mode
op = opcodes.OpInstanceMigrate(instance_name=instance_name, mode=mode, op = opcodes.OpInstanceMigrate(instance_name=instance_name, mode=mode,
cleanup=opts.cleanup) cleanup=opts.cleanup, iallocator=iallocator,
target_node=target_node)
SubmitOpCode(op, cl=cl, opts=opts) SubmitOpCode(op, cl=cl, opts=opts)
return 0 return 0
...@@ -1344,15 +1359,15 @@ commands = { ...@@ -1344,15 +1359,15 @@ commands = {
'failover': ( 'failover': (
FailoverInstance, ARGS_ONE_INSTANCE, FailoverInstance, ARGS_ONE_INSTANCE,
[FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT, SHUTDOWN_TIMEOUT_OPT, [FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT, SHUTDOWN_TIMEOUT_OPT,
DRY_RUN_OPT, PRIORITY_OPT], DRY_RUN_OPT, PRIORITY_OPT, DST_NODE_OPT, IALLOCATOR_OPT],
"[-f] <instance>", "Stops the instance and starts it on the backup node," "[-f] <instance>", "Stops the instance and starts it on the backup node,"
" using the remote mirror (only for instances of type drbd)"), " using the remote mirror (only for mirrored instances)"),
'migrate': ( 'migrate': (
MigrateInstance, ARGS_ONE_INSTANCE, MigrateInstance, ARGS_ONE_INSTANCE,
[FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, CLEANUP_OPT, DRY_RUN_OPT, [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, CLEANUP_OPT, DRY_RUN_OPT,
PRIORITY_OPT], PRIORITY_OPT, DST_NODE_OPT, IALLOCATOR_OPT],
"[-f] <instance>", "Migrate instance to its secondary node" "[-f] <instance>", "Migrate instance to its secondary node"
" (only for instances of type drbd)"), " (only for mirrored instances)"),
'move': ( 'move': (
MoveInstance, ARGS_ONE_INSTANCE, MoveInstance, ARGS_ONE_INSTANCE,
[FORCE_OPT, SUBMIT_OPT, SINGLE_NODE_OPT, SHUTDOWN_TIMEOUT_OPT, [FORCE_OPT, SUBMIT_OPT, SINGLE_NODE_OPT, SHUTDOWN_TIMEOUT_OPT,
......
...@@ -338,7 +338,8 @@ def FailoverNode(opts, args): ...@@ -338,7 +338,8 @@ def FailoverNode(opts, args):
jex = JobExecutor(cl=cl, opts=opts) jex = JobExecutor(cl=cl, opts=opts)
for iname in pinst: for iname in pinst:
op = opcodes.OpInstanceFailover(instance_name=iname, op = opcodes.OpInstanceFailover(instance_name=iname,
ignore_consistency=opts.ignore_consistency) ignore_consistency=opts.ignore_consistency,
iallocator=opts.iallocator)
jex.QueueJob(iname, op) jex.QueueJob(iname, op)
results = jex.GetResults() results = jex.GetResults()
bad_cnt = len([row for row in results if not row[0]]) bad_cnt = len([row for row in results if not row[0]])
...@@ -380,7 +381,8 @@ def MigrateNode(opts, args): ...@@ -380,7 +381,8 @@ def MigrateNode(opts, args):
mode = constants.HT_MIGRATION_NONLIVE mode = constants.HT_MIGRATION_NONLIVE
else: else:
mode = opts.migration_mode mode = opts.migration_mode
op = opcodes.OpNodeMigrate(node_name=args[0], mode=mode) op = opcodes.OpNodeMigrate(node_name=args[0], mode=mode,
iallocator=opts.iallocator)
SubmitOpCode(op, cl=cl, opts=opts) SubmitOpCode(op, cl=cl, opts=opts)
...@@ -815,13 +817,15 @@ commands = { ...@@ -815,13 +817,15 @@ commands = {
"Relocate the secondary instances from a node" "Relocate the secondary instances from a node"
" to other nodes (only for instances with drbd disk template)"), " to other nodes (only for instances with drbd disk template)"),
'failover': ( 'failover': (
FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT, PRIORITY_OPT], FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT,
IALLOCATOR_OPT, PRIORITY_OPT],
"[-f] <node>", "[-f] <node>",
"Stops the primary instances on a node and start them on their" "Stops the primary instances on a node and start them on their"
" secondary node (only for instances with drbd disk template)"), " secondary node (only for instances with drbd disk template)"),
'migrate': ( 'migrate': (
MigrateNode, ARGS_ONE_NODE, MigrateNode, ARGS_ONE_NODE,
[FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, PRIORITY_OPT], [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT,
IALLOCATOR_OPT, PRIORITY_OPT],
"[-f] <node>", "[-f] <node>",
"Migrate all the primary instance on a node away from it" "Migrate all the primary instance on a node away from it"
" (only for instances of type drbd)"), " (only for instances of type drbd)"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment