Skip to content
Snippets Groups Projects
Commit 8e445e6d authored by Iustin Pop's avatar Iustin Pop
Browse files

Add support for luxi backend in CLI/hspace/hbal

This patch changes the backend selection method in CLI to prefer, in order:
  - a RAPI specification
  - a Luxi specification
  - and finally the node/instance files

It also modifies hspace and hbal to provide a ‘-L’ command line option
for enabling Luxi.
parent 53ec9022
No related branches found
No related tags found
No related merge requests found
......@@ -34,18 +34,21 @@ module Ganeti.HTools.CLI
, 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
......@@ -54,6 +57,10 @@ import qualified Ganeti.HTools.Node as Node
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.
......@@ -73,6 +80,8 @@ class EToolOptions a where
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
......@@ -141,10 +150,13 @@ loadExternalData opts = do
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) <-
......
......@@ -54,6 +54,7 @@ data Options = Options
, 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
......@@ -73,6 +74,7 @@ instance CLI.EToolOptions Options where
instFile = optInstf
instSet = optInstSet
masterName = optMaster
luxiSocket = optLuxi
silent a = optVerbose a == 0
-- | Default values for the command line options.
......@@ -87,6 +89,7 @@ defaultOptions = Options
, optInstSet = False
, optMaxLength = -1
, optMaster = ""
, optLuxi = Nothing
, optVerbose = 1
, optOffline = []
, optMinScore = 1e-9
......@@ -120,6 +123,10 @@ options =
, 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 \
......
......@@ -28,6 +28,7 @@ module Main (main) where
import Data.Char (toUpper)
import Data.List
import Data.Function
import Data.Maybe (fromMaybe)
import Monad
import System
import System.IO
......@@ -53,6 +54,7 @@ data Options = Options
, 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
......@@ -75,6 +77,7 @@ instance CLI.EToolOptions Options where
instFile = optInstf
instSet = optInstSet
masterName = optMaster
luxiSocket = optLuxi
silent a = optVerbose a == 0
-- | Default values for the command line options.
......@@ -86,6 +89,7 @@ defaultOptions = Options
, optInstf = "instances"
, optInstSet = False
, optMaster = ""
, optLuxi = Nothing
, optVerbose = 1
, optOffline = []
, optIMem = 4096
......@@ -113,6 +117,10 @@ options =
, 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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment