Revision 9188aeef Ganeti/HTools/Rapi.hs
b/Ganeti/HTools/Rapi.hs | ||
---|---|---|
21 | 21 |
import qualified Ganeti.HTools.Node as Node |
22 | 22 |
import qualified Ganeti.HTools.Instance as Instance |
23 | 23 |
|
24 |
-- | Read an URL via curl and return the body if successful |
|
24 |
-- | Read an URL via curl and return the body if successful.
|
|
25 | 25 |
getUrl :: (Monad m) => String -> IO (m String) |
26 | 26 |
getUrl url = do |
27 | 27 |
(code, body) <- curlGetString url [CurlSSLVerifyPeer False, |
... | ... | |
31 | 31 |
_ -> fail $ printf "Curl error for '%s', error %s" |
32 | 32 |
url (show code)) |
33 | 33 |
|
34 |
-- | Append the default port if not passed in |
|
34 |
-- | Append the default port if not passed in.
|
|
35 | 35 |
formatHost :: String -> String |
36 | 36 |
formatHost master = |
37 | 37 |
if elem ':' master then master |
38 | 38 |
else "https://" ++ master ++ ":5080" |
39 | 39 |
|
40 |
-- | Parse a instance list in JSON format. |
|
40 | 41 |
getInstances :: NameAssoc |
41 | 42 |
-> String |
42 | 43 |
-> Result [(String, Instance.Instance)] |
... | ... | |
45 | 46 |
ilist <- mapM (parseInstance ktn) arr |
46 | 47 |
return ilist |
47 | 48 |
|
49 |
-- | Parse a node list in JSON format. |
|
48 | 50 |
getNodes :: String -> Result [(String, Node.Node)] |
49 | 51 |
getNodes body = do |
50 | 52 |
arr <- loadJSArray body |
51 | 53 |
nlist <- mapM parseNode arr |
52 | 54 |
return nlist |
53 | 55 |
|
56 |
-- | Construct an instance from a JSON object. |
|
54 | 57 |
parseInstance :: [(String, Ndx)] |
55 | 58 |
-> JSObject JSValue |
56 | 59 |
-> Result (String, Instance.Instance) |
... | ... | |
66 | 69 |
let inst = Instance.create name mem disk running pnode snode |
67 | 70 |
return (name, inst) |
68 | 71 |
|
72 |
-- | Construct a node from a JSON object. |
|
69 | 73 |
parseNode :: JSObject JSValue -> Result (String, Node.Node) |
70 | 74 |
parseNode a = do |
71 | 75 |
name <- fromObj "name" a |
... | ... | |
83 | 87 |
dtotal dfree (offline || drained)) |
84 | 88 |
return (name, node) |
85 | 89 |
|
90 |
-- | Builds the cluster data from an URL. |
|
86 | 91 |
loadData :: String -- ^ Cluster or URL to use as source |
87 | 92 |
-> IO (Result (Node.AssocList, Instance.AssocList)) |
88 | 93 |
loadData master = do -- IO monad |
Also available in: Unified diff