Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Path.hs @ cefd4a4a

History | View | Annotate | Download (2.5 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 29a30533 Iustin Pop
  ) where
37 9eeb0aa5 Michael Hanselmann
38 9eeb0aa5 Michael Hanselmann
import System.FilePath
39 2f441f72 Michael Hanselmann
import System.Posix.Env (getEnvDefault)
40 2f441f72 Michael Hanselmann
41 29a30533 Iustin Pop
import qualified Ganeti.Constants as C
42 9eeb0aa5 Michael Hanselmann
43 29a30533 Iustin Pop
-- | Simple helper to concat two paths.
44 29a30533 Iustin Pop
pjoin :: IO String -> String -> IO String
45 29a30533 Iustin Pop
pjoin a b = do
46 29a30533 Iustin Pop
  a' <- a
47 29a30533 Iustin Pop
  return $ a' </> b
48 29a30533 Iustin Pop
49 29a30533 Iustin Pop
-- | Returns the root directory, which can be either the real root or
50 29a30533 Iustin Pop
-- the virtual root.
51 29a30533 Iustin Pop
getRootDir :: IO FilePath
52 29a30533 Iustin Pop
getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
53 29a30533 Iustin Pop
54 29a30533 Iustin Pop
-- | Prefixes a path with the current root directory.
55 29a30533 Iustin Pop
addNodePrefix :: FilePath -> IO FilePath
56 29a30533 Iustin Pop
addNodePrefix path = do
57 29a30533 Iustin Pop
  root <- getRootDir
58 29a30533 Iustin Pop
  return $ root ++ path
59 29a30533 Iustin Pop
60 29a30533 Iustin Pop
-- | Directory for data.
61 29a30533 Iustin Pop
dataDir :: IO FilePath
62 2f441f72 Michael Hanselmann
dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
63 9eeb0aa5 Michael Hanselmann
64 29a30533 Iustin Pop
-- | Directory for runtime files.
65 29a30533 Iustin Pop
runDir :: IO FilePath
66 2f441f72 Michael Hanselmann
runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
67 9eeb0aa5 Michael Hanselmann
68 29a30533 Iustin Pop
-- | Directory for log files.
69 29a30533 Iustin Pop
logDir :: IO FilePath
70 2f441f72 Michael Hanselmann
logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
71 9eeb0aa5 Michael Hanselmann
72 29a30533 Iustin Pop
-- | Directory for Unix sockets.
73 29a30533 Iustin Pop
socketDir :: IO FilePath
74 29a30533 Iustin Pop
socketDir = runDir `pjoin` "socket"
75 9eeb0aa5 Michael Hanselmann
76 9eeb0aa5 Michael Hanselmann
-- | The default LUXI socket path.
77 29a30533 Iustin Pop
defaultLuxiSocket :: IO FilePath
78 29a30533 Iustin Pop
defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
79 9eeb0aa5 Michael Hanselmann
80 9eeb0aa5 Michael Hanselmann
-- | The default LUXI socket for queries.
81 29a30533 Iustin Pop
defaultQuerySocket :: IO FilePath
82 29a30533 Iustin Pop
defaultQuerySocket = socketDir `pjoin` "ganeti-query"
83 9eeb0aa5 Michael Hanselmann
84 29a30533 Iustin Pop
-- | Path to file containing confd's HMAC key.
85 29a30533 Iustin Pop
confdHmacKey :: IO FilePath
86 29a30533 Iustin Pop
confdHmacKey = dataDir `pjoin` "hmac.key"
87 9eeb0aa5 Michael Hanselmann
88 29a30533 Iustin Pop
-- | Path to cluster configuration file.
89 29a30533 Iustin Pop
clusterConfFile :: IO FilePath
90 29a30533 Iustin Pop
clusterConfFile  = dataDir `pjoin` "config.data"
91 7766de33 Agata Murawska
92 29a30533 Iustin Pop
-- | Path to the noded certificate.
93 29a30533 Iustin Pop
nodedCertFile  :: IO FilePath
94 29a30533 Iustin Pop
nodedCertFile = dataDir `pjoin` "server.pem"