Add support for luxi backend in CLI/hspace/hbal
authorIustin Pop <iustin@google.com>
Tue, 14 Jul 2009 13:04:47 +0000 (15:04 +0200)
committerIustin Pop <iustin@google.com>
Tue, 14 Jul 2009 13:06:46 +0000 (15:06 +0200)
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.

Ganeti/HTools/CLI.hs
hbal.hs
hspace.hs

index d625e2f..a3bdafa 100644 (file)
@@ -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) <-
diff --git a/hbal.hs b/hbal.hs
index 1533346..21d9c74 100644 (file)
--- a/hbal.hs
+++ b/hbal.hs
@@ -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 \
index 380efcb..89e50de 100644 (file)
--- a/hspace.hs
+++ b/hspace.hs
@@ -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"