From: Apollon Oikonomopoulos <[email protected]>

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: Apollon Oikonomopoulos <[email protected]>
---
 lib/cli.py           |    6 ++++++
 scripts/gnt-instance |   28 ++++++++++++++++++++++------
 scripts/gnt-node     |   11 +++++++----
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index 90c64e0..21934a3 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -61,6 +61,7 @@ __all__ = [
   "DISK_OPT",
   "DISK_TEMPLATE_OPT",
   "DRAINED_OPT",
+  "DST_NODE_OPT",
   "EARLY_RELEASE_OPT",
   "ENABLED_HV_OPT",
   "ERROR_CODES_OPT",
@@ -747,6 +748,11 @@ REMOVE_INSTANCE_OPT = cli_option("--remove-instance", 
dest="remove_instance",
                                  action="store_true", default=False,
                                  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",
                                help="Specifies the new secondary node",
                                metavar="NODE", default=None,
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 710fb4d..c02abc7 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -836,6 +836,12 @@ def FailoverInstance(opts, args):
   cl = GetClient()
   instance_name = args[0]
   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:
     _EnsureInstancesExist(cl, [instance_name])
@@ -848,7 +854,9 @@ def FailoverInstance(opts, args):
 
   op = opcodes.OpFailoverInstance(instance_name=instance_name,
                                   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)
   return 0
 
@@ -868,6 +876,12 @@ def MigrateInstance(opts, args):
   cl = GetClient()
   instance_name = args[0]
   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:
     _EnsureInstancesExist(cl, [instance_name])
@@ -885,7 +899,8 @@ def MigrateInstance(opts, args):
       return 1
 
   op = opcodes.OpMigrateInstance(instance_name=instance_name, live=opts.live,
-                                 cleanup=opts.cleanup)
+                                 cleanup=opts.cleanup, iallocator=iallocator,
+                                 target_node=target_node)
   SubmitOpCode(op, cl=cl, opts=opts)
   return 0
 
@@ -1378,14 +1393,15 @@ commands = {
     "[--show-cmd] <instance>", "Opens a console on the specified instance"),
   'failover': (
     FailoverInstance, ARGS_ONE_INSTANCE,
-    [FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT, SHUTDOWN_TIMEOUT_OPT],
+    [FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT, SHUTDOWN_TIMEOUT_OPT,
+     DST_NODE_OPT, IALLOCATOR_OPT],
     "[-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': (
     MigrateInstance, ARGS_ONE_INSTANCE,
-    [FORCE_OPT, NONLIVE_OPT, CLEANUP_OPT],
+    [FORCE_OPT, NONLIVE_OPT, CLEANUP_OPT, DST_NODE_OPT, IALLOCATOR_OPT],
     "[-f] <instance>", "Migrate instance to its secondary node"
-    " (only for instances of type drbd)"),
+    " (only for mirrored instances)"),
   'move': (
     MoveInstance, ARGS_ONE_INSTANCE,
     [FORCE_OPT, SUBMIT_OPT, SINGLE_NODE_OPT, SHUTDOWN_TIMEOUT_OPT],
diff --git a/scripts/gnt-node b/scripts/gnt-node
index 9e96248..a8f801c 100755
--- a/scripts/gnt-node
+++ b/scripts/gnt-node
@@ -331,7 +331,8 @@ def FailoverNode(opts, args):
   jex = JobExecutor(cl=cl, opts=opts)
   for iname in pinst:
     op = opcodes.OpFailoverInstance(instance_name=iname,
-                                    ignore_consistency=opts.ignore_consistency)
+                                    ignore_consistency=opts.ignore_consistency,
+                                    iallocator=opts.iallocator)
     jex.QueueJob(iname, op)
   results = jex.GetResults()
   bad_cnt = len([row for row in results if not row[0]])
@@ -364,7 +365,8 @@ def MigrateNode(opts, args):
                                (",".join("'%s'" % name for name in pinst))):
     return 2
 
-  op = opcodes.OpMigrateNode(node_name=args[0], live=opts.live)
+  op = opcodes.OpMigrateNode(node_name=args[0], live=opts.live,
+                              iallocator=opts.iallocator)
   SubmitOpCode(op, cl=cl, opts=opts)
 
 
@@ -651,12 +653,13 @@ commands = {
     "Relocate the secondary instances from a node"
     " to other nodes (only for instances with drbd disk template)"),
   'failover': (
-    FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT],
+    FailoverNode, ARGS_ONE_NODE,
+    [FORCE_OPT, IGNORE_CONSIST_OPT, IALLOCATOR_OPT],
     "[-f] <node>",
     "Stops the primary instances on a node and start them on their"
     " secondary node (only for instances with drbd disk template)"),
   'migrate': (
-    MigrateNode, ARGS_ONE_NODE, [FORCE_OPT, NONLIVE_OPT],
+    MigrateNode, ARGS_ONE_NODE, [FORCE_OPT, NONLIVE_OPT, IALLOCATOR_OPT],
     "[-f] <node>",
     "Migrate all the primary instance on a node away from it"
     " (only for instances of type drbd)"),
-- 
1.7.1

Reply via email to