On Tue, Jul 14, 2015 at 05:59:21PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
...so that the user can modify it. As usual, we do so with
only a temporary lock acquired by WConfD.

Signed-off-by: Klaus Aehlig <[email protected]>
---
lib/config/__init__.py                   |  5 +++++
src/Ganeti/WConfd/ConfigModifications.hs | 16 ++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/config/__init__.py b/lib/config/__init__.py
index 7b6187f..618a8f6 100644
--- a/lib/config/__init__.py
+++ b/lib/config/__init__.py
@@ -3383,6 +3383,11 @@ class ConfigWriter(object):
      if disk_uuid in inst_info.disks:
        return inst_uuid

+  def SetMaintdRoundDelay(self, delay):
+    """Set the minimal time the maintenance daemon should wait between 
rounds"""
+    utils.SimpleRetry(True, self._wconfd.SetMaintdRoundDelay, 0.1, 30,
+                      args=[delay])
+

class DetachedConfig(ConfigWriter):
  """Read-only snapshot of the config."""
diff --git a/src/Ganeti/WConfd/ConfigModifications.hs 
b/src/Ganeti/WConfd/ConfigModifications.hs
index f724c2e..f643fc3 100644
--- a/src/Ganeti/WConfd/ConfigModifications.hs
+++ b/src/Ganeti/WConfd/ConfigModifications.hs
@@ -42,9 +42,9 @@ module Ganeti.WConfd.ConfigModifications where
import Control.Applicative ((<$>))
import Control.Lens (_2)
import Control.Lens.Getter ((^.))
-import Control.Lens.Setter ((.~), (%~))
+import Control.Lens.Setter ((.~), (%~), (+~), over)
import Control.Lens.Traversal (mapMOf)
-import Control.Monad (unless, when, forM_, foldM, liftM2)
+import Control.Monad (unless, when, forM_, foldM, liftM, liftM2)
import Control.Monad.Error (throwError, MonadError)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.State (StateT, get, put, modify,
@@ -653,6 +653,17 @@ updateDisk disk = do
    . T.releaseDRBDMinors $ uuidOf disk
  return . MaybeForJSON $ fmap (_2 %~ TimeAsDoubleJSON) r

+-- | Set the maintenance intervall.
+setMaintdRoundDelay :: Int -> WConfdMonad Bool
+setMaintdRoundDelay delay = do
+  now <- liftIO getClockTime
+  let setDelay = over (csConfigDataL . configMaintenanceL)
+                   $ (serialL +~ 1) . (mTimeL .~ now)
+                     . (maintRoundDelayL .~ delay)
+  liftM isJust $ modifyConfigWithLock
+    (\_ cs -> return . setDelay $ cs)
+    (return ())
+
-- * The list of functions exported to RPC.

exportedFunctions :: [Name]
@@ -672,4 +683,5 @@ exportedFunctions = [ 'addInstance
                    , 'updateNetwork
                    , 'updateNode
                    , 'updateNodeGroup
+                    , 'setMaintdRoundDelay
                    ]
--
2.4.3.573.g4eafbef


LGTM

Reply via email to