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 , jobQueueArchiveSubDir
40 , getInstReasonFilename
43 import System.FilePath
44 import System.Posix.Env (getEnvDefault)
48 -- | Simple helper to concat two paths.
49 pjoin :: IO String -> String -> IO String
54 -- | Returns the root directory, which can be either the real root or
56 getRootDir :: IO FilePath
57 getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
59 -- | Prefixes a path with the current root directory.
60 addNodePrefix :: FilePath -> IO FilePath
61 addNodePrefix path = do
65 -- | Directory for data.
66 dataDir :: IO FilePath
67 dataDir = addNodePrefix $ AutoConf.localstatedir </> "lib" </> "ganeti"
69 -- | Helper for building on top of dataDir (internal).
70 dataDirP :: FilePath -> IO FilePath
71 dataDirP = (dataDir `pjoin`)
73 -- | Directory for runtime files.
75 runDir = addNodePrefix $ AutoConf.localstatedir </> "run" </> "ganeti"
77 -- | Directory for log files.
79 logDir = addNodePrefix $ AutoConf.localstatedir </> "log" </> "ganeti"
81 -- | Directory for Unix sockets.
82 socketDir :: IO FilePath
83 socketDir = runDir `pjoin` "socket"
85 -- | The default LUXI socket path.
86 defaultLuxiSocket :: IO FilePath
87 defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
89 -- | The default LUXI socket for queries.
90 defaultQuerySocket :: IO FilePath
91 defaultQuerySocket = socketDir `pjoin` "ganeti-query"
93 -- | Path to file containing confd's HMAC key.
94 confdHmacKey :: IO FilePath
95 confdHmacKey = dataDirP "hmac.key"
97 -- | Path to cluster configuration file.
98 clusterConfFile :: IO FilePath
99 clusterConfFile = dataDirP "config.data"
101 -- | Path to the noded certificate.
102 nodedCertFile :: IO FilePath
103 nodedCertFile = dataDirP "server.pem"
105 -- | Job queue directory.
106 queueDir :: IO FilePath
107 queueDir = dataDirP "queue"
109 -- | Job queue serial file.
110 jobQueueSerialFile :: IO FilePath
111 jobQueueSerialFile = dataDirP "serial"
113 -- | Job queue archive directory.
114 jobQueueArchiveSubDir :: FilePath
115 jobQueueArchiveSubDir = "archive"
117 -- | Directory containing the reason trails for the last change of status of
119 instanceReasonDir :: IO FilePath
120 instanceReasonDir = runDir `pjoin` "instance-reason"
122 -- | The path of the file containing the reason trail for an instance, given the
124 getInstReasonFilename :: String -> IO FilePath
125 getInstReasonFilename instName = instanceReasonDir `pjoin` instName