root / src / Ganeti / Path.hs @ f3eb4bfd
History | View | Annotate | Download (4.2 kB)
1 |
{-| Path-related helper functions. |
---|---|
2 |
|
3 |
-} |
4 |
|
5 |
{- |
6 |
|
7 |
Copyright (C) 2012, 2014 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 |
, defaultMasterSocket |
32 |
, defaultQuerySocket |
33 |
, defaultWConfdSocket |
34 |
, confdHmacKey |
35 |
, clusterConfFile |
36 |
, lockStatusFile |
37 |
, watcherPauseFile |
38 |
, nodedCertFile |
39 |
, nodedClientCertFile |
40 |
, queueDir |
41 |
, jobQueueSerialFile |
42 |
, jobQueueLockFile |
43 |
, jobQueueDrainFile |
44 |
, jobQueueArchiveSubDir |
45 |
, instanceReasonDir |
46 |
, getInstReasonFilename |
47 |
) where |
48 |
|
49 |
import System.FilePath |
50 |
import System.Posix.Env (getEnvDefault) |
51 |
|
52 |
import AutoConf |
53 |
|
54 |
-- | Simple helper to concat two paths. |
55 |
pjoin :: IO String -> String -> IO String |
56 |
pjoin a b = do |
57 |
a' <- a |
58 |
return $ a' </> b |
59 |
|
60 |
-- | Returns the root directory, which can be either the real root or |
61 |
-- the virtual root. |
62 |
getRootDir :: IO FilePath |
63 |
getRootDir = getEnvDefault "GANETI_ROOTDIR" "" |
64 |
|
65 |
-- | Prefixes a path with the current root directory. |
66 |
addNodePrefix :: FilePath -> IO FilePath |
67 |
addNodePrefix path = do |
68 |
root <- getRootDir |
69 |
return $ root ++ path |
70 |
|
71 |
-- | Directory for data. |
72 |
dataDir :: IO FilePath |
73 |
dataDir = addNodePrefix $ AutoConf.localstatedir </> "lib" </> "ganeti" |
74 |
|
75 |
-- | Helper for building on top of dataDir (internal). |
76 |
dataDirP :: FilePath -> IO FilePath |
77 |
dataDirP = (dataDir `pjoin`) |
78 |
|
79 |
-- | Directory for runtime files. |
80 |
runDir :: IO FilePath |
81 |
runDir = addNodePrefix $ AutoConf.localstatedir </> "run" </> "ganeti" |
82 |
|
83 |
-- | Directory for log files. |
84 |
logDir :: IO FilePath |
85 |
logDir = addNodePrefix $ AutoConf.localstatedir </> "log" </> "ganeti" |
86 |
|
87 |
-- | Directory for Unix sockets. |
88 |
socketDir :: IO FilePath |
89 |
socketDir = runDir `pjoin` "socket" |
90 |
|
91 |
-- | The default path for the master-daemon LUXI socket. |
92 |
defaultMasterSocket :: IO FilePath |
93 |
defaultMasterSocket = socketDir `pjoin` "ganeti-master" |
94 |
|
95 |
-- | The default LUXI socket for queries. |
96 |
defaultQuerySocket :: IO FilePath |
97 |
defaultQuerySocket = socketDir `pjoin` "ganeti-query" |
98 |
|
99 |
-- | The default WConfD socket for queries. |
100 |
defaultWConfdSocket :: IO FilePath |
101 |
defaultWConfdSocket = socketDir `pjoin` "ganeti-wconfd" |
102 |
|
103 |
-- | Path to file containing confd's HMAC key. |
104 |
confdHmacKey :: IO FilePath |
105 |
confdHmacKey = dataDirP "hmac.key" |
106 |
|
107 |
-- | Path to cluster configuration file. |
108 |
clusterConfFile :: IO FilePath |
109 |
clusterConfFile = dataDirP "config.data" |
110 |
|
111 |
-- | Path to the file representing the lock status. |
112 |
lockStatusFile :: IO FilePath |
113 |
lockStatusFile = dataDirP "locks.data" |
114 |
|
115 |
-- | Path to the watcher pause file. |
116 |
watcherPauseFile :: IO FilePath |
117 |
watcherPauseFile = dataDirP "watcher.pause" |
118 |
|
119 |
-- | Path to the noded certificate. |
120 |
nodedCertFile :: IO FilePath |
121 |
nodedCertFile = dataDirP "server.pem" |
122 |
|
123 |
-- | Path to the noded client certificate. |
124 |
nodedClientCertFile :: IO FilePath |
125 |
nodedClientCertFile = dataDirP "client.pem" |
126 |
|
127 |
-- | Job queue directory. |
128 |
queueDir :: IO FilePath |
129 |
queueDir = dataDirP "queue" |
130 |
|
131 |
-- | Job queue serial file. |
132 |
jobQueueSerialFile :: IO FilePath |
133 |
jobQueueSerialFile = queueDir `pjoin` "serial" |
134 |
|
135 |
-- | Job queue lock file |
136 |
jobQueueLockFile :: IO FilePath |
137 |
jobQueueLockFile = queueDir `pjoin` "lock" |
138 |
|
139 |
-- | Job queue drain file |
140 |
jobQueueDrainFile :: IO FilePath |
141 |
jobQueueDrainFile = queueDir `pjoin` "drain" |
142 |
|
143 |
-- | Job queue archive directory. |
144 |
jobQueueArchiveSubDir :: FilePath |
145 |
jobQueueArchiveSubDir = "archive" |
146 |
|
147 |
-- | Directory containing the reason trails for the last change of status of |
148 |
-- instances. |
149 |
instanceReasonDir :: IO FilePath |
150 |
instanceReasonDir = runDir `pjoin` "instance-reason" |
151 |
|
152 |
-- | The path of the file containing the reason trail for an instance, given the |
153 |
-- instance name. |
154 |
getInstReasonFilename :: String -> IO FilePath |
155 |
getInstReasonFilename instName = instanceReasonDir `pjoin` instName |