Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Query / Cluster.hs @ 88772d17

History | View | Annotate | Download (2 kB)

1 1c3231aa Thomas Thrainer
{-| Implementation of the Ganeti Query2 cluster queries.
2 1c3231aa Thomas Thrainer
3 1c3231aa Thomas Thrainer
 -}
4 1c3231aa Thomas Thrainer
5 1c3231aa Thomas Thrainer
{-
6 1c3231aa Thomas Thrainer
7 1c3231aa Thomas Thrainer
Copyright (C) 2012, 2013 Google Inc.
8 1c3231aa Thomas Thrainer
9 1c3231aa Thomas Thrainer
This program is free software; you can redistribute it and/or modify
10 1c3231aa Thomas Thrainer
it under the terms of the GNU General Public License as published by
11 1c3231aa Thomas Thrainer
the Free Software Foundation; either version 2 of the License, or
12 1c3231aa Thomas Thrainer
(at your option) any later version.
13 1c3231aa Thomas Thrainer
14 1c3231aa Thomas Thrainer
This program is distributed in the hope that it will be useful, but
15 1c3231aa Thomas Thrainer
WITHOUT ANY WARRANTY; without even the implied warranty of
16 1c3231aa Thomas Thrainer
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 1c3231aa Thomas Thrainer
General Public License for more details.
18 1c3231aa Thomas Thrainer
19 1c3231aa Thomas Thrainer
You should have received a copy of the GNU General Public License
20 1c3231aa Thomas Thrainer
along with this program; if not, write to the Free Software
21 1c3231aa Thomas Thrainer
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 1c3231aa Thomas Thrainer
02110-1301, USA.
23 1c3231aa Thomas Thrainer
24 1c3231aa Thomas Thrainer
-}
25 1c3231aa Thomas Thrainer
26 1c3231aa Thomas Thrainer
module Ganeti.Query.Cluster
27 1c3231aa Thomas Thrainer
  ( clusterMasterNodeName
28 7f58ff5d Klaus Aehlig
  , isWatcherPaused
29 1c3231aa Thomas Thrainer
  ) where
30 1c3231aa Thomas Thrainer
31 7f58ff5d Klaus Aehlig
import Control.Exception (try)
32 1c3231aa Thomas Thrainer
import Control.Monad (liftM)
33 7f58ff5d Klaus Aehlig
import Data.Char (isSpace)
34 7f58ff5d Klaus Aehlig
import Numeric (readDec)
35 1c3231aa Thomas Thrainer
36 1c3231aa Thomas Thrainer
import Ganeti.Config
37 1c3231aa Thomas Thrainer
import Ganeti.Errors
38 7f58ff5d Klaus Aehlig
import Ganeti.Logging
39 7f58ff5d Klaus Aehlig
import Ganeti.Objects
40 7f58ff5d Klaus Aehlig
import Ganeti.Path
41 7f58ff5d Klaus Aehlig
import Ganeti.Utils (getCurrentTime)
42 1c3231aa Thomas Thrainer
43 1c3231aa Thomas Thrainer
-- | Get master node name.
44 1c3231aa Thomas Thrainer
clusterMasterNodeName :: ConfigData -> ErrorResult String
45 1c3231aa Thomas Thrainer
clusterMasterNodeName cfg =
46 1c3231aa Thomas Thrainer
  let cluster = configCluster cfg
47 1c3231aa Thomas Thrainer
      masterNodeUuid = clusterMasterNode cluster
48 1c3231aa Thomas Thrainer
  in liftM nodeName $ getNode cfg masterNodeUuid
49 7f58ff5d Klaus Aehlig
50 7f58ff5d Klaus Aehlig
isWatcherPaused :: IO (Maybe Integer)
51 7f58ff5d Klaus Aehlig
isWatcherPaused = do
52 7f58ff5d Klaus Aehlig
  logDebug "Checking if the watcher is paused"
53 7f58ff5d Klaus Aehlig
  wfile <- watcherPauseFile
54 7f58ff5d Klaus Aehlig
  contents <- try $ readFile wfile :: IO (Either IOError String)
55 7f58ff5d Klaus Aehlig
  case contents of
56 7f58ff5d Klaus Aehlig
    Left _ -> return Nothing
57 7f58ff5d Klaus Aehlig
    Right s -> case readDec (dropWhile isSpace s) of
58 7f58ff5d Klaus Aehlig
                 [(n, rest)] | all isSpace rest -> do
59 7f58ff5d Klaus Aehlig
                   now <- getCurrentTime
60 7f58ff5d Klaus Aehlig
                   return $ if n > now then Just n else Nothing
61 7f58ff5d Klaus Aehlig
                 _ -> do
62 7f58ff5d Klaus Aehlig
                   logWarning $ "Watcher pause file contents '" ++ s
63 7f58ff5d Klaus Aehlig
                                 ++ "' not parsable as int"
64 7f58ff5d Klaus Aehlig
                   return Nothing