Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Path.hs @ b3cc1646

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

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

    
50
import AutoConf
51

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

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

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

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

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

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

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

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

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

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

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

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

    
105
-- | Path to the watcher pause file.
106
watcherPauseFile :: IO FilePath
107
watcherPauseFile = dataDirP "watcher.pause"
108

    
109
-- | Path to the noded certificate.
110
nodedCertFile :: IO FilePath
111
nodedCertFile = dataDirP "server.pem"
112

    
113
-- | Path to the noded client certificate.
114
nodedClientCertFile :: IO FilePath
115
nodedClientCertFile = dataDirP "client.pem"
116

    
117
-- | Job queue directory.
118
queueDir :: IO FilePath
119
queueDir = dataDirP "queue"
120

    
121
-- | Job queue serial file.
122
jobQueueSerialFile :: IO FilePath
123
jobQueueSerialFile = queueDir `pjoin` "serial"
124

    
125
-- | Job queue lock file
126
jobQueueLockFile :: IO FilePath
127
jobQueueLockFile = queueDir `pjoin` "lock"
128

    
129
-- | Job queue drain file
130
jobQueueDrainFile :: IO FilePath
131
jobQueueDrainFile = queueDir `pjoin` "drain"
132

    
133
-- | Job queue archive directory.
134
jobQueueArchiveSubDir :: FilePath
135
jobQueueArchiveSubDir = "archive"
136

    
137
-- | Directory containing the reason trails for the last change of status of
138
-- instances.
139
instanceReasonDir :: IO FilePath
140
instanceReasonDir = runDir `pjoin` "instance-reason"
141

    
142
-- | The path of the file containing the reason trail for an instance, given the
143
-- instance name.
144
getInstReasonFilename :: String -> IO FilePath
145
getInstReasonFilename instName = instanceReasonDir `pjoin` instName