Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Path.hs @ 13d26b66

History | View | Annotate | Download (4.1 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
  , watcherPauseFile
37
  , nodedCertFile
38
  , nodedClientCertFile
39
  , queueDir
40
  , jobQueueSerialFile
41
  , jobQueueLockFile
42
  , jobQueueDrainFile
43
  , jobQueueArchiveSubDir
44
  , instanceReasonDir
45
  , getInstReasonFilename
46
  ) where
47

    
48
import System.FilePath
49
import System.Posix.Env (getEnvDefault)
50

    
51
import AutoConf
52

    
53
-- | Simple helper to concat two paths.
54
pjoin :: IO String -> String -> IO String
55
pjoin a b = do
56
  a' <- a
57
  return $ a' </> b
58

    
59
-- | Returns the root directory, which can be either the real root or
60
-- the virtual root.
61
getRootDir :: IO FilePath
62
getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
63

    
64
-- | Prefixes a path with the current root directory.
65
addNodePrefix :: FilePath -> IO FilePath
66
addNodePrefix path = do
67
  root <- getRootDir
68
  return $ root ++ path
69

    
70
-- | Directory for data.
71
dataDir :: IO FilePath
72
dataDir = addNodePrefix $ AutoConf.localstatedir </> "lib" </> "ganeti"
73

    
74
-- | Helper for building on top of dataDir (internal).
75
dataDirP :: FilePath -> IO FilePath
76
dataDirP = (dataDir `pjoin`)
77

    
78
-- | Directory for runtime files.
79
runDir :: IO FilePath
80
runDir = addNodePrefix $ AutoConf.localstatedir </> "run" </> "ganeti"
81

    
82
-- | Directory for log files.
83
logDir :: IO FilePath
84
logDir = addNodePrefix $ AutoConf.localstatedir </> "log" </> "ganeti"
85

    
86
-- | Directory for Unix sockets.
87
socketDir :: IO FilePath
88
socketDir = runDir `pjoin` "socket"
89

    
90
-- | The default path for the master-daemon LUXI socket.
91
defaultMasterSocket :: IO FilePath
92
defaultMasterSocket = socketDir `pjoin` "ganeti-master"
93

    
94
-- | The default LUXI socket for queries.
95
defaultQuerySocket :: IO FilePath
96
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
97

    
98
-- | The default WConfD socket for queries.
99
defaultWConfdSocket :: IO FilePath
100
defaultWConfdSocket = socketDir `pjoin` "ganeti-wconfd"
101

    
102
-- | Path to file containing confd's HMAC key.
103
confdHmacKey :: IO FilePath
104
confdHmacKey = dataDirP "hmac.key"
105

    
106
-- | Path to cluster configuration file.
107
clusterConfFile :: IO FilePath
108
clusterConfFile  = dataDirP "config.data"
109

    
110
-- | Path to the watcher pause file.
111
watcherPauseFile :: IO FilePath
112
watcherPauseFile = dataDirP "watcher.pause"
113

    
114
-- | Path to the noded certificate.
115
nodedCertFile :: IO FilePath
116
nodedCertFile = dataDirP "server.pem"
117

    
118
-- | Path to the noded client certificate.
119
nodedClientCertFile :: IO FilePath
120
nodedClientCertFile = dataDirP "client.pem"
121

    
122
-- | Job queue directory.
123
queueDir :: IO FilePath
124
queueDir = dataDirP "queue"
125

    
126
-- | Job queue serial file.
127
jobQueueSerialFile :: IO FilePath
128
jobQueueSerialFile = queueDir `pjoin` "serial"
129

    
130
-- | Job queue lock file
131
jobQueueLockFile :: IO FilePath
132
jobQueueLockFile = queueDir `pjoin` "lock"
133

    
134
-- | Job queue drain file
135
jobQueueDrainFile :: IO FilePath
136
jobQueueDrainFile = queueDir `pjoin` "drain"
137

    
138
-- | Job queue archive directory.
139
jobQueueArchiveSubDir :: FilePath
140
jobQueueArchiveSubDir = "archive"
141

    
142
-- | Directory containing the reason trails for the last change of status of
143
-- instances.
144
instanceReasonDir :: IO FilePath
145
instanceReasonDir = runDir `pjoin` "instance-reason"
146

    
147
-- | The path of the file containing the reason trail for an instance, given the
148
-- instance name.
149
getInstReasonFilename :: String -> IO FilePath
150
getInstReasonFilename instName = instanceReasonDir `pjoin` instName