Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Path.hs @ 02926b4b

History | View | Annotate | Download (3.5 kB)

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
  , jobQueueLockFile 
39
  , jobQueueArchiveSubDir
40
  , instanceReasonDir
41
  , getInstReasonFilename
42
  ) where
43

    
44
import System.FilePath
45
import System.Posix.Env (getEnvDefault)
46

    
47
import AutoConf
48

    
49
-- | Simple helper to concat two paths.
50
pjoin :: IO String -> String -> IO String
51
pjoin a b = do
52
  a' <- a
53
  return $ a' </> b
54

    
55
-- | Returns the root directory, which can be either the real root or
56
-- the virtual root.
57
getRootDir :: IO FilePath
58
getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
59

    
60
-- | Prefixes a path with the current root directory.
61
addNodePrefix :: FilePath -> IO FilePath
62
addNodePrefix path = do
63
  root <- getRootDir
64
  return $ root ++ path
65

    
66
-- | Directory for data.
67
dataDir :: IO FilePath
68
dataDir = addNodePrefix $ AutoConf.localstatedir </> "lib" </> "ganeti"
69

    
70
-- | Helper for building on top of dataDir (internal).
71
dataDirP :: FilePath -> IO FilePath
72
dataDirP = (dataDir `pjoin`)
73

    
74
-- | Directory for runtime files.
75
runDir :: IO FilePath
76
runDir = addNodePrefix $ AutoConf.localstatedir </> "run" </> "ganeti"
77

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

    
82
-- | Directory for Unix sockets.
83
socketDir :: IO FilePath
84
socketDir = runDir `pjoin` "socket"
85

    
86
-- | The default LUXI socket path.
87
defaultLuxiSocket :: IO FilePath
88
defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
89

    
90
-- | The default LUXI socket for queries.
91
defaultQuerySocket :: IO FilePath
92
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
93

    
94
-- | Path to file containing confd's HMAC key.
95
confdHmacKey :: IO FilePath
96
confdHmacKey = dataDirP "hmac.key"
97

    
98
-- | Path to cluster configuration file.
99
clusterConfFile :: IO FilePath
100
clusterConfFile  = dataDirP "config.data"
101

    
102
-- | Path to the noded certificate.
103
nodedCertFile :: IO FilePath
104
nodedCertFile = dataDirP "server.pem"
105

    
106
-- | Job queue directory.
107
queueDir :: IO FilePath
108
queueDir = dataDirP "queue"
109

    
110
-- | Job queue serial file.
111
jobQueueSerialFile :: IO FilePath
112
jobQueueSerialFile = queueDir `pjoin` "serial"
113

    
114
-- | Job queue lock file
115
jobQueueLockFile :: IO FilePath
116
jobQueueLockFile = queueDir `pjoin` "lock"
117

    
118
-- | Job queue archive directory.
119
jobQueueArchiveSubDir :: FilePath
120
jobQueueArchiveSubDir = "archive"
121

    
122
-- | Directory containing the reason trails for the last change of status of
123
-- instances.
124
instanceReasonDir :: IO FilePath
125
instanceReasonDir = runDir `pjoin` "instance-reason"
126

    
127
-- | The path of the file containing the reason trail for an instance, given the
128
-- instance name.
129
getInstReasonFilename :: String -> IO FilePath
130
getInstReasonFilename instName = instanceReasonDir `pjoin` instName