, parseEnv
, shTemplate
, loadExternalData
+ , defaultLuxiSocket
) where
+import Data.Maybe (isJust, fromJust)
+import qualified Data.Version
+import Monad
import System.Console.GetOpt
import System.Posix.Env
import System.IO
import System.Info
import System
-import Monad
import Text.Printf (printf, hPrintf)
-import qualified Data.Version
import qualified Ganeti.HTools.Version as Version(version)
+import qualified Ganeti.HTools.Luxi as Luxi
import qualified Ganeti.HTools.Rapi as Rapi
import qualified Ganeti.HTools.Text as Text
import qualified Ganeti.HTools.Loader as Loader
import Ganeti.HTools.Types
+-- | The default value for the luxi socket
+defaultLuxiSocket :: FilePath
+defaultLuxiSocket = "/var/run/ganeti/socket/ganeti-master"
+
-- | Class for types which support show help and show version.
class CLIOptions a where
-- | Denotes whether the show help option has been passed.
instSet :: a -> Bool
-- | Rapi target, if one has been passed.
masterName :: a -> String
+ -- | Whether to connect to a local luxi socket.
+ luxiSocket :: a -> Maybe FilePath
-- | Whether to be less verbose.
silent :: a -> Bool
else env_node
instf = if instSet opts then instFile opts
else env_inst
+ mhost = masterName opts
+ lsock = luxiSocket opts
input_data <-
- case masterName opts of
- "" -> Text.loadData nodef instf
- host -> Rapi.loadData host
+ case () of
+ _ | mhost /= "" -> Rapi.loadData mhost
+ | isJust lsock -> Luxi.loadData $ fromJust lsock
+ | otherwise -> Text.loadData nodef instf
let ldresult = input_data >>= Loader.mergeData
(loaded_nl, il, csf) <-
, optInstSet :: Bool -- ^ The insts have been set by options
, optMaxLength :: Int -- ^ Stop after this many steps
, optMaster :: String -- ^ Collect data from RAPI
+ , optLuxi :: Maybe FilePath -- ^ Collect data from Luxi
, optVerbose :: Int -- ^ Verbosity level
, optOffline :: [String] -- ^ Names of offline nodes
, optMinScore :: Cluster.Score -- ^ The minimum score we aim for
instFile = optInstf
instSet = optInstSet
masterName = optMaster
+ luxiSocket = optLuxi
silent a = optVerbose a == 0
-- | Default values for the command line options.
, optInstSet = False
, optMaxLength = -1
, optMaster = ""
+ , optLuxi = Nothing
, optVerbose = 1
, optOffline = []
, optMinScore = 1e-9
, Option ['m'] ["master"]
(ReqArg (\ m opts -> opts { optMaster = m }) "ADDRESS")
"collect data via RAPI at the given ADDRESS"
+ , Option ['L'] ["luxi"]
+ (OptArg ((\ f opts -> opts { optLuxi = Just f }) .
+ fromMaybe CLI.defaultLuxiSocket) "SOCKET")
+ "collect data via Luxi, optionally using the given SOCKET path"
, Option ['l'] ["max-length"]
(ReqArg (\ i opts -> opts { optMaxLength = read i::Int }) "N")
"cap the solution at this many moves (useful for very unbalanced \
import Data.Char (toUpper)
import Data.List
import Data.Function
+import Data.Maybe (fromMaybe)
import Monad
import System
import System.IO
, optInstf :: FilePath -- ^ Path to the instances file
, optInstSet :: Bool -- ^ The insts have been set by options
, optMaster :: String -- ^ Collect data from RAPI
+ , optLuxi :: Maybe FilePath -- ^ Collect data from Luxi
, optVerbose :: Int -- ^ Verbosity level
, optOffline :: [String] -- ^ Names of offline nodes
, optIMem :: Int -- ^ Instance memory
instFile = optInstf
instSet = optInstSet
masterName = optMaster
+ luxiSocket = optLuxi
silent a = optVerbose a == 0
-- | Default values for the command line options.
, optInstf = "instances"
, optInstSet = False
, optMaster = ""
+ , optLuxi = Nothing
, optVerbose = 1
, optOffline = []
, optIMem = 4096
, Option ['m'] ["master"]
(ReqArg (\ m opts -> opts { optMaster = m }) "ADDRESS")
"collect data via RAPI at the given ADDRESS"
+ , Option ['L'] ["luxi"]
+ (OptArg ((\ f opts -> opts { optLuxi = Just f }) .
+ fromMaybe CLI.defaultLuxiSocket) "SOCKET")
+ "collect data via Luxi, optionally using the given SOCKET path"
, Option ['v'] ["verbose"]
(NoArg (\ opts -> opts { optVerbose = optVerbose opts + 1 }))
"increase the verbosity level"