Revision 0cc3d742 src/Ganeti/HTools/Cluster.hs
b/src/Ganeti/HTools/Cluster.hs  

150  150 
data CStats = CStats 
151  151 
{ csFmem :: Integer  ^ Cluster free mem 
152  152 
, csFdsk :: Integer  ^ Cluster free disk 
153 
, csFspn :: Integer  ^ Cluster free spindles 

153  154 
, csAmem :: Integer  ^ Cluster allocatable mem 
154  155 
, csAdsk :: Integer  ^ Cluster allocatable disk 
155  156 
, csAcpu :: Integer  ^ Cluster allocatable cpus 
...  ...  
158  159 
, csMcpu :: Integer  ^ Max node allocatable cpu 
159  160 
, csImem :: Integer  ^ Instance used mem 
160  161 
, csIdsk :: Integer  ^ Instance used disk 
162 
, csIspn :: Integer  ^ Instance used spindles 

161  163 
, csIcpu :: Integer  ^ Instance used cpu 
162  164 
, csTmem :: Double  ^ Cluster total mem 
163  165 
, csTdsk :: Double  ^ Cluster total disk 
166 
, csTspn :: Double  ^ Cluster total spindles 

164  167 
, csTcpu :: Double  ^ Cluster total cpus 
165  168 
, csVcpu :: Integer  ^ Cluster total virtual cpus 
166  169 
, csNcpu :: Double  ^ Equivalent to 'csIcpu' but in terms of 
...  ...  
222  225  
223  226 
  Zeroinitializer for the CStats type. 
224  227 
emptyCStats :: CStats 
225 
emptyCStats = CStats 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

228 
emptyCStats = CStats 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


226  229  
227  230 
  Update stats with data from a new node. 
228  231 
updateCStats :: CStats > Node.Node > CStats 
...  ...  
233  236 
csImem = x_imem, csIdsk = x_idsk, csIcpu = x_icpu, 
234  237 
csTmem = x_tmem, csTdsk = x_tdsk, csTcpu = x_tcpu, 
235  238 
csVcpu = x_vcpu, csNcpu = x_ncpu, 
236 
csXmem = x_xmem, csNmem = x_nmem, csNinst = x_ninst 

239 
csXmem = x_xmem, csNmem = x_nmem, csNinst = x_ninst, 

240 
csFspn = x_fspn, csIspn = x_ispn, csTspn = x_tspn 

237  241 
} 
238  242 
= cs 
239  243 
inc_amem = Node.fMem node  Node.rMem node 
...  ...  
243  247 
 Node.xMem node  Node.fMem node 
244  248 
inc_icpu = Node.uCpu node 
245  249 
inc_idsk = truncate (Node.tDsk node)  Node.fDsk node 
250 
inc_ispn = Node.tSpindles node  Node.fSpindles node 

246  251 
inc_vcpu = Node.hiCpu node 
247  252 
inc_acpu = Node.availCpu node 
248  253 
inc_ncpu = fromIntegral (Node.uCpu node) / 
249  254 
iPolicyVcpuRatio (Node.iPolicy node) 
250  255 
in cs { csFmem = x_fmem + fromIntegral (Node.fMem node) 
251  256 
, csFdsk = x_fdsk + fromIntegral (Node.fDsk node) 
257 
, csFspn = x_fspn + fromIntegral (Node.fSpindles node) 

252  258 
, csAmem = x_amem + fromIntegral inc_amem' 
253  259 
, csAdsk = x_adsk + fromIntegral inc_adsk 
254  260 
, csAcpu = x_acpu + fromIntegral inc_acpu 
...  ...  
257  263 
, csMcpu = max x_mcpu (fromIntegral inc_acpu) 
258  264 
, csImem = x_imem + fromIntegral inc_imem 
259  265 
, csIdsk = x_idsk + fromIntegral inc_idsk 
266 
, csIspn = x_ispn + fromIntegral inc_ispn 

260  267 
, csIcpu = x_icpu + fromIntegral inc_icpu 
261  268 
, csTmem = x_tmem + Node.tMem node 
262  269 
, csTdsk = x_tdsk + Node.tDsk node 
270 
, csTspn = x_tspn + fromIntegral (Node.tSpindles node) 

263  271 
, csTcpu = x_tcpu + Node.tCpu node 
264  272 
, csVcpu = x_vcpu + fromIntegral inc_vcpu 
265  273 
, csNcpu = x_ncpu + inc_ncpu 
...  ...  
283  291 
computeAllocationDelta :: CStats > CStats > AllocStats 
284  292 
computeAllocationDelta cini cfin = 
285  293 
let CStats {csImem = i_imem, csIdsk = i_idsk, csIcpu = i_icpu, 
286 
csNcpu = i_ncpu } = cini 

294 
csNcpu = i_ncpu, csIspn = i_ispn } = cini


287  295 
CStats {csImem = f_imem, csIdsk = f_idsk, csIcpu = f_icpu, 
288  296 
csTmem = t_mem, csTdsk = t_dsk, csVcpu = f_vcpu, 
289 
csNcpu = f_ncpu, csTcpu = f_tcpu } = cfin 

297 
csNcpu = f_ncpu, csTcpu = f_tcpu, 

298 
csIspn = f_ispn, csTspn = t_spn } = cfin 

290  299 
rini = AllocInfo { allocInfoVCpus = fromIntegral i_icpu 
291  300 
, allocInfoNCpus = i_ncpu 
292  301 
, allocInfoMem = fromIntegral i_imem 
293  302 
, allocInfoDisk = fromIntegral i_idsk 
303 
, allocInfoSpn = fromIntegral i_ispn 

294  304 
} 
295  305 
rfin = AllocInfo { allocInfoVCpus = fromIntegral (f_icpu  i_icpu) 
296  306 
, allocInfoNCpus = f_ncpu  i_ncpu 
297  307 
, allocInfoMem = fromIntegral (f_imem  i_imem) 
298  308 
, allocInfoDisk = fromIntegral (f_idsk  i_idsk) 
309 
, allocInfoSpn = fromIntegral (f_ispn  i_ispn) 

299  310 
} 
300  311 
runa = AllocInfo { allocInfoVCpus = fromIntegral (f_vcpu  f_icpu) 
301  312 
, allocInfoNCpus = f_tcpu  f_ncpu 
302  313 
, allocInfoMem = truncate t_mem  fromIntegral f_imem 
303  314 
, allocInfoDisk = truncate t_dsk  fromIntegral f_idsk 
315 
, allocInfoSpn = truncate t_spn  fromIntegral f_ispn 

304  316 
} 
305  317 
in (rini, rfin, runa) 
306  318 
Also available in: Unified diff