Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Path.hs @ 29a30533

History | View | Annotate | Download (2.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
  ) where
37

    
38
import System.FilePath
39
import System.Posix.Env (getEnvDefault)
40

    
41
import qualified Ganeti.Constants as C
42

    
43
-- | Simple helper to concat two paths.
44
pjoin :: IO String -> String -> IO String
45
pjoin a b = do
46
  a' <- a
47
  return $ a' </> b
48

    
49
-- | Returns the root directory, which can be either the real root or
50
-- the virtual root.
51
getRootDir :: IO FilePath
52
getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
53

    
54
-- | Prefixes a path with the current root directory.
55
addNodePrefix :: FilePath -> IO FilePath
56
addNodePrefix path = do
57
  root <- getRootDir
58
  return $ root ++ path
59

    
60
-- | Directory for data.
61
dataDir :: IO FilePath
62
dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
63

    
64
-- | Directory for runtime files.
65
runDir :: IO FilePath
66
runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
67

    
68
-- | Directory for log files.
69
logDir :: IO FilePath
70
logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
71

    
72
-- | Directory for Unix sockets.
73
socketDir :: IO FilePath
74
socketDir = runDir `pjoin` "socket"
75

    
76
-- | The default LUXI socket path.
77
defaultLuxiSocket :: IO FilePath
78
defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
79

    
80
-- | The default LUXI socket for queries.
81
defaultQuerySocket :: IO FilePath
82
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
83

    
84
-- | Path to file containing confd's HMAC key.
85
confdHmacKey :: IO FilePath
86
confdHmacKey = dataDir `pjoin` "hmac.key"
87

    
88
-- | Path to cluster configuration file.
89
clusterConfFile :: IO FilePath
90
clusterConfFile  = dataDir `pjoin` "config.data"
91

    
92
-- | Path to the noded certificate.
93
nodedCertFile  :: IO FilePath
94
nodedCertFile = dataDir `pjoin` "server.pem"