Improve mon-collector drbd CLI handling
[ganeti-local] / htools / Ganeti / Path.hs
index 5f439dd..9383c18 100644 (file)
@@ -24,47 +24,90 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 -}
 
 module Ganeti.Path
-  ( defaultLuxiSocket
-  , defaultQuerySocket
-  , dataDir
-  , logDir
+  ( dataDir
   , runDir
+  , logDir
+  , socketDir
+  , defaultLuxiSocket
+  , defaultQuerySocket
   , confdHmacKey
   , clusterConfFile
+  , nodedCertFile
+  , queueDir
+  , jobQueueSerialFile
+  , jobQueueArchiveSubDir
   ) where
 
-import qualified Ganeti.Constants as C
 import System.FilePath
+import System.Posix.Env (getEnvDefault)
+
+import qualified Ganeti.Constants as C
 
+-- | Simple helper to concat two paths.
+pjoin :: IO String -> String -> IO String
+pjoin a b = do
+  a' <- a
+  return $ a' </> b
 
--- | Directory for data
-dataDir :: FilePath
-dataDir = C.autoconfLocalstatedir </> "lib" </> "ganeti"
+-- | Returns the root directory, which can be either the real root or
+-- the virtual root.
+getRootDir :: IO FilePath
+getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
 
--- | Directory for runtime files
-runDir :: FilePath
-runDir = C.autoconfLocalstatedir </> "run" </> "ganeti"
+-- | Prefixes a path with the current root directory.
+addNodePrefix :: FilePath -> IO FilePath
+addNodePrefix path = do
+  root <- getRootDir
+  return $ root ++ path
 
--- | Directory for log files
-logDir :: FilePath
-logDir = C.autoconfLocalstatedir </> "log" </> "ganeti"
+-- | Directory for data.
+dataDir :: IO FilePath
+dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
 
--- | Directory for Unix sockets
-socketDir :: FilePath
-socketDir = runDir </> "socket"
+-- | Helper for building on top of dataDir (internal).
+dataDirP :: FilePath -> IO FilePath
+dataDirP = (dataDir `pjoin`)
+
+-- | Directory for runtime files.
+runDir :: IO FilePath
+runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
+
+-- | Directory for log files.
+logDir :: IO FilePath
+logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
+
+-- | Directory for Unix sockets.
+socketDir :: IO FilePath
+socketDir = runDir `pjoin` "socket"
 
 -- | The default LUXI socket path.
-defaultLuxiSocket :: FilePath
-defaultLuxiSocket = socketDir </> "ganeti-master"
+defaultLuxiSocket :: IO FilePath
+defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
 
 -- | The default LUXI socket for queries.
-defaultQuerySocket :: FilePath
-defaultQuerySocket = socketDir </> "ganeti-query"
+defaultQuerySocket :: IO FilePath
+defaultQuerySocket = socketDir `pjoin` "ganeti-query"
+
+-- | Path to file containing confd's HMAC key.
+confdHmacKey :: IO FilePath
+confdHmacKey = dataDirP "hmac.key"
+
+-- | Path to cluster configuration file.
+clusterConfFile :: IO FilePath
+clusterConfFile  = dataDirP "config.data"
+
+-- | Path to the noded certificate.
+nodedCertFile :: IO FilePath
+nodedCertFile = dataDirP "server.pem"
+
+-- | Job queue directory.
+queueDir :: IO FilePath
+queueDir = dataDirP "queue"
 
--- | Path to file containing confd's HMAC key
-confdHmacKey :: FilePath
-confdHmacKey = dataDir </> "hmac.key"
+-- | Job queue serial file.
+jobQueueSerialFile :: IO FilePath
+jobQueueSerialFile = dataDirP "serial"
 
--- | Path to cluster configuration file
-clusterConfFile :: FilePath
-clusterConfFile  = dataDir </> "config.data"
+-- | Job queue archive directory.
+jobQueueArchiveSubDir :: FilePath
+jobQueueArchiveSubDir = "archive"