Revision 9f6dcdea Ganeti/HTools/Rapi.hs
b/Ganeti/HTools/Rapi.hs | ||
---|---|---|
62 | 62 |
getInstances :: NameAssoc |
63 | 63 |
-> String |
64 | 64 |
-> Result [(String, Instance.Instance)] |
65 |
getInstances ktn body = do |
|
66 |
arr <- loadJSArray body |
|
67 |
ilist <- mapM (parseInstance ktn) arr |
|
68 |
return ilist |
|
65 |
getInstances ktn body = loadJSArray body >>= mapM (parseInstance ktn) |
|
69 | 66 |
|
70 | 67 |
-- | Parse a node list in JSON format. |
71 | 68 |
getNodes :: String -> Result [(String, Node.Node)] |
72 |
getNodes body = do |
|
73 |
arr <- loadJSArray body |
|
74 |
nlist <- mapM parseNode arr |
|
75 |
return nlist |
|
69 |
getNodes body = loadJSArray body >>= mapM parseNode |
|
76 | 70 |
|
77 | 71 |
-- | Construct an instance from a JSON object. |
78 | 72 |
parseInstance :: [(String, Ndx)] |
... | ... | |
96 | 90 |
parseNode a = do |
97 | 91 |
name <- fromObj "name" a |
98 | 92 |
offline <- fromObj "offline" a |
99 |
node <- (case offline of
|
|
100 |
True -> return $ Node.create name 0 0 0 0 0 0 True
|
|
101 |
_ -> do
|
|
102 |
drained <- fromObj "drained" a
|
|
103 |
mtotal <- fromObj "mtotal" a
|
|
104 |
mnode <- fromObj "mnode" a
|
|
105 |
mfree <- fromObj "mfree" a
|
|
106 |
dtotal <- fromObj "dtotal" a
|
|
107 |
dfree <- fromObj "dfree" a
|
|
108 |
ctotal <- fromObj "ctotal" a
|
|
109 |
return $ Node.create name mtotal mnode mfree
|
|
110 |
dtotal dfree ctotal (offline || drained))
|
|
93 |
node <- (if offline
|
|
94 |
then return $ Node.create name 0 0 0 0 0 0 True
|
|
95 |
else do
|
|
96 |
drained <- fromObj "drained" a |
|
97 |
mtotal <- fromObj "mtotal" a |
|
98 |
mnode <- fromObj "mnode" a |
|
99 |
mfree <- fromObj "mfree" a |
|
100 |
dtotal <- fromObj "dtotal" a |
|
101 |
dfree <- fromObj "dfree" a |
|
102 |
ctotal <- fromObj "ctotal" a |
|
103 |
return $ Node.create name mtotal mnode mfree |
|
104 |
dtotal dfree ctotal (offline || drained)) |
|
111 | 105 |
return (name, node) |
112 | 106 |
|
113 | 107 |
-- | Builds the cluster data from an URL. |
Also available in: Unified diff