Loader.hs: rewrite extractExTags to use chompPrefix
[ganeti-local] / src / Ganeti / Path.hs
1 {-| Path-related helper functions.
2
3 -}
4
5 {-
6
7 Copyright (C) 2012 Google Inc.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301, USA.
23
24 -}
25
26 module Ganeti.Path
27   ( dataDir
28   , runDir
29   , logDir
30   , socketDir
31   , defaultLuxiSocket
32   , defaultQuerySocket
33   , confdHmacKey
34   , clusterConfFile
35   , nodedCertFile
36   , queueDir
37   , jobQueueSerialFile
38   , jobQueueArchiveSubDir
39   ) where
40
41 import System.FilePath
42 import System.Posix.Env (getEnvDefault)
43
44 import qualified Ganeti.Constants as C
45
46 -- | Simple helper to concat two paths.
47 pjoin :: IO String -> String -> IO String
48 pjoin a b = do
49   a' <- a
50   return $ a' </> b
51
52 -- | Returns the root directory, which can be either the real root or
53 -- the virtual root.
54 getRootDir :: IO FilePath
55 getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
56
57 -- | Prefixes a path with the current root directory.
58 addNodePrefix :: FilePath -> IO FilePath
59 addNodePrefix path = do
60   root <- getRootDir
61   return $ root ++ path
62
63 -- | Directory for data.
64 dataDir :: IO FilePath
65 dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
66
67 -- | Helper for building on top of dataDir (internal).
68 dataDirP :: FilePath -> IO FilePath
69 dataDirP = (dataDir `pjoin`)
70
71 -- | Directory for runtime files.
72 runDir :: IO FilePath
73 runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
74
75 -- | Directory for log files.
76 logDir :: IO FilePath
77 logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
78
79 -- | Directory for Unix sockets.
80 socketDir :: IO FilePath
81 socketDir = runDir `pjoin` "socket"
82
83 -- | The default LUXI socket path.
84 defaultLuxiSocket :: IO FilePath
85 defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
86
87 -- | The default LUXI socket for queries.
88 defaultQuerySocket :: IO FilePath
89 defaultQuerySocket = socketDir `pjoin` "ganeti-query"
90
91 -- | Path to file containing confd's HMAC key.
92 confdHmacKey :: IO FilePath
93 confdHmacKey = dataDirP "hmac.key"
94
95 -- | Path to cluster configuration file.
96 clusterConfFile :: IO FilePath
97 clusterConfFile  = dataDirP "config.data"
98
99 -- | Path to the noded certificate.
100 nodedCertFile :: IO FilePath
101 nodedCertFile = dataDirP "server.pem"
102
103 -- | Job queue directory.
104 queueDir :: IO FilePath
105 queueDir = dataDirP "queue"
106
107 -- | Job queue serial file.
108 jobQueueSerialFile :: IO FilePath
109 jobQueueSerialFile = dataDirP "serial"
110
111 -- | Job queue archive directory.
112 jobQueueArchiveSubDir :: FilePath
113 jobQueueArchiveSubDir = "archive"