Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Path.hs @ e181c8cd

History | View | Annotate | Download (4.7 kB)

1 9eeb0aa5 Michael Hanselmann
{-| Path-related helper functions.
2 9eeb0aa5 Michael Hanselmann
3 9eeb0aa5 Michael Hanselmann
-}
4 9eeb0aa5 Michael Hanselmann
5 9eeb0aa5 Michael Hanselmann
{-
6 9eeb0aa5 Michael Hanselmann
7 582bfaf6 Jose A. Lopes
Copyright (C) 2012, 2014 Google Inc.
8 9eeb0aa5 Michael Hanselmann
9 9eeb0aa5 Michael Hanselmann
This program is free software; you can redistribute it and/or modify
10 9eeb0aa5 Michael Hanselmann
it under the terms of the GNU General Public License as published by
11 9eeb0aa5 Michael Hanselmann
the Free Software Foundation; either version 2 of the License, or
12 9eeb0aa5 Michael Hanselmann
(at your option) any later version.
13 9eeb0aa5 Michael Hanselmann
14 9eeb0aa5 Michael Hanselmann
This program is distributed in the hope that it will be useful, but
15 9eeb0aa5 Michael Hanselmann
WITHOUT ANY WARRANTY; without even the implied warranty of
16 9eeb0aa5 Michael Hanselmann
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 9eeb0aa5 Michael Hanselmann
General Public License for more details.
18 9eeb0aa5 Michael Hanselmann
19 9eeb0aa5 Michael Hanselmann
You should have received a copy of the GNU General Public License
20 9eeb0aa5 Michael Hanselmann
along with this program; if not, write to the Free Software
21 9eeb0aa5 Michael Hanselmann
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 9eeb0aa5 Michael Hanselmann
02110-1301, USA.
23 9eeb0aa5 Michael Hanselmann
24 9eeb0aa5 Michael Hanselmann
-}
25 9eeb0aa5 Michael Hanselmann
26 29a30533 Iustin Pop
module Ganeti.Path
27 29a30533 Iustin Pop
  ( dataDir
28 29a30533 Iustin Pop
  , runDir
29 29a30533 Iustin Pop
  , logDir
30 29a30533 Iustin Pop
  , socketDir
31 2745aa81 Petr Pudlak
  , livelockDir
32 2745aa81 Petr Pudlak
  , livelockFile
33 9d049fb4 Klaus Aehlig
  , defaultMasterSocket
34 29a30533 Iustin Pop
  , defaultQuerySocket
35 59881a0b Petr Pudlak
  , defaultWConfdSocket
36 29a30533 Iustin Pop
  , confdHmacKey
37 29a30533 Iustin Pop
  , clusterConfFile
38 f3eb4bfd Klaus Aehlig
  , lockStatusFile
39 4b7863cb Klaus Aehlig
  , watcherPauseFile
40 29a30533 Iustin Pop
  , nodedCertFile
41 b3cc1646 Helga Velroyen
  , nodedClientCertFile
42 1db32048 Iustin Pop
  , queueDir
43 1db32048 Iustin Pop
  , jobQueueSerialFile
44 582bfaf6 Jose A. Lopes
  , jobQueueLockFile
45 582bfaf6 Jose A. Lopes
  , jobQueueDrainFile
46 1db32048 Iustin Pop
  , jobQueueArchiveSubDir
47 74b25887 Michele Tartara
  , instanceReasonDir
48 74b25887 Michele Tartara
  , getInstReasonFilename
49 7b4bde57 Petr Pudlak
  , jqueueExecutorPy
50 29a30533 Iustin Pop
  ) where
51 9eeb0aa5 Michael Hanselmann
52 9eeb0aa5 Michael Hanselmann
import System.FilePath
53 2f441f72 Michael Hanselmann
import System.Posix.Env (getEnvDefault)
54 2f441f72 Michael Hanselmann
55 f81d41cc Jose A. Lopes
import AutoConf
56 9eeb0aa5 Michael Hanselmann
57 29a30533 Iustin Pop
-- | Simple helper to concat two paths.
58 29a30533 Iustin Pop
pjoin :: IO String -> String -> IO String
59 29a30533 Iustin Pop
pjoin a b = do
60 29a30533 Iustin Pop
  a' <- a
61 29a30533 Iustin Pop
  return $ a' </> b
62 29a30533 Iustin Pop
63 29a30533 Iustin Pop
-- | Returns the root directory, which can be either the real root or
64 29a30533 Iustin Pop
-- the virtual root.
65 29a30533 Iustin Pop
getRootDir :: IO FilePath
66 29a30533 Iustin Pop
getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
67 29a30533 Iustin Pop
68 29a30533 Iustin Pop
-- | Prefixes a path with the current root directory.
69 29a30533 Iustin Pop
addNodePrefix :: FilePath -> IO FilePath
70 29a30533 Iustin Pop
addNodePrefix path = do
71 29a30533 Iustin Pop
  root <- getRootDir
72 29a30533 Iustin Pop
  return $ root ++ path
73 29a30533 Iustin Pop
74 29a30533 Iustin Pop
-- | Directory for data.
75 29a30533 Iustin Pop
dataDir :: IO FilePath
76 f81d41cc Jose A. Lopes
dataDir = addNodePrefix $ AutoConf.localstatedir </> "lib" </> "ganeti"
77 9eeb0aa5 Michael Hanselmann
78 1db32048 Iustin Pop
-- | Helper for building on top of dataDir (internal).
79 1db32048 Iustin Pop
dataDirP :: FilePath -> IO FilePath
80 1db32048 Iustin Pop
dataDirP = (dataDir `pjoin`)
81 1db32048 Iustin Pop
82 29a30533 Iustin Pop
-- | Directory for runtime files.
83 29a30533 Iustin Pop
runDir :: IO FilePath
84 f81d41cc Jose A. Lopes
runDir = addNodePrefix $ AutoConf.localstatedir </> "run" </> "ganeti"
85 9eeb0aa5 Michael Hanselmann
86 29a30533 Iustin Pop
-- | Directory for log files.
87 29a30533 Iustin Pop
logDir :: IO FilePath
88 f81d41cc Jose A. Lopes
logDir = addNodePrefix $ AutoConf.localstatedir </> "log" </> "ganeti"
89 9eeb0aa5 Michael Hanselmann
90 29a30533 Iustin Pop
-- | Directory for Unix sockets.
91 29a30533 Iustin Pop
socketDir :: IO FilePath
92 29a30533 Iustin Pop
socketDir = runDir `pjoin` "socket"
93 9eeb0aa5 Michael Hanselmann
94 2745aa81 Petr Pudlak
-- | Directory for the jobs' livelocks.
95 2745aa81 Petr Pudlak
livelockDir :: IO FilePath
96 2745aa81 Petr Pudlak
livelockDir = runDir `pjoin` "livelocks"
97 2745aa81 Petr Pudlak
98 2745aa81 Petr Pudlak
-- | A helper for building a job's livelock file. It prepends
99 2745aa81 Petr Pudlak
-- 'livelockDir' to a given filename.
100 2745aa81 Petr Pudlak
livelockFile :: FilePath -> IO FilePath
101 2745aa81 Petr Pudlak
livelockFile = pjoin livelockDir
102 2745aa81 Petr Pudlak
103 9d049fb4 Klaus Aehlig
-- | The default path for the master-daemon LUXI socket.
104 9d049fb4 Klaus Aehlig
defaultMasterSocket :: IO FilePath
105 9d049fb4 Klaus Aehlig
defaultMasterSocket = socketDir `pjoin` "ganeti-master"
106 9eeb0aa5 Michael Hanselmann
107 9eeb0aa5 Michael Hanselmann
-- | The default LUXI socket for queries.
108 29a30533 Iustin Pop
defaultQuerySocket :: IO FilePath
109 29a30533 Iustin Pop
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
110 9eeb0aa5 Michael Hanselmann
111 59881a0b Petr Pudlak
-- | The default WConfD socket for queries.
112 59881a0b Petr Pudlak
defaultWConfdSocket :: IO FilePath
113 59881a0b Petr Pudlak
defaultWConfdSocket = socketDir `pjoin` "ganeti-wconfd"
114 59881a0b Petr Pudlak
115 29a30533 Iustin Pop
-- | Path to file containing confd's HMAC key.
116 29a30533 Iustin Pop
confdHmacKey :: IO FilePath
117 1db32048 Iustin Pop
confdHmacKey = dataDirP "hmac.key"
118 9eeb0aa5 Michael Hanselmann
119 29a30533 Iustin Pop
-- | Path to cluster configuration file.
120 29a30533 Iustin Pop
clusterConfFile :: IO FilePath
121 1db32048 Iustin Pop
clusterConfFile  = dataDirP "config.data"
122 7766de33 Agata Murawska
123 f3eb4bfd Klaus Aehlig
-- | Path to the file representing the lock status.
124 f3eb4bfd Klaus Aehlig
lockStatusFile :: IO FilePath
125 f3eb4bfd Klaus Aehlig
lockStatusFile  = dataDirP "locks.data"
126 f3eb4bfd Klaus Aehlig
127 4b7863cb Klaus Aehlig
-- | Path to the watcher pause file.
128 4b7863cb Klaus Aehlig
watcherPauseFile :: IO FilePath
129 4b7863cb Klaus Aehlig
watcherPauseFile = dataDirP "watcher.pause"
130 4b7863cb Klaus Aehlig
131 29a30533 Iustin Pop
-- | Path to the noded certificate.
132 1db32048 Iustin Pop
nodedCertFile :: IO FilePath
133 1db32048 Iustin Pop
nodedCertFile = dataDirP "server.pem"
134 1db32048 Iustin Pop
135 b3cc1646 Helga Velroyen
-- | Path to the noded client certificate.
136 b3cc1646 Helga Velroyen
nodedClientCertFile :: IO FilePath
137 b3cc1646 Helga Velroyen
nodedClientCertFile = dataDirP "client.pem"
138 b3cc1646 Helga Velroyen
139 1db32048 Iustin Pop
-- | Job queue directory.
140 1db32048 Iustin Pop
queueDir :: IO FilePath
141 1db32048 Iustin Pop
queueDir = dataDirP "queue"
142 1db32048 Iustin Pop
143 1db32048 Iustin Pop
-- | Job queue serial file.
144 1db32048 Iustin Pop
jobQueueSerialFile :: IO FilePath
145 6fe0f9a6 Klaus Aehlig
jobQueueSerialFile = queueDir `pjoin` "serial"
146 1db32048 Iustin Pop
147 02926b4b Klaus Aehlig
-- | Job queue lock file
148 02926b4b Klaus Aehlig
jobQueueLockFile :: IO FilePath
149 02926b4b Klaus Aehlig
jobQueueLockFile = queueDir `pjoin` "lock"
150 02926b4b Klaus Aehlig
151 e773a018 Klaus Aehlig
-- | Job queue drain file
152 e773a018 Klaus Aehlig
jobQueueDrainFile :: IO FilePath
153 e773a018 Klaus Aehlig
jobQueueDrainFile = queueDir `pjoin` "drain"
154 e773a018 Klaus Aehlig
155 1db32048 Iustin Pop
-- | Job queue archive directory.
156 1db32048 Iustin Pop
jobQueueArchiveSubDir :: FilePath
157 1db32048 Iustin Pop
jobQueueArchiveSubDir = "archive"
158 74b25887 Michele Tartara
159 74b25887 Michele Tartara
-- | Directory containing the reason trails for the last change of status of
160 74b25887 Michele Tartara
-- instances.
161 74b25887 Michele Tartara
instanceReasonDir :: IO FilePath
162 74b25887 Michele Tartara
instanceReasonDir = runDir `pjoin` "instance-reason"
163 74b25887 Michele Tartara
164 74b25887 Michele Tartara
-- | The path of the file containing the reason trail for an instance, given the
165 74b25887 Michele Tartara
-- instance name.
166 74b25887 Michele Tartara
getInstReasonFilename :: String -> IO FilePath
167 74b25887 Michele Tartara
getInstReasonFilename instName = instanceReasonDir `pjoin` instName
168 7b4bde57 Petr Pudlak
169 7b4bde57 Petr Pudlak
-- | The path to the Python executable for starting jobs.
170 7b4bde57 Petr Pudlak
jqueueExecutorPy :: IO FilePath
171 7b4bde57 Petr Pudlak
jqueueExecutorPy = return $ versionedsharedir
172 7b4bde57 Petr Pudlak
                            </> "ganeti" </> "jqueue" </> "exec.py"