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>
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 \
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_-]+$")
# 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.
print Convert(constants, "")
print Convert(luxi, "luxi")
print Convert(qlang, "qlang")
+ print Convert(_autoconf, "autoconf")
if __name__ == "__main__":
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
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
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)
, parseYesNo
, parseISpecString
, shTemplate
- , defaultLuxiSocket
, maybePrintNodes
, maybePrintInsts
, maybeShowWarnings
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.
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
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)
"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
--- /dev/null
+{-| 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"
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
-- 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)
import Text.Printf
import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
import Ganeti.BasicTypes
data GanetiDaemon = GanetiMasterd
-- | 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.
import System.IO.Error (isDoesNotExistError)
import qualified Ganeti.Constants as C
+import qualified Ganeti.Path as Path
import Ganeti.BasicTypes
import Ganeti.HTools.Utils
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'