Revision 7dc27988 src/Ganeti/Confd/Client.hs
b/src/Ganeti/Confd/Client.hs | ||
---|---|---|
31 | 31 |
import Control.Concurrent |
32 | 32 |
import Control.Monad |
33 | 33 |
import Data.List |
34 |
import Data.Maybe |
|
34 | 35 |
import qualified Network.Socket as S |
35 | 36 |
import System.Posix.Time |
36 | 37 |
import qualified Text.JSON as J |
... | ... | |
42 | 43 |
import Ganeti.Hash |
43 | 44 |
import Ganeti.Ssconf |
44 | 45 |
|
45 |
-- | Builds a properly initialized ConfdClient |
|
46 |
getConfdClient :: IO ConfdClient |
|
47 |
getConfdClient = S.withSocketsDo $ do |
|
46 |
-- | Builds a properly initialized ConfdClient. |
|
47 |
-- The parameters (an IP address and the port number for the Confd client |
|
48 |
-- to connect to) are mainly meant for testing purposes. If they are not |
|
49 |
-- provided, the list of master candidates and the default port number will |
|
50 |
-- be used. |
|
51 |
getConfdClient :: Maybe String -> Maybe Int -> IO ConfdClient |
|
52 |
getConfdClient addr portNum = S.withSocketsDo $ do |
|
48 | 53 |
hmac <- getClusterHmac |
49 | 54 |
candList <- getMasterCandidatesIps Nothing |
50 | 55 |
peerList <- |
51 | 56 |
case candList of |
52 | 57 |
(Ok p) -> return p |
53 | 58 |
(Bad msg) -> fail msg |
54 |
return . ConfdClient hmac peerList $ fromIntegral C.defaultConfdPort |
|
59 |
let addrList = maybe peerList (:[]) addr |
|
60 |
port = fromMaybe C.defaultConfdPort portNum |
|
61 |
return . ConfdClient hmac addrList $ fromIntegral port |
|
55 | 62 |
|
56 | 63 |
-- | Sends a query to all the Confd servers the client is connected to. |
57 | 64 |
-- Returns the most up-to-date result according to the serial number, |
Also available in: Unified diff