Refactor NodeInfo RPC regarding storage reporting
[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   , instanceReasonDir
40   , getInstReasonFilename
41   ) where
42
43 import System.FilePath
44 import System.Posix.Env (getEnvDefault)
45
46 import qualified Ganeti.Constants as C
47
48 -- | Simple helper to concat two paths.
49 pjoin :: IO String -> String -> IO String
50 pjoin a b = do
51   a' <- a
52   return $ a' </> b
53
54 -- | Returns the root directory, which can be either the real root or
55 -- the virtual root.
56 getRootDir :: IO FilePath
57 getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
58
59 -- | Prefixes a path with the current root directory.
60 addNodePrefix :: FilePath -> IO FilePath
61 addNodePrefix path = do
62   root <- getRootDir
63   return $ root ++ path
64
65 -- | Directory for data.
66 dataDir :: IO FilePath
67 dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
68
69 -- | Helper for building on top of dataDir (internal).
70 dataDirP :: FilePath -> IO FilePath
71 dataDirP = (dataDir `pjoin`)
72
73 -- | Directory for runtime files.
74 runDir :: IO FilePath
75 runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
76
77 -- | Directory for log files.
78 logDir :: IO FilePath
79 logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
80
81 -- | Directory for Unix sockets.
82 socketDir :: IO FilePath
83 socketDir = runDir `pjoin` "socket"
84
85 -- | The default LUXI socket path.
86 defaultLuxiSocket :: IO FilePath
87 defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
88
89 -- | The default LUXI socket for queries.
90 defaultQuerySocket :: IO FilePath
91 defaultQuerySocket = socketDir `pjoin` "ganeti-query"
92
93 -- | Path to file containing confd's HMAC key.
94 confdHmacKey :: IO FilePath
95 confdHmacKey = dataDirP "hmac.key"
96
97 -- | Path to cluster configuration file.
98 clusterConfFile :: IO FilePath
99 clusterConfFile  = dataDirP "config.data"
100
101 -- | Path to the noded certificate.
102 nodedCertFile :: IO FilePath
103 nodedCertFile = dataDirP "server.pem"
104
105 -- | Job queue directory.
106 queueDir :: IO FilePath
107 queueDir = dataDirP "queue"
108
109 -- | Job queue serial file.
110 jobQueueSerialFile :: IO FilePath
111 jobQueueSerialFile = dataDirP "serial"
112
113 -- | Job queue archive directory.
114 jobQueueArchiveSubDir :: FilePath
115 jobQueueArchiveSubDir = "archive"
116
117 -- | Directory containing the reason trails for the last change of status of
118 -- instances.
119 instanceReasonDir :: IO FilePath
120 instanceReasonDir = runDir `pjoin` "instance-reason"
121
122 -- | The path of the file containing the reason trail for an instance, given the
123 -- instance name.
124 getInstReasonFilename :: String -> IO FilePath
125 getInstReasonFilename instName = instanceReasonDir `pjoin` instName