Revision 0ec8cce2 src/Ganeti/HTools/Backend/Luxi.hs

b/src/Ganeti/HTools/Backend/Luxi.hs
83 83
  st' <- fromJVal st
84 84
  Qlang.checkRS st' v >>= fromJVal
85 85

  
86
annotateConvert :: String -> String -> String -> Result a -> Result a
87
annotateConvert otype oname oattr =
88
  annotateResult $ otype ++ " '" ++ oname ++
89
    "', error while reading attribute '" ++ oattr ++ "'"
90

  
86 91
-- | Annotate errors when converting values with owner/attribute for
87 92
-- better debugging.
88 93
genericConvert :: (Text.JSON.JSON a) =>
......
92 97
               -> (JSValue, JSValue) -- ^ The value we're trying to convert
93 98
               -> Result a           -- ^ The annotated result
94 99
genericConvert otype oname oattr =
95
  annotateResult (otype ++ " '" ++ oname ++
96
                  "', error while reading attribute '" ++
97
                  oattr ++ "'") . fromJValWithStatus
100
  annotateConvert otype oname oattr . fromJValWithStatus
101

  
102
convertArrayMaybe :: (Text.JSON.JSON a) =>
103
                  String             -- ^ The object type
104
               -> String             -- ^ The object name
105
               -> String             -- ^ The attribute we're trying to convert
106
               -> (JSValue, JSValue) -- ^ The value we're trying to convert
107
               -> Result [Maybe a]   -- ^ The annotated result
108
convertArrayMaybe otype oname oattr (st, v) = do
109
  st' <- fromJVal st
110
  Qlang.checkRS st' v >>=
111
    annotateConvert otype oname oattr . arrayMaybeFromJVal
98 112

  
99 113
-- * Data querying functionality
100 114

  
......
114 128
     ["name", "disk_usage", "be/memory", "be/vcpus",
115 129
      "status", "pnode", "snodes", "tags", "oper_ram",
116 130
      "be/auto_balance", "disk_template",
117
      "be/spindle_use"] Qlang.EmptyFilter
131
      "be/spindle_use", "disk.sizes", "disk.spindles"] Qlang.EmptyFilter
118 132

  
119 133
-- | The input data for cluster query.
120 134
queryClusterInfoMsg :: L.LuxiOp
......
155 169
              -> Result (String, Instance.Instance)
156 170
parseInstance ktn [ name, disk, mem, vcpus
157 171
                  , status, pnode, snodes, tags, oram
158
                  , auto_balance, disk_template, su ] = do
172
                  , auto_balance, disk_template, su
173
                  , dsizes, dspindles ] = do
159 174
  xname <- annotateResult "Parsing new instance" (fromJValWithStatus name)
160 175
  let convert a = genericConvert "Instance" xname a
161 176
  xdisk <- convert "disk_usage" disk
......
173 188
  xauto_balance <- convert "auto_balance" auto_balance
174 189
  xdt <- convert "disk_template" disk_template
175 190
  xsu <- convert "be/spindle_use" su
176
  let inst = Instance.create xname xmem xdisk [Instance.Disk xdisk Nothing]
191
  xdsizes <- convert "disk.sizes" dsizes
192
  xdspindles <- convertArrayMaybe "Instance" xname "disk.spindles" dspindles
193
  let disks = zipWith Instance.Disk xdsizes xdspindles
194
      inst = Instance.create xname xmem xdisk disks
177 195
             xvcpus xrunning xtags xauto_balance xpnode snode xdt xsu []
178 196
  return (xname, inst)
179 197

  

Also available in: Unified diff