1 {-| Path-related helper functions.
7 Copyright (C) 2012 Google Inc.
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.
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.
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
38 import System.FilePath
39 import System.Posix.Env (getEnvDefault)
41 import qualified Ganeti.Constants as C
43 -- | Simple helper to concat two paths.
44 pjoin :: IO String -> String -> IO String
49 -- | Returns the root directory, which can be either the real root or
51 getRootDir :: IO FilePath
52 getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
54 -- | Prefixes a path with the current root directory.
55 addNodePrefix :: FilePath -> IO FilePath
56 addNodePrefix path = do
60 -- | Directory for data.
61 dataDir :: IO FilePath
62 dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
64 -- | Directory for runtime files.
66 runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
68 -- | Directory for log files.
70 logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
72 -- | Directory for Unix sockets.
73 socketDir :: IO FilePath
74 socketDir = runDir `pjoin` "socket"
76 -- | The default LUXI socket path.
77 defaultLuxiSocket :: IO FilePath
78 defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
80 -- | The default LUXI socket for queries.
81 defaultQuerySocket :: IO FilePath
82 defaultQuerySocket = socketDir `pjoin` "ganeti-query"
84 -- | Path to file containing confd's HMAC key.
85 confdHmacKey :: IO FilePath
86 confdHmacKey = dataDir `pjoin` "hmac.key"
88 -- | Path to cluster configuration file.
89 clusterConfFile :: IO FilePath
90 clusterConfFile = dataDir `pjoin` "config.data"
92 -- | Path to the noded certificate.
93 nodedCertFile :: IO FilePath
94 nodedCertFile = dataDir `pjoin` "server.pem"