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