...so that other daemons can use this functionality as well, without the need to duplicate code.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/Daemon/Utils.hs | 25 ++++++++++++++++++++++++- src/Ganeti/Query/Server.hs | 19 ++----------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Ganeti/Daemon/Utils.hs b/src/Ganeti/Daemon/Utils.hs index 1f86e51..0d537a8 100644 --- a/src/Ganeti/Daemon/Utils.hs +++ b/src/Ganeti/Daemon/Utils.hs @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.Daemon.Utils ( verifyMaster + , handleMasterVerificationOptions ) where import Control.Concurrent (threadDelay) @@ -32,11 +33,12 @@ import Control.Monad (unless) import Data.Either (rights) import qualified Data.Foldable as F import Data.List (partition) +import System.Exit (ExitCode(..)) import Ganeti.BasicTypes import qualified Ganeti.Config as Config import qualified Ganeti.Constants as C -import Ganeti.Daemon (getFQDN) +import Ganeti.Daemon (getFQDN, DaemonOptions, optNoVoting, optYesDoIt) import Ganeti.Logging import Ganeti.Objects import qualified Ganeti.Path as Path @@ -83,3 +85,24 @@ verifyMaster retries = runResultT $ do liftIO $ logDebug "Voting not final due to missing votes." liftIO . threadDelay $ C.masterVotingRetryIntervall * 1000000 mkResultT $ verifyMaster (retries - 1) + +-- | Verify master position according to the options provided, usually +-- by carrying out a voting. Either return unit on success, or a suggested +-- exit code. +handleMasterVerificationOptions :: DaemonOptions -> IO (Either ExitCode ()) +handleMasterVerificationOptions opts = + if optNoVoting opts + then if optYesDoIt opts + then return $ Right () + else do + logError "The no-voting option is dangerous and cannot be\ + \ given without providing yes-do-it as well." + return . Left $ ExitFailure C.exitFailure + else do + masterStatus <- verifyMaster C.masterVotingRetries + case masterStatus of + Bad s -> do + logError $ "Failed to verify master status: " ++ s + return . Left $ ExitFailure C.exitFailure + Ok _ -> return $ Right () + diff --git a/src/Ganeti/Query/Server.hs b/src/Ganeti/Query/Server.hs index 70b1574..bddcd06 100644 --- a/src/Ganeti/Query/Server.hs +++ b/src/Ganeti/Query/Server.hs @@ -44,7 +44,6 @@ import qualified Text.JSON as J import Text.JSON (encode, showJSON, JSValue(..)) import System.Info (arch) import System.Directory -import System.Exit (ExitCode(..)) import System.Posix.Signals as P import qualified Ganeti.Constants as C @@ -52,7 +51,7 @@ import qualified Ganeti.ConstantUtils as ConstantUtils (unFrozenSet) import Ganeti.Errors import qualified Ganeti.Path as Path import Ganeti.Daemon -import Ganeti.Daemon.Utils (verifyMaster) +import Ganeti.Daemon.Utils (handleMasterVerificationOptions) import Ganeti.Objects import qualified Ganeti.Config as Config import Ganeti.ConfigReader @@ -449,21 +448,7 @@ activateMasterIP = runResultT $ do -- | Check function for luxid. checkMain :: CheckFn () -checkMain opts = - if optNoVoting opts - then if optYesDoIt opts - then return $ Right () - else do - logError "The no-voting option is dangerous and cannot be\ - \ given without providing yes-do-it as well." - return . Left $ ExitFailure C.exitFailure - else do - masterStatus <- verifyMaster C.masterVotingRetries - case masterStatus of - Bad s -> do - logError $ "Failed to verify master status: " ++ s - return . Left $ ExitFailure C.exitFailure - Ok _ -> return $ Right () +checkMain = handleMasterVerificationOptions -- | Prepare function for luxid. prepMain :: PrepFn () PrepResult -- 1.9.1.423.g4596e3a
