diff --git a/src/Ganeti/Confd/Client.hs b/src/Ganeti/Confd/Client.hs index 78a782024164bbb94fa7dc06a01a89661d7a259a..d7a5ea048ea67fce1c4f7cdd76ef1297333a4c92 100644 --- a/src/Ganeti/Confd/Client.hs +++ b/src/Ganeti/Confd/Client.hs @@ -31,6 +31,7 @@ module Ganeti.Confd.Client import Control.Concurrent import Control.Monad import Data.List +import Data.Maybe import qualified Network.Socket as S import System.Posix.Time import qualified Text.JSON as J @@ -42,16 +43,22 @@ import qualified Ganeti.Constants as C import Ganeti.Hash import Ganeti.Ssconf --- | Builds a properly initialized ConfdClient -getConfdClient :: IO ConfdClient -getConfdClient = S.withSocketsDo $ do +-- | Builds a properly initialized ConfdClient. +-- The parameters (an IP address and the port number for the Confd client +-- to connect to) are mainly meant for testing purposes. If they are not +-- provided, the list of master candidates and the default port number will +-- be used. +getConfdClient :: Maybe String -> Maybe Int -> IO ConfdClient +getConfdClient addr portNum = S.withSocketsDo $ do hmac <- getClusterHmac candList <- getMasterCandidatesIps Nothing peerList <- case candList of (Ok p) -> return p (Bad msg) -> fail msg - return . ConfdClient hmac peerList $ fromIntegral C.defaultConfdPort + let addrList = maybe peerList (:[]) addr + port = fromMaybe C.defaultConfdPort portNum + return . ConfdClient hmac addrList $ fromIntegral port -- | Sends a query to all the Confd servers the client is connected to. -- Returns the most up-to-date result according to the serial number, diff --git a/src/Ganeti/DataCollectors/CLI.hs b/src/Ganeti/DataCollectors/CLI.hs index c793078079ad69205e16322b73eb8a04925336c2..3c58a3f09babea5c777498c45f76d9a6abc34456 100644 --- a/src/Ganeti/DataCollectors/CLI.hs +++ b/src/Ganeti/DataCollectors/CLI.hs @@ -36,6 +36,9 @@ module Ganeti.DataCollectors.CLI , oShowComp , oDrbdPairing , oDrbdStatus + , oNode + , oConfdAddr + , oConfdPort , genericOptions ) where @@ -43,6 +46,8 @@ import System.Console.GetOpt import Ganeti.BasicTypes import Ganeti.Common as Common +import Ganeti.Utils + -- * Data types @@ -55,6 +60,10 @@ data Options = Options -- status information , optDrbdPairing :: Maybe FilePath -- ^ Path to the file containing pairings -- between instances and DRBD minors + , optNode :: Maybe String -- ^ Info are requested for this node + , optConfdAddr :: Maybe String -- ^ IP address of the Confd server + , optConfdPort :: Maybe Int -- ^ The port of the Confd server to + -- connect to } deriving Show -- | Default values for the command line options. @@ -65,6 +74,9 @@ defaultOptions = Options , optShowVer = False , optDrbdStatus = Nothing , optDrbdPairing = Nothing + , optNode = Nothing + , optConfdAddr = Nothing + , optConfdPort = Nothing } -- | Abbreviation for the option type. @@ -93,6 +105,28 @@ oDrbdStatus = "the DRBD status FILE", OptComplFile) +oNode :: OptType +oNode = + ( Option "n" ["node"] + (ReqArg (\ n o -> Ok o { optNode = Just n }) "NODE") + "the FQDN of the NODE about which information is requested", + OptComplFile) + +oConfdAddr :: OptType +oConfdAddr = + ( Option "a" ["address"] + (ReqArg (\ a o -> Ok o { optConfdAddr = Just a }) "IP_ADDR") + "the IP address of the Confd server to connect to", + OptComplFile) + +oConfdPort :: OptType +oConfdPort = + (Option "p" ["port"] + (reqWithConversion (tryRead "reading port") + (\port opts -> Ok opts { optConfdPort = Just port }) "PORT") + "Network port of the Confd server to connect to", + OptComplInteger) + -- | Generic options. genericOptions :: [GenericOptType Options] genericOptions = [ oShowVer diff --git a/src/Ganeti/DataCollectors/Drbd.hs b/src/Ganeti/DataCollectors/Drbd.hs index 8f0aeb4527f3ab93401eb5815e82fa77a38fbca9..f15479dd2f25f6a6c70ad9451014a8ed679f4313 100644 --- a/src/Ganeti/DataCollectors/Drbd.hs +++ b/src/Ganeti/DataCollectors/Drbd.hs @@ -90,7 +90,7 @@ arguments = [ArgCompletion OptComplFile 0 (Just 0)] getPairingInfo :: Maybe String -> IO (BT.Result [DrbdInstMinor]) getPairingInfo Nothing = do curNode <- getHostName - client <- getConfdClient + client <- getConfdClient Nothing Nothing reply <- query client ReqNodeDrbd $ PlainQuery curNode return $ case fmap (J.readJSONs . confdReplyAnswer) reply of