Revision 29a30533 htools/Ganeti/Path.hs
b/htools/Ganeti/Path.hs | ||
---|---|---|
23 | 23 |
|
24 | 24 |
-} |
25 | 25 |
|
26 |
module Ganeti.Path where |
|
26 |
module Ganeti.Path |
|
27 |
( dataDir |
|
28 |
, runDir |
|
29 |
, logDir |
|
30 |
, socketDir |
|
31 |
, defaultLuxiSocket |
|
32 |
, defaultQuerySocket |
|
33 |
, confdHmacKey |
|
34 |
, clusterConfFile |
|
35 |
, nodedCertFile |
|
36 |
) where |
|
27 | 37 |
|
28 |
import qualified Ganeti.Constants as C |
|
29 | 38 |
import System.FilePath |
30 | 39 |
import System.Posix.Env (getEnvDefault) |
31 |
import System.IO.Unsafe |
|
32 |
|
|
33 |
{-# NOINLINE getRootDir #-} |
|
34 |
getRootDir :: FilePath |
|
35 |
getRootDir = unsafePerformIO $ getEnvDefault "GANETI_ROOTDIR" "" |
|
36 | 40 |
|
37 |
-- | Prefixes a path with the current root directory |
|
38 |
addNodePrefix :: FilePath -> FilePath |
|
39 |
addNodePrefix path = getRootDir ++ path |
|
41 |
import qualified Ganeti.Constants as C |
|
40 | 42 |
|
41 |
-- | Directory for data |
|
42 |
dataDir :: FilePath |
|
43 |
-- | Simple helper to concat two paths. |
|
44 |
pjoin :: IO String -> String -> IO String |
|
45 |
pjoin a b = do |
|
46 |
a' <- a |
|
47 |
return $ a' </> b |
|
48 |
|
|
49 |
-- | Returns the root directory, which can be either the real root or |
|
50 |
-- the virtual root. |
|
51 |
getRootDir :: IO FilePath |
|
52 |
getRootDir = getEnvDefault "GANETI_ROOTDIR" "" |
|
53 |
|
|
54 |
-- | Prefixes a path with the current root directory. |
|
55 |
addNodePrefix :: FilePath -> IO FilePath |
|
56 |
addNodePrefix path = do |
|
57 |
root <- getRootDir |
|
58 |
return $ root ++ path |
|
59 |
|
|
60 |
-- | Directory for data. |
|
61 |
dataDir :: IO FilePath |
|
43 | 62 |
dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti" |
44 | 63 |
|
45 |
-- | Directory for runtime files |
|
46 |
runDir :: FilePath |
|
64 |
-- | Directory for runtime files.
|
|
65 |
runDir :: IO FilePath
|
|
47 | 66 |
runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti" |
48 | 67 |
|
49 |
-- | Directory for log files |
|
50 |
logDir :: FilePath |
|
68 |
-- | Directory for log files.
|
|
69 |
logDir :: IO FilePath
|
|
51 | 70 |
logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti" |
52 | 71 |
|
53 |
-- | Directory for Unix sockets |
|
54 |
socketDir :: FilePath |
|
55 |
socketDir = runDir </> "socket"
|
|
72 |
-- | Directory for Unix sockets.
|
|
73 |
socketDir :: IO FilePath
|
|
74 |
socketDir = runDir `pjoin` "socket"
|
|
56 | 75 |
|
57 | 76 |
-- | The default LUXI socket path. |
58 |
defaultLuxiSocket :: FilePath |
|
59 |
defaultLuxiSocket = socketDir </> "ganeti-master"
|
|
77 |
defaultLuxiSocket :: IO FilePath
|
|
78 |
defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
|
|
60 | 79 |
|
61 | 80 |
-- | The default LUXI socket for queries. |
62 |
defaultQuerySocket :: FilePath |
|
63 |
defaultQuerySocket = socketDir </> "ganeti-query"
|
|
81 |
defaultQuerySocket :: IO FilePath
|
|
82 |
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
|
|
64 | 83 |
|
65 |
-- | Path to file containing confd's HMAC key |
|
66 |
confdHmacKey :: FilePath |
|
67 |
confdHmacKey = dataDir </> "hmac.key"
|
|
84 |
-- | Path to file containing confd's HMAC key.
|
|
85 |
confdHmacKey :: IO FilePath
|
|
86 |
confdHmacKey = dataDir `pjoin` "hmac.key"
|
|
68 | 87 |
|
69 |
-- | Path to cluster configuration file |
|
70 |
clusterConfFile :: FilePath |
|
71 |
clusterConfFile = dataDir </> "config.data"
|
|
88 |
-- | Path to cluster configuration file.
|
|
89 |
clusterConfFile :: IO FilePath
|
|
90 |
clusterConfFile = dataDir `pjoin` "config.data"
|
|
72 | 91 |
|
73 |
-- | Path |
|
74 |
nodedCertFile :: FilePath |
|
75 |
nodedCertFile = dataDir </> "server.pem" |
|
92 |
-- | Path to the noded certificate. |
|
93 |
nodedCertFile :: IO FilePath |
|
94 |
nodedCertFile = dataDir `pjoin` "server.pem" |
Also available in: Unified diff