Use autoconf-based paths from Haskell instead of constants
authorMichael Hanselmann <hansmi@google.com>
Mon, 17 Sep 2012 17:19:28 +0000 (19:19 +0200)
committerMichael Hanselmann <hansmi@google.com>
Tue, 18 Sep 2012 15:11:07 +0000 (17:11 +0200)
Future changes will change Path.hs to use an environment variable.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

Makefile.am
autotools/convert-constants
htools/Ganeti/Confd/Server.hs
htools/Ganeti/Confd/Utils.hs
htools/Ganeti/HTools/CLI.hs
htools/Ganeti/HTools/Program/Hscan.hs
htools/Ganeti/Path.hs [new file with mode: 0644]
htools/Ganeti/Query/Server.hs
htools/Ganeti/Runtime.hs
htools/Ganeti/Ssconf.hs

index 3c7820a..5a6e137 100644 (file)
@@ -429,6 +429,7 @@ HS_LIB_SRCS = \
        htools/Ganeti/Luxi.hs \
        htools/Ganeti/Objects.hs \
        htools/Ganeti/OpCodes.hs \
+       htools/Ganeti/Path.hs \
        htools/Ganeti/Query/Common.hs \
        htools/Ganeti/Query/Filter.hs \
        htools/Ganeti/Query/Language.hs \
index e051821..b08f6f3 100755 (executable)
@@ -29,6 +29,8 @@ from ganeti import compat
 from ganeti import constants
 from ganeti import luxi
 from ganeti import qlang
+from ganeti import _autoconf
+
 
 #: Constant name regex
 CONSTANT_RE = re.compile("^[A-Z][A-Z0-9_-]+$")
@@ -46,6 +48,7 @@ RE_TYPE = type(CONSTANT_RE)
 # have strings instead of easily looked-up names.
 IGNORED_DECL_NAMES = ["DEFAULT_ENABLED_HYPERVISOR"]
 
+
 def NameRules(name):
   """Converts the upper-cased Python name to Haskell camelCase.
 
@@ -289,6 +292,7 @@ def main():
   print Convert(constants, "")
   print Convert(luxi, "luxi")
   print Convert(qlang, "qlang")
+  print Convert(_autoconf, "autoconf")
 
 
 if __name__ == "__main__":
index 6bedee9..b14eb43 100644 (file)
@@ -55,6 +55,7 @@ import Ganeti.Config
 import Ganeti.Hash
 import Ganeti.Logging
 import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
 import Ganeti.Query.Server (runQueryD)
 
 -- * Types and constants definitions
@@ -503,11 +504,11 @@ main opts = do
   hmac <- getClusterHmac
   -- Inotify setup
   inotify <- initINotify
-  let inotiaction = addNotifier inotify C.clusterConfFile cref statemvar
+  let inotiaction = addNotifier inotify Path.clusterConfFile cref statemvar
   -- fork the timeout timer
-  _ <- forkIO $ onTimeoutTimer inotiaction C.clusterConfFile cref statemvar
+  _ <- forkIO $ onTimeoutTimer inotiaction Path.clusterConfFile cref statemvar
   -- fork the polling timer
-  _ <- forkIO $ onReloadTimer inotiaction C.clusterConfFile cref statemvar
+  _ <- forkIO $ onReloadTimer inotiaction Path.clusterConfFile cref statemvar
   -- launch the queryd listener
   _ <- forkIO $ runQueryD Nothing (configReader cref)
   -- and finally enter the responder loop
index 180e327..043ded0 100644 (file)
@@ -40,12 +40,13 @@ import Ganeti.BasicTypes
 import Ganeti.Confd
 import Ganeti.Hash
 import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
 import Ganeti.JSON
 import Ganeti.HTools.Utils
 
 -- | Returns the HMAC key.
 getClusterHmac :: IO HashKey
-getClusterHmac = fmap B.unpack $ B.readFile C.confdHmacKey
+getClusterHmac = fmap B.unpack $ B.readFile Path.confdHmacKey
 
 -- | Parses a signed request.
 parseRequest :: HashKey -> String -> Result (String, String, ConfdRequest)
index 0561490..e458013 100644 (file)
@@ -36,7 +36,6 @@ module Ganeti.HTools.CLI
   , parseYesNo
   , parseISpecString
   , shTemplate
-  , defaultLuxiSocket
   , maybePrintNodes
   , maybePrintInsts
   , maybeShowWarnings
@@ -92,20 +91,12 @@ import Text.Printf (printf)
 
 import qualified Ganeti.HTools.Container as Container
 import qualified Ganeti.HTools.Node as Node
-import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
 import Ganeti.HTools.Types
 import Ganeti.HTools.Utils
 import Ganeti.BasicTypes
 import Ganeti.Common as Common
 
--- * Constants
-
--- | The default value for the luxi socket.
---
--- This is re-exported from the "Ganeti.Constants" module.
-defaultLuxiSocket :: FilePath
-defaultLuxiSocket = C.masterSocket
-
 -- * Data types
 
 -- | Command line options structure.
@@ -301,7 +292,7 @@ oIAllocSrc = Option "I" ["ialloc-src"]
 oLuxiSocket :: OptType
 oLuxiSocket = Option "L" ["luxi"]
               (OptArg ((\ f opts -> Ok opts { optLuxi = Just f }) .
-                       fromMaybe defaultLuxiSocket) "SOCKET")
+                       fromMaybe Path.defaultLuxiSocket) "SOCKET")
               "collect data via Luxi, optionally using the given SOCKET path"
 
 oMachineReadable :: OptType
index 5c89de9..b83cc57 100644 (file)
@@ -39,6 +39,7 @@ import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 import qualified Ganeti.HTools.Rapi as Rapi
 import qualified Ganeti.HTools.Luxi as Luxi
+import qualified Ganeti.Path as Path
 import Ganeti.HTools.Loader (checkData, mergeData, ClusterData(..))
 import Ganeti.HTools.Text (serializeCluster)
 
@@ -138,7 +139,7 @@ main opts clusters = do
                 "t_disk" "f_disk" "Score"
 
   when (null clusters) $ do
-         let lsock = fromMaybe defaultLuxiSocket (optLuxi opts)
+         let lsock = fromMaybe Path.defaultLuxiSocket (optLuxi opts)
          let name = local
          input_data <- Luxi.loadData lsock
          result <- writeData nlen name opts input_data
diff --git a/htools/Ganeti/Path.hs b/htools/Ganeti/Path.hs
new file mode 100644 (file)
index 0000000..5f439dd
--- /dev/null
@@ -0,0 +1,70 @@
+{-| Path-related helper functions.
+
+-}
+
+{-
+
+Copyright (C) 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+
+module Ganeti.Path
+  ( defaultLuxiSocket
+  , defaultQuerySocket
+  , dataDir
+  , logDir
+  , runDir
+  , confdHmacKey
+  , clusterConfFile
+  ) where
+
+import qualified Ganeti.Constants as C
+import System.FilePath
+
+
+-- | Directory for data
+dataDir :: FilePath
+dataDir = C.autoconfLocalstatedir </> "lib" </> "ganeti"
+
+-- | Directory for runtime files
+runDir :: FilePath
+runDir = C.autoconfLocalstatedir </> "run" </> "ganeti"
+
+-- | Directory for log files
+logDir :: FilePath
+logDir = C.autoconfLocalstatedir </> "log" </> "ganeti"
+
+-- | Directory for Unix sockets
+socketDir :: FilePath
+socketDir = runDir </> "socket"
+
+-- | The default LUXI socket path.
+defaultLuxiSocket :: FilePath
+defaultLuxiSocket = socketDir </> "ganeti-master"
+
+-- | The default LUXI socket for queries.
+defaultQuerySocket :: FilePath
+defaultQuerySocket = socketDir </> "ganeti-query"
+
+-- | Path to file containing confd's HMAC key
+confdHmacKey :: FilePath
+confdHmacKey = dataDir </> "hmac.key"
+
+-- | Path to cluster configuration file
+clusterConfFile :: FilePath
+clusterConfFile  = dataDir </> "config.data"
index 80be42c..876aba0 100644 (file)
@@ -42,6 +42,7 @@ import Text.JSON.Pretty (pp_value)
 import System.Info (arch)
 
 import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
 import Ganeti.Daemon
 import Ganeti.Objects
 import qualified Ganeti.Config as Config
@@ -197,7 +198,7 @@ mainLoop creader socket = do
 -- only one exposed from this module.
 runQueryD :: Maybe FilePath -> ConfigReader -> IO ()
 runQueryD fpath creader = do
-  let socket_path = fromMaybe C.querySocket fpath
+  let socket_path = fromMaybe Path.defaultQuerySocket fpath
   cleanupSocket socket_path
   bracket
     (getServer socket_path)
index 7a8acca..8295736 100644 (file)
@@ -49,6 +49,7 @@ import System.Posix.User
 import Text.Printf
 
 import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
 import Ganeti.BasicTypes
 
 data GanetiDaemon = GanetiMasterd
@@ -92,11 +93,11 @@ daemonGroup (ExtraGroup  AdminGroup)    = C.adminGroup
 
 -- | Returns the log file for a daemon.
 daemonLogFile :: GanetiDaemon -> FilePath
-daemonLogFile daemon = C.logDir </> daemonName daemon <.> "log"
+daemonLogFile daemon = Path.logDir </> daemonName daemon <.> "log"
 
 -- | Returns the pid file name for a daemon.
 daemonPidFile :: GanetiDaemon -> FilePath
-daemonPidFile daemon = C.runDir </> daemonName daemon <.> "pid"
+daemonPidFile daemon = Path.runDir </> daemonName daemon <.> "pid"
 
 -- | All groups list. A bit hacking, as we can't enforce it's complete
 -- at compile time.
index cc36395..47a2e04 100644 (file)
@@ -46,6 +46,7 @@ import System.FilePath ((</>))
 import System.IO.Error (isDoesNotExistError)
 
 import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
 import Ganeti.BasicTypes
 import Ganeti.HTools.Utils
 
@@ -86,7 +87,7 @@ $(declareSADT "SSKey"
 keyToFilename :: Maybe FilePath     -- ^ Optional config path override
               -> SSKey              -- ^ ssconf key
               -> FilePath
-keyToFilename optpath key = fromMaybe C.dataDir optpath </>
+keyToFilename optpath key = fromMaybe Path.dataDir optpath </>
                             sSFilePrefix ++ sSKeyToRaw key
 
 -- | Runs an IO action while transforming any error into 'Bad'