Revision 3603605a htools/Ganeti/HTools/Rapi.hs

b/htools/Ganeti/HTools/Rapi.hs
48 48
import qualified Ganeti.HTools.Instance as Instance
49 49
import qualified Ganeti.Constants as C
50 50

  
51
{-# ANN module "HLint: ignore Eta reduce" #-}
52

  
51 53
-- | Read an URL via curl and return the body if successful.
52 54
getUrl :: (Monad m) => String -> IO (m String)
53 55

  
......
108 110
  disk <- extract "disk_usage" a
109 111
  beparams <- liftM fromJSObject (extract "beparams" a)
110 112
  omem <- extract "oper_ram" a
111
  mem <- (case omem of
112
            JSRational _ _ -> annotateResult owner_name (fromJVal omem)
113
            _ -> extract "memory" beparams)
113
  mem <- case omem of
114
           JSRational _ _ -> annotateResult owner_name (fromJVal omem)
115
           _ -> extract "memory" beparams
114 116
  vcpus <- extract "vcpus" beparams
115 117
  pnode <- extract "pnode" a >>= lookupNode ktn name
116 118
  snodes <- extract "snodes" a
117
  snode <- (if null snodes then return Node.noSecondary
118
            else readEitherString (head snodes) >>= lookupNode ktn name)
119
  snode <- if null snodes
120
             then return Node.noSecondary
121
             else readEitherString (head snodes) >>= lookupNode ktn name
119 122
  running <- extract "status" a
120 123
  tags <- extract "tags" a
121 124
  auto_balance <- extract "auto_balance" beparams
......
136 139
  let vm_cap' = fromMaybe True vm_cap
137 140
  guuid   <- annotateResult desc $ maybeFromObj a "group.uuid"
138 141
  guuid' <-  lookupGroup ktg name (fromMaybe defaultGroupID guuid)
139
  node <- (if offline || drained || not vm_cap'
140
           then return $ Node.create name 0 0 0 0 0 0 True guuid'
141
           else do
142
             mtotal  <- extract "mtotal"
143
             mnode   <- extract "mnode"
144
             mfree   <- extract "mfree"
145
             dtotal  <- extract "dtotal"
146
             dfree   <- extract "dfree"
147
             ctotal  <- extract "ctotal"
148
             return $ Node.create name mtotal mnode mfree
149
                    dtotal dfree ctotal False guuid')
142
  node <- if offline || drained || not vm_cap'
143
            then return $ Node.create name 0 0 0 0 0 0 True guuid'
144
            else do
145
              mtotal  <- extract "mtotal"
146
              mnode   <- extract "mnode"
147
              mfree   <- extract "mfree"
148
              dtotal  <- extract "dtotal"
149
              dfree   <- extract "dfree"
150
              ctotal  <- extract "ctotal"
151
              return $ Node.create name mtotal mnode mfree
152
                     dtotal dfree ctotal False guuid'
150 153
  return (name, node)
151 154

  
152 155
-- | Construct a group from a JSON object.

Also available in: Unified diff