Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Path.hs @ 557f5dad

History | View | Annotate | Download (3.6 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
  , defaultMasterSocket
32
  , defaultQuerySocket
33
  , confdHmacKey
34
  , clusterConfFile
35
  , nodedCertFile
36
  , queueDir
37
  , jobQueueSerialFile
38
  , jobQueueLockFile 
39
  , jobQueueDrainFile  
40
  , jobQueueArchiveSubDir
41
  , instanceReasonDir
42
  , getInstReasonFilename
43
  ) where
44

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

    
48
import AutoConf
49

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

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

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

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

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

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

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

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

    
87
-- | The default path for the master-daemon LUXI socket.
88
defaultMasterSocket :: IO FilePath
89
defaultMasterSocket = socketDir `pjoin` "ganeti-master"
90

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

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

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

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

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

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

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

    
119
-- | Job queue drain file
120
jobQueueDrainFile :: IO FilePath
121
jobQueueDrainFile = queueDir `pjoin` "drain"
122

    
123
-- | Job queue archive directory.
124
jobQueueArchiveSubDir :: FilePath
125
jobQueueArchiveSubDir = "archive"
126

    
127
-- | Directory containing the reason trails for the last change of status of
128
-- instances.
129
instanceReasonDir :: IO FilePath
130
instanceReasonDir = runDir `pjoin` "instance-reason"
131

    
132
-- | The path of the file containing the reason trail for an instance, given the
133
-- instance name.
134
getInstReasonFilename :: String -> IO FilePath
135
getInstReasonFilename instName = instanceReasonDir `pjoin` instName