From d70e204019223f154520ef5ed5e95ff01c1337b4 Mon Sep 17 00:00:00 2001
From: Buildbot <synnefo@builder.dev.grnet.gr>
Date: Mon, 1 Sep 2014 13:05:37 +0300
Subject: [PATCH] cyclades: Add GANETI_DISKS_WAIT_FOR_SYNC option

Add new setting to denote whether Ganeti will wait for the disk mirror to
sync (DRBD). This setting is used when creating a new instance or adding
a new disk to an existing Ganeti instance.
---
 Changelog                                                | 2 ++
 snf-cyclades-app/conf/20-snf-cyclades-app-backend.conf   | 6 +++++-
 snf-cyclades-app/synnefo/app_settings/default/backend.py | 6 +++++-
 snf-cyclades-app/synnefo/logic/backend.py                | 4 ++++
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Changelog b/Changelog
index 73f49ae3c..0bd53a728 100644
--- a/Changelog
+++ b/Changelog
@@ -164,6 +164,8 @@ Cyclades
   are drained.
 * Fix the'network-inspect' command to not contain externally reserved IPs
   in th number of available IPs.
+* Add `GANETI_DISKS_WAIT_FOR_SYNC` setting to decide whether Ganeti will
+  wait for the disk mirror to sync (`--no-wait-for-sync` Ganeti option).
 * Fix mishandling of `MAX_CIDR_BLOCK` setting. Allowed CIDR sizes
   changed from (MAX_CIDR_BLOCK, 29) to [MAX_CIDR_BLOCK, 29].
 * Fix various minor bugs.
diff --git a/snf-cyclades-app/conf/20-snf-cyclades-app-backend.conf b/snf-cyclades-app/conf/20-snf-cyclades-app-backend.conf
index 778594e15..1d9fbb639 100644
--- a/snf-cyclades-app/conf/20-snf-cyclades-app-backend.conf
+++ b/snf-cyclades-app/conf/20-snf-cyclades-app-backend.conf
@@ -27,7 +27,7 @@
 #    'hvparams': {'kvm': {'serial_console': False},
 #                 'xen-pvm': {},
 #                 'xen-hvm': {}},
-#    'wait_for_sync': False}
+#}
 #
 ## If True, qemu-kvm will hotplug a NIC when connecting a vm to
 ## a network. This requires qemu-kvm=1.0.
@@ -37,6 +37,10 @@
 ## not already locked. This might result in slightly unbalanced clusters.
 #GANETI_USE_OPPORTUNISTIC_LOCKING = True
 #
+## If False, Ganeti will not wait for the disk mirror to sync
+## (--no-wait-for-sync option in Ganeti). Useful only for DRBD template.
+#GANETI_DISKS_WAIT_FOR_SYNC = False
+#
 ## This module implements the strategy for allocating a vm to a backend
 #BACKEND_ALLOCATOR_MODULE = "synnefo.logic.allocators.default_allocator"
 ## Refresh backend statistics timeout, in minutes, used in backend allocation
diff --git a/snf-cyclades-app/synnefo/app_settings/default/backend.py b/snf-cyclades-app/synnefo/app_settings/default/backend.py
index 26d35b1bf..16b2adf55 100644
--- a/snf-cyclades-app/synnefo/app_settings/default/backend.py
+++ b/snf-cyclades-app/synnefo/app_settings/default/backend.py
@@ -27,7 +27,7 @@ GANETI_CREATEINSTANCE_KWARGS = {
     'hvparams': {"kvm": {'serial_console': False},
                  "xen-pvm": {},
                  "xen-hvm": {}},
-    'wait_for_sync': False}
+}
 
 # If True, qemu-kvm will hotplug a NIC when connecting a vm to
 # a network. This requires qemu-kvm=1.0.
@@ -37,6 +37,10 @@ GANETI_USE_HOTPLUG = True
 # not already locked. This might result in slightly unbalanced clusters.
 GANETI_USE_OPPORTUNISTIC_LOCKING = True
 
+# If False, Ganeti will not wait for the disk mirror to sync
+# (--no-wait-for-sync option in Ganeti). Useful only for DRBD template.
+GANETI_DISKS_WAIT_FOR_SYNC = False
+
 # This module implements the strategy for allocating a vm to a backend
 BACKEND_ALLOCATOR_MODULE = "synnefo.logic.allocators.default_allocator"
 # Refresh backend statistics timeout, in minutes, used in backend allocation
diff --git a/snf-cyclades-app/synnefo/logic/backend.py b/snf-cyclades-app/synnefo/logic/backend.py
index ad2c287de..a9e721a03 100644
--- a/snf-cyclades-app/synnefo/logic/backend.py
+++ b/snf-cyclades-app/synnefo/logic/backend.py
@@ -808,6 +808,9 @@ def create_instance(vm, nics, volumes, flavor, image):
 
     kw["disks"] = disks
 
+    # --no-wait-for-sync option for DRBD disks
+    kw["wait_for_sync"] = settings.GANETI_DISKS_WAIT_FOR_SYNC
+
     kw['nics'] = [{"name": nic.backend_uuid,
                    "network": nic.network.backend_id,
                    "ip": nic.ipv4_address}
@@ -1216,6 +1219,7 @@ def attach_volume(vm, volume, depends=[]):
     kwargs = {
         "instance": vm.backend_vm_id,
         "disks": [("add", "-1", disk)],
+        "wait_for_sync": settings.GANETI_DISKS_WAIT_FOR_SYNC,
         "depends": depends,
     }
     if vm.backend.use_hotplug():
-- 
GitLab