Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Path.hs @ 07e68848

History | View | Annotate | Download (3.4 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 9eeb0aa5 Michael Hanselmann
Copyright (C) 2012 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 29a30533 Iustin Pop
  , defaultLuxiSocket
32 29a30533 Iustin Pop
  , defaultQuerySocket
33 29a30533 Iustin Pop
  , confdHmacKey
34 29a30533 Iustin Pop
  , clusterConfFile
35 29a30533 Iustin Pop
  , nodedCertFile
36 1db32048 Iustin Pop
  , queueDir
37 1db32048 Iustin Pop
  , jobQueueSerialFile
38 1db32048 Iustin Pop
  , jobQueueArchiveSubDir
39 74b25887 Michele Tartara
  , instanceReasonDir
40 74b25887 Michele Tartara
  , getInstReasonFilename
41 29a30533 Iustin Pop
  ) where
42 9eeb0aa5 Michael Hanselmann
43 9eeb0aa5 Michael Hanselmann
import System.FilePath
44 2f441f72 Michael Hanselmann
import System.Posix.Env (getEnvDefault)
45 2f441f72 Michael Hanselmann
46 f81d41cc Jose A. Lopes
import AutoConf
47 9eeb0aa5 Michael Hanselmann
48 29a30533 Iustin Pop
-- | Simple helper to concat two paths.
49 29a30533 Iustin Pop
pjoin :: IO String -> String -> IO String
50 29a30533 Iustin Pop
pjoin a b = do
51 29a30533 Iustin Pop
  a' <- a
52 29a30533 Iustin Pop
  return $ a' </> b
53 29a30533 Iustin Pop
54 29a30533 Iustin Pop
-- | Returns the root directory, which can be either the real root or
55 29a30533 Iustin Pop
-- the virtual root.
56 29a30533 Iustin Pop
getRootDir :: IO FilePath
57 29a30533 Iustin Pop
getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
58 29a30533 Iustin Pop
59 29a30533 Iustin Pop
-- | Prefixes a path with the current root directory.
60 29a30533 Iustin Pop
addNodePrefix :: FilePath -> IO FilePath
61 29a30533 Iustin Pop
addNodePrefix path = do
62 29a30533 Iustin Pop
  root <- getRootDir
63 29a30533 Iustin Pop
  return $ root ++ path
64 29a30533 Iustin Pop
65 29a30533 Iustin Pop
-- | Directory for data.
66 29a30533 Iustin Pop
dataDir :: IO FilePath
67 f81d41cc Jose A. Lopes
dataDir = addNodePrefix $ AutoConf.localstatedir </> "lib" </> "ganeti"
68 9eeb0aa5 Michael Hanselmann
69 1db32048 Iustin Pop
-- | Helper for building on top of dataDir (internal).
70 1db32048 Iustin Pop
dataDirP :: FilePath -> IO FilePath
71 1db32048 Iustin Pop
dataDirP = (dataDir `pjoin`)
72 1db32048 Iustin Pop
73 29a30533 Iustin Pop
-- | Directory for runtime files.
74 29a30533 Iustin Pop
runDir :: IO FilePath
75 f81d41cc Jose A. Lopes
runDir = addNodePrefix $ AutoConf.localstatedir </> "run" </> "ganeti"
76 9eeb0aa5 Michael Hanselmann
77 29a30533 Iustin Pop
-- | Directory for log files.
78 29a30533 Iustin Pop
logDir :: IO FilePath
79 f81d41cc Jose A. Lopes
logDir = addNodePrefix $ AutoConf.localstatedir </> "log" </> "ganeti"
80 9eeb0aa5 Michael Hanselmann
81 29a30533 Iustin Pop
-- | Directory for Unix sockets.
82 29a30533 Iustin Pop
socketDir :: IO FilePath
83 29a30533 Iustin Pop
socketDir = runDir `pjoin` "socket"
84 9eeb0aa5 Michael Hanselmann
85 9eeb0aa5 Michael Hanselmann
-- | The default LUXI socket path.
86 29a30533 Iustin Pop
defaultLuxiSocket :: IO FilePath
87 29a30533 Iustin Pop
defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
88 9eeb0aa5 Michael Hanselmann
89 9eeb0aa5 Michael Hanselmann
-- | The default LUXI socket for queries.
90 29a30533 Iustin Pop
defaultQuerySocket :: IO FilePath
91 29a30533 Iustin Pop
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
92 9eeb0aa5 Michael Hanselmann
93 29a30533 Iustin Pop
-- | Path to file containing confd's HMAC key.
94 29a30533 Iustin Pop
confdHmacKey :: IO FilePath
95 1db32048 Iustin Pop
confdHmacKey = dataDirP "hmac.key"
96 9eeb0aa5 Michael Hanselmann
97 29a30533 Iustin Pop
-- | Path to cluster configuration file.
98 29a30533 Iustin Pop
clusterConfFile :: IO FilePath
99 1db32048 Iustin Pop
clusterConfFile  = dataDirP "config.data"
100 7766de33 Agata Murawska
101 29a30533 Iustin Pop
-- | Path to the noded certificate.
102 1db32048 Iustin Pop
nodedCertFile :: IO FilePath
103 1db32048 Iustin Pop
nodedCertFile = dataDirP "server.pem"
104 1db32048 Iustin Pop
105 1db32048 Iustin Pop
-- | Job queue directory.
106 1db32048 Iustin Pop
queueDir :: IO FilePath
107 1db32048 Iustin Pop
queueDir = dataDirP "queue"
108 1db32048 Iustin Pop
109 1db32048 Iustin Pop
-- | Job queue serial file.
110 1db32048 Iustin Pop
jobQueueSerialFile :: IO FilePath
111 6fe0f9a6 Klaus Aehlig
jobQueueSerialFile = queueDir `pjoin` "serial"
112 1db32048 Iustin Pop
113 1db32048 Iustin Pop
-- | Job queue archive directory.
114 1db32048 Iustin Pop
jobQueueArchiveSubDir :: FilePath
115 1db32048 Iustin Pop
jobQueueArchiveSubDir = "archive"
116 74b25887 Michele Tartara
117 74b25887 Michele Tartara
-- | Directory containing the reason trails for the last change of status of
118 74b25887 Michele Tartara
-- instances.
119 74b25887 Michele Tartara
instanceReasonDir :: IO FilePath
120 74b25887 Michele Tartara
instanceReasonDir = runDir `pjoin` "instance-reason"
121 74b25887 Michele Tartara
122 74b25887 Michele Tartara
-- | The path of the file containing the reason trail for an instance, given the
123 74b25887 Michele Tartara
-- instance name.
124 74b25887 Michele Tartara
getInstReasonFilename :: String -> IO FilePath
125 74b25887 Michele Tartara
getInstReasonFilename instName = instanceReasonDir `pjoin` instName