Commit 9eeb0aa5 authored by Michael Hanselmann's avatar Michael Hanselmann

Use autoconf-based paths from Haskell instead of constants

Future changes will change Path.hs to use an environment variable.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 09bf5d24
......@@ -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 \
......
......@@ -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__":
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
{-| 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"
......@@ -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)
......
......@@ -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.
......
......@@ -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'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment