From f30d8165917cc9278f8847362d0768b71ce88f0d Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 5 Jul 2012 15:27:02 +0200
Subject: [PATCH] Add --wait-for-sync in gnt-instance
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Note that this needs (like for the opcode) a new option, with the
default reverted (False instead of True).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 lib/cli.py                 | 5 +++++
 lib/client/gnt_instance.py | 5 +++--
 man/gnt-instance.rst       | 9 ++++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index feb0fe41a..63642e1d3 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -195,6 +195,7 @@ __all__ = [
   "USE_REPL_NET_OPT",
   "VERBOSE_OPT",
   "VG_NAME_OPT",
+  "WFSYNC_OPT",
   "YES_DOIT_OPT",
   "DISK_STATE_OPT",
   "HV_STATE_OPT",
@@ -747,6 +748,10 @@ NWSYNC_OPT = cli_option("--no-wait-for-sync", dest="wait_for_sync",
                         default=True, action="store_false",
                         help="Don't wait for sync (DANGEROUS!)")
 
+WFSYNC_OPT = cli_option("--wait-for-sync", dest="wait_for_sync",
+                        default=False, action="store_true",
+                        help="Wait for disks to sync")
+
 ONLINE_INST_OPT = cli_option("--online", dest="online_inst",
                              action="store_true", default=False,
                              help="Enable offline instance")
diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py
index c6dfd69e3..819bd5740 100644
--- a/lib/client/gnt_instance.py
+++ b/lib/client/gnt_instance.py
@@ -566,7 +566,8 @@ def ActivateDisks(opts, args):
   """
   instance_name = args[0]
   op = opcodes.OpInstanceActivateDisks(instance_name=instance_name,
-                                       ignore_size=opts.ignore_size)
+                                       ignore_size=opts.ignore_size,
+                                       wait_for_sync=opts.wait_for_sync)
   disks_info = SubmitOrSend(op, opts)
   for host, iname, nname in disks_info:
     ToStdout("%s:%s:%s", host, iname, nname)
@@ -1620,7 +1621,7 @@ commands = {
     "<instance>", "Reboots an instance"),
   "activate-disks": (
     ActivateDisks, ARGS_ONE_INSTANCE,
-    [SUBMIT_OPT, IGNORE_SIZE_OPT, PRIORITY_OPT],
+    [SUBMIT_OPT, IGNORE_SIZE_OPT, PRIORITY_OPT, WFSYNC_OPT],
     "<instance>", "Activate an instance's disks"),
   "deactivate-disks": (
     DeactivateDisks, ARGS_ONE_INSTANCE,
diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst
index 77bec0d54..b71643a15 100644
--- a/man/gnt-instance.rst
+++ b/man/gnt-instance.rst
@@ -1301,7 +1301,7 @@ options.
 ACTIVATE-DISKS
 ^^^^^^^^^^^^^^
 
-**activate-disks** [\--submit] [\--ignore-size] {*instance*}
+**activate-disks** [\--submit] [\--ignore-size] [\--wait-for-sync] {*instance*}
 
 Activates the block devices of the given instance. If successful, the
 command will show the location and name of the block devices::
@@ -1323,6 +1323,13 @@ where the configuration has gotten out of sync with the real-world
 in LVM devices). This should not be used in normal cases, but only
 when activate-disks fails without it.
 
+The ``--wait-for-sync`` option will ensure that the command returns only
+after the instance's disks are synchronised (mostly for DRBD); this can
+be useful to ensure consistency, as otherwise there are no commands that
+can wait until synchronisation is done. However when passing this
+option, the command will have additional output, making it harder to
+parse the disk information.
+
 Note that it is safe to run this command while the instance is already
 running.
 
-- 
GitLab