Revision 0eb83d70

b/src/Ganeti/HTools/Backend/IAlloc.hs
130 130
  vm_capable  <- annotateResult desc $ maybeFromObj a "vm_capable"
131 131
  let vm_capable' = fromMaybe True vm_capable
132 132
  gidx <- lookupGroup ktg n guuid
133
  node <- if offline || drained || not vm_capable'
134
            then return $ Node.create n 0 0 0 0 0 0 True 0 gidx
135
            else do
136
              mtotal <- extract "total_memory"
137
              mnode  <- extract "reserved_memory"
138
              mfree  <- extract "free_memory"
139
              dtotal <- extract "total_disk"
140
              dfree  <- extract "free_disk"
141
              ctotal <- extract "total_cpus"
142
              ndparams <- extract "ndparams" >>= asJSObject
143
              spindles <- tryFromObj desc (fromJSObject ndparams)
144
                          "spindle_count"
145
              return $ Node.create n mtotal mnode mfree
146
                     dtotal dfree ctotal False spindles gidx
133
  ndparams <- extract "ndparams" >>= asJSObject
134
  spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count"
135
  let live = not offline && not drained && vm_capable'
136
      lvextract def = eitherLive live def . extract
137
  mtotal <- lvextract 0.0 "total_memory"
138
  mnode  <- lvextract 0 "reserved_memory"
139
  mfree  <- lvextract 0 "free_memory"
140
  dtotal <- lvextract 0.0 "total_disk"
141
  dfree  <- lvextract 0 "free_disk"
142
  ctotal <- lvextract 0.0 "total_cpus"
143
  let node = Node.create n mtotal mnode mfree dtotal dfree ctotal (not live)
144
             spindles gidx
147 145
  return (n, node)
148 146

  
149 147
-- | Parses a group as found in the cluster group list.
b/src/Ganeti/HTools/Backend/Luxi.hs
194 194
  xvm_capable <- convert "vm_capable" vm_capable
195 195
  xspindles <- convert "spindles" spindles
196 196
  xgdx   <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname
197
  node <- if xoffline || xdrained || not xvm_capable
198
            then return $ Node.create xname 0 0 0 0 0 0 True xspindles xgdx
199
            else do
200
              xmtotal  <- convert "mtotal" mtotal
201
              xmnode   <- convert "mnode" mnode
202
              xmfree   <- convert "mfree" mfree
203
              xdtotal  <- convert "dtotal" dtotal
204
              xdfree   <- convert "dfree" dfree
205
              xctotal  <- convert "ctotal" ctotal
206
              return $ Node.create xname xmtotal xmnode xmfree
207
                     xdtotal xdfree xctotal False xspindles xgdx
197
  let live = not xoffline && not xdrained && xvm_capable
198
      lvconvert def n d = eitherLive live def $ convert n d
199
  xmtotal <- lvconvert 0.0 "mtotal" mtotal
200
  xmnode <- lvconvert 0 "mnode" mnode
201
  xmfree <- lvconvert 0 "mfree" mfree
202
  xdtotal <- lvconvert 0.0 "dtotal" dtotal
203
  xdfree <- lvconvert 0 "dfree" dfree
204
  xctotal <- lvconvert 0.0 "ctotal" ctotal
205
  let node = Node.create xname xmtotal xmnode xmfree xdtotal xdfree
206
             xctotal (not live) xspindles xgdx
208 207
  return (xname, node)
209 208

  
210 209
parseNode _ v = fail ("Invalid node query result: " ++ show v)
b/src/Ganeti/HTools/Backend/Rapi.hs
157 157
  spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count"
158 158
  guuid   <- annotateResult desc $ maybeFromObj a "group.uuid"
159 159
  guuid' <-  lookupGroup ktg name (fromMaybe defaultGroupID guuid)
160
  node <- if offline || drained || not vm_cap'
161
            then return $ Node.create name 0 0 0 0 0 0 True 0 guuid'
162
            else do
163
              mtotal  <- extract "mtotal"
164
              mnode   <- extract "mnode"
165
              mfree   <- extract "mfree"
166
              dtotal  <- extract "dtotal"
167
              dfree   <- extract "dfree"
168
              ctotal  <- extract "ctotal"
169
              return $ Node.create name mtotal mnode mfree
170
                     dtotal dfree ctotal False spindles guuid'
160
  let live = not offline && not drained && vm_cap'
161
      lvextract def = eitherLive live def . extract
162
  mtotal <- lvextract 0.0 "mtotal"
163
  mnode <- lvextract 0 "mnode"
164
  mfree <- lvextract 0 "mfree"
165
  dtotal <- lvextract 0.0 "dtotal"
166
  dfree <- lvextract 0 "dfree"
167
  ctotal <- lvextract 0.0 "ctotal"
168
  let node = Node.create name mtotal mnode mfree dtotal dfree ctotal (not live)
169
             spindles guuid'
171 170
  return (name, node)
172 171

  
173 172
-- | Construct a group from a JSON object.
b/src/Ganeti/HTools/Loader.hs
34 34
  , lookupNode
35 35
  , lookupInstance
36 36
  , lookupGroup
37
  , eitherLive
37 38
  , commonSuffix
38 39
  , RqType(..)
39 40
  , Request(..)
......
332 333
  let rfind = flip Container.find il
333 334
  in sum . map (Instance.dsk . rfind)
334 335
       $ Node.pList node ++ Node.sList node
336

  
337
-- | Get live information or a default value
338
eitherLive :: (Monad m) => Bool -> a -> m a -> m a
339
eitherLive True _ live_data = live_data
340
eitherLive False def_data _ = return def_data

Also available in: Unified diff