Commit c119f0bd authored by Klaus Aehlig's avatar Klaus Aehlig

Add routines to manipulate the jobs list for maintd

In this way, the maintenance daemon can update the jobs part
of its state, while complying with the requirement that all its
state be stored in the configuration (and hence, also sufficiently
replicated).
Signed-off-by: 's avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: 's avatarPetr Pudlak <pudlak@google.com>
parent 517490d7
......@@ -67,7 +67,8 @@ import Ganeti.Locking.Locks (ClientId, ciIdentifier)
import Ganeti.Logging.Lifted (logDebug, logInfo)
import Ganeti.Objects
import Ganeti.Objects.Lens
import Ganeti.Types (AdminState, AdminStateSource)
import Ganeti.Types (AdminState, AdminStateSource, JobId)
import Ganeti.Utils (ordNub)
import Ganeti.WConfd.ConfigState (ConfigState, csConfigData, csConfigDataL)
import Ganeti.WConfd.Monad (WConfdMonad, modifyConfigWithLock
, modifyConfigAndReturnWithLock)
......@@ -664,6 +665,28 @@ setMaintdRoundDelay delay = do
(\_ cs -> return . setDelay $ cs)
(return ())
-- | Clear the list of current maintenance jobs.
clearMaintdJobs :: WConfdMonad Bool
clearMaintdJobs = do
now <- liftIO getClockTime
let clear = over (csConfigDataL . configMaintenanceL)
$ (serialL +~ 1) . (mTimeL .~ now) . (maintJobsL .~ [])
liftM isJust $ modifyConfigWithLock
(\_ cs -> return . clear $ cs)
(return ())
-- | Append new jobs to the list of current maintenace jobs, if
-- not alread present.
appendMaintdJobs :: [JobId] -> WConfdMonad Bool
appendMaintdJobs jobs = do
now <- liftIO getClockTime
let addJobs = over (csConfigDataL . configMaintenanceL)
$ (serialL +~ 1) . (mTimeL .~ now)
. over maintJobsL (ordNub . (++ jobs))
liftM isJust $ modifyConfigWithLock
(\_ cs -> return . addJobs $ cs)
(return ())
-- * The list of functions exported to RPC.
exportedFunctions :: [Name]
......@@ -684,4 +707,6 @@ exportedFunctions = [ 'addInstance
, 'updateNode
, 'updateNodeGroup
, 'setMaintdRoundDelay
, 'clearMaintdJobs
, 'appendMaintdJobs
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment