On Thu, Jul 23, 2015 at 07:33:53PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
In this way, OpClusterSetParams will be able to set those
values as well.

Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/WConfd/ConfigModifications.hs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/src/Ganeti/WConfd/ConfigModifications.hs 
b/src/Ganeti/WConfd/ConfigModifications.hs
index 30bd86d..68c6811 100644
--- a/src/Ganeti/WConfd/ConfigModifications.hs
+++ b/src/Ganeti/WConfd/ConfigModifications.hs
@@ -687,6 +687,27 @@ appendMaintdJobs jobs = do
    (\_ cs -> return . addJobs $ cs)
    (return ())

+-- | Set the autobalance flag.
+setMaintdBalance :: Bool -> WConfdMonad Bool
+setMaintdBalance value = do
+  now <- liftIO getClockTime
+  let setFlag = over (csConfigDataL . configMaintenanceL)
+                  $ (serialL +~ 1) . (mTimeL .~ now) . (maintBalanceL .~ value)
+  liftM isJust $ modifyConfigWithLock
+    (\_ cs -> return . setFlag $ cs)
+    (return ())
+
+-- | Set the auto-balance threshold.
+setMaintdBalanceThreshold :: Double -> WConfdMonad Bool
+setMaintdBalanceThreshold value = do
+  now <- liftIO getClockTime
+  let setValue = over (csConfigDataL . configMaintenanceL)
+                   $ (serialL +~ 1) . (mTimeL .~ now)
+                     . (maintBalanceThresholdL .~ value)
+  liftM isJust $ modifyConfigWithLock
+    (\_ cs -> return . setValue $ cs)
+    (return ())
+

Just an idea: this pattern is repeated in several functions in the module, perhaps it'd help to add (in another patch series) some utility function for modifying the configuration this way (using a lens, updating the serial/mtime and returning Bool if it succeeded).

-- * The list of functions exported to RPC.

exportedFunctions :: [Name]
@@ -709,4 +730,6 @@ exportedFunctions = [ 'addInstance
                    , 'setMaintdRoundDelay
                    , 'clearMaintdJobs
                    , 'appendMaintdJobs
+                    , 'setMaintdBalance
+                    , 'setMaintdBalanceThreshold
                    ]
--
2.4.3.573.g4eafbef


LGTM

Reply via email to