Commit 65c75276 authored by Klaus Aehlig's avatar Klaus Aehlig

Add a utility to run an Rpc call in a new WConfD client

...that takes care of creating and closing the client
properly.
Signed-off-by: 's avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: 's avatarPetr Pudlak <pudlak@google.com>
parent a803622f
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskell, FlexibleContexts #-}
{-| The Ganeti WConfd client functions.
......@@ -39,13 +39,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module Ganeti.WConfd.Client where
import Control.Exception.Lifted (bracket)
import Control.Monad (unless)
import Control.Monad.Base
import Control.Monad.Error (MonadError)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Control (MonadBaseControl)
import Ganeti.THH.HsRPC
import Ganeti.Constants
import Ganeti.Errors (GanetiException)
import Ganeti.JSON (unMaybeForJSON)
import Ganeti.Locking.Locks (ClientId)
import Ganeti.Objects (ConfigData)
import Ganeti.UDSServer (ConnectConfig(..), Client, connectClient)
import qualified Ganeti.Path as Path
import Ganeti.THH.HsRPC
import Ganeti.UDSServer (ConnectConfig(..), Client, connectClient, closeClient)
import Ganeti.WConfd.Core (exportedFunctions)
-- * Generated client functions
......@@ -65,6 +73,15 @@ wconfdConnectConfig = ConnectConfig { recvTmo = wconfdDefRwto
getWConfdClient :: FilePath -> IO Client
getWConfdClient = connectClient wconfdConnectConfig wconfdDefCtmo
-- | Run an Rpc with a fresh client.
runNewWConfdClient :: ( MonadBase IO m, MonadBaseControl IO m
, MonadError GanetiException m )
=> RpcClientMonad a -> m a
runNewWConfdClient request =
bracket (liftBase (Path.defaultWConfdSocket >>= getWConfdClient))
(liftBase . closeClient)
$ runRpcClient request
-- * Helper functions for getting a remote lock
-- | Calls the `lockConfig` RPC until the lock is obtained.
......
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