Revision 117dc2d8 Ganeti/HTools/Rapi.hs
b/Ganeti/HTools/Rapi.hs | ||
---|---|---|
77 | 77 |
-> [(String, JSValue)] |
78 | 78 |
-> Result (String, Instance.Instance) |
79 | 79 |
parseInstance ktn a = do |
80 |
name <- fromObj "name" a |
|
81 |
disk <- fromObj "disk_usage" a |
|
82 |
mem <- fromObj "beparams" a >>= fromObj "memory" . fromJSObject |
|
83 |
vcpus <- fromObj "beparams" a >>= fromObj "vcpus" . fromJSObject |
|
84 |
pnode <- fromObj "pnode" a >>= lookupNode ktn name |
|
85 |
snodes <- fromObj "snodes" a |
|
80 |
name <- tryFromObj "Parsing new instance" a "name" |
|
81 |
let extract s x = tryFromObj ("Instance '" ++ name ++ "'") x s |
|
82 |
disk <- extract "disk_usage" a |
|
83 |
beparams <- liftM fromJSObject (extract "beparams" a) |
|
84 |
mem <- extract "memory" beparams |
|
85 |
vcpus <- extract "vcpus" beparams |
|
86 |
pnode <- extract "pnode" a >>= lookupNode ktn name |
|
87 |
snodes <- extract "snodes" a |
|
86 | 88 |
snode <- (if null snodes then return Node.noSecondary |
87 | 89 |
else readEitherString (head snodes) >>= lookupNode ktn name) |
88 |
running <- fromObj "status" a
|
|
90 |
running <- extract "status" a
|
|
89 | 91 |
let inst = Instance.create name mem disk vcpus running pnode snode |
90 | 92 |
return (name, inst) |
91 | 93 |
|
92 | 94 |
-- | Construct a node from a JSON object. |
93 | 95 |
parseNode :: [(String, JSValue)] -> Result (String, Node.Node) |
94 | 96 |
parseNode a = do |
95 |
name <- fromObj "name" a |
|
96 |
offline <- fromObj "offline" a |
|
97 |
name <- tryFromObj "Parsing new node" a "name" |
|
98 |
let extract s = tryFromObj ("Node '" ++ name ++ "'") a s |
|
99 |
offline <- extract "offline" |
|
97 | 100 |
node <- (if offline |
98 | 101 |
then return $ Node.create name 0 0 0 0 0 0 True |
99 | 102 |
else do |
100 |
drained <- fromObj "drained" a
|
|
101 |
mtotal <- fromObj "mtotal" a
|
|
102 |
mnode <- fromObj "mnode" a
|
|
103 |
mfree <- fromObj "mfree" a
|
|
104 |
dtotal <- fromObj "dtotal" a
|
|
105 |
dfree <- fromObj "dfree" a
|
|
106 |
ctotal <- fromObj "ctotal" a
|
|
103 |
drained <- extract "drained"
|
|
104 |
mtotal <- extract "mtotal"
|
|
105 |
mnode <- extract "mnode"
|
|
106 |
mfree <- extract "mfree"
|
|
107 |
dtotal <- extract "dtotal"
|
|
108 |
dfree <- extract "dfree"
|
|
109 |
ctotal <- extract "ctotal"
|
|
107 | 110 |
return $ Node.create name mtotal mnode mfree |
108 | 111 |
dtotal dfree ctotal (offline || drained)) |
109 | 112 |
return (name, node) |
Also available in: Unified diff