Revision eebc8ab2

b/src/Ganeti/DataCollectors/InstStatus.hs
43 43
import Network.BSD (getHostName)
44 44
import qualified Text.JSON as J
45 45

  
46
import Ganeti.BasicTypes as BT
46 47
import Ganeti.Confd.ClientFunctions
47 48
import Ganeti.Common
48 49
import Ganeti.DataCollectors.CLI
......
181 182
  node <- getHostName
182 183
  answer <- getInstances node srvAddr srvPort
183 184
  inst <- exitIfBad "Can't get instance info from ConfD" answer
184
  domains <- getInferredDomInfo
185
  uptimes <- getUptimeInfo
186
  let primaryInst =  fst inst
187
  iStatus <- mapM (buildStatus domains uptimes) primaryInst
188
  let globalStatus = computeGlobalStatus iStatus
189
      jsonReport = J.showJSON $ ReportData iStatus globalStatus
185
  d <- getInferredDomInfo
186
  reportData <-
187
    case d of
188
      BT.Ok domains -> do
189
        uptimes <- getUptimeInfo
190
        let primaryInst =  fst inst
191
        iStatus <- mapM (buildStatus domains uptimes) primaryInst
192
        let globalStatus = computeGlobalStatus iStatus
193
        return $ ReportData iStatus globalStatus
194
      BT.Bad m ->
195
        return . ReportData [] . DCStatus DCSCBad $
196
          "Unable to receive the list of instances: " ++ m
197
  let jsonReport = J.showJSON reportData
190 198
  buildReport dcName dcVersion dcFormatVersion dcCategory dcKind jsonReport
191 199

  
192 200
-- | Main function.
b/src/Ganeti/Hypervisor/Xen.hs
40 40
import qualified Ganeti.Constants as C
41 41
import Ganeti.Hypervisor.Xen.Types
42 42
import Ganeti.Hypervisor.Xen.XmParser
43
import Ganeti.Logging
43 44
import Ganeti.Utils
44 45

  
45 46

  
46 47
-- | Get information about the current Xen domains as a map where the domain
47 48
-- name is the key. This only includes the information made available by Xen
48 49
-- itself.
49
getDomainsInfo :: IO (Map.Map String Domain)
50
getDomainsInfo :: IO (BT.Result (Map.Map String Domain))
50 51
getDomainsInfo = do
51 52
  contents <-
52
    ((E.try $ readProcess C.xenCmdXm ["list", "--long"] "")
53
      :: IO (Either IOError String)) >>=
54
      exitIfBad "running command" . either (BT.Bad . show) BT.Ok
55
  case A.parseOnly xmListParser $ pack contents of
56
    Left msg -> exitErr msg
57
    Right dom -> return dom
53
        (E.try $ readProcess C.xenCmdXm ["list", "--long"] "")
54
          :: IO (Either IOError String)
55
  return $
56
    either (BT.Bad . show) (
57
      \c ->
58
        case A.parseOnly xmListParser $ pack c of
59
          Left msg -> BT.Bad msg
60
          Right dom -> BT.Ok dom
61
      ) contents
58 62

  
59 63
-- | Given a domain and a map containing information about multiple domains,
60 64
-- infer additional information about that domain (specifically, whether it is
......
70 74
-- name is the key. This includes information made available by Xen itself as
71 75
-- well as further information that can be inferred by querying Xen multiple
72 76
-- times and comparing the results.
73
getInferredDomInfo :: IO (Map.Map String Domain)
77
getInferredDomInfo :: IO (BT.Result (Map.Map String Domain))
74 78
getInferredDomInfo = do
75 79
  domMap1 <- getDomainsInfo
76 80
  domMap2 <- getDomainsInfo
77
  return $ fmap (inferDomInfos domMap2) domMap1
81
  case (domMap1, domMap2) of
82
    (BT.Bad m1, BT.Bad m2) -> return . BT.Bad $ m1 ++ "\n" ++ m2
83
    (BT.Bad m, BT.Ok d) -> do
84
      logWarning $ "Unable to retrieve domains info the first time" ++ m
85
      return $ BT.Ok d
86
    (BT.Ok d, BT.Bad m) -> do
87
      logWarning $ "Unable to retrieve domains info the second time" ++ m
88
      return $ BT.Ok d
89
    (BT.Ok d1, BT.Ok d2) -> return . BT.Ok $ fmap (inferDomInfos d2) d1
78 90

  
79 91
-- | Get information about the uptime of domains, as a map where the domain ID
80 92
-- is the key.

Also available in: Unified diff