Revision 8c72f711

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

  
154 151
-- | Parses a group as found in the cluster group list.
b/src/Ganeti/HTools/Backend/Luxi.hs
198 198
  xgdx   <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname
199 199
  xtags <- convert "tags" tags
200 200
  xexcl_stor <- convert "exclusive_storage" excl_stor
201
  node <- if xoffline || xdrained || not xvm_capable
202
            then return $
203
              Node.create xname 0 0 0 0 0 0 True xspindles xgdx False
204
            else do
205
              xmtotal  <- convert "mtotal" mtotal
206
              xmnode   <- convert "mnode" mnode
207
              xmfree   <- convert "mfree" mfree
208
              xdtotal  <- convert "dtotal" dtotal
209
              xdfree   <- convert "dfree" dfree
210
              xctotal  <- convert "ctotal" ctotal
211
              return . flip Node.setNodeTags xtags $
212
                Node.create xname xmtotal xmnode xmfree xdtotal xdfree
213
                            xctotal False xspindles xgdx xexcl_stor
201
  let live = not xoffline && not xdrained && xvm_capable
202
      lvconvert def n d = eitherLive live def $ convert n d
203
  xmtotal <- lvconvert 0.0 "mtotal" mtotal
204
  xmnode <- lvconvert 0 "mnode" mnode
205
  xmfree <- lvconvert 0 "mfree" mfree
206
  xdtotal <- lvconvert 0.0 "dtotal" dtotal
207
  xdfree <- lvconvert 0 "dfree" dfree
208
  xctotal <- lvconvert 0.0 "ctotal" ctotal
209
  let node = flip Node.setNodeTags xtags $
210
             Node.create xname xmtotal xmnode xmfree xdtotal xdfree
211
             xctotal (not live) xspindles xgdx xexcl_stor
214 212
  return (xname, node)
215 213

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

  
178 177
-- | 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