Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Query / Cluster.hs @ c92b4671

History | View | Annotate | Download (2 kB)

1
{-| Implementation of the Ganeti Query2 cluster queries.
2

    
3
 -}
4

    
5
{-
6

    
7
Copyright (C) 2012, 2013 Google Inc.
8

    
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.
13

    
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.
18

    
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
22
02110-1301, USA.
23

    
24
-}
25

    
26
module Ganeti.Query.Cluster
27
  ( clusterMasterNodeName
28
  , isWatcherPaused
29
  ) where
30

    
31
import Control.Exception (try)
32
import Control.Monad (liftM)
33
import Data.Char (isSpace)
34
import Numeric (readDec)
35

    
36
import Ganeti.Config
37
import Ganeti.Errors
38
import Ganeti.Logging
39
import Ganeti.Objects
40
import Ganeti.Path
41
import Ganeti.Utils (getCurrentTime)
42

    
43
-- | Get master node name.
44
clusterMasterNodeName :: ConfigData -> ErrorResult String
45
clusterMasterNodeName cfg =
46
  let cluster = configCluster cfg
47
      masterNodeUuid = clusterMasterNode cluster
48
  in liftM nodeName $ getNode cfg masterNodeUuid
49

    
50
isWatcherPaused :: IO (Maybe Integer)
51
isWatcherPaused = do
52
  logDebug "Checking if the watcher is paused"
53
  wfile <- watcherPauseFile
54
  contents <- try $ readFile wfile :: IO (Either IOError String)
55
  case contents of
56
    Left _ -> return Nothing
57
    Right s -> case readDec (dropWhile isSpace s) of
58
                 [(n, rest)] | all isSpace rest -> do
59
                   now <- getCurrentTime
60
                   return $ if n > now then Just n else Nothing
61
                 _ -> do
62
                   logWarning $ "Watcher pause file contents '" ++ s
63
                                 ++ "' not parsable as int"
64
                   return Nothing