Revision 9f6dcdea Ganeti/HTools/Node.hs
b/Ganeti/HTools/Node.hs | ||
---|---|---|
154 | 154 |
idx = -1, |
155 | 155 |
peers = PeerMap.empty, |
156 | 156 |
r_mem = 0, |
157 |
p_mem = (fromIntegral mem_f_init) / mem_t_init,
|
|
158 |
p_dsk = (fromIntegral dsk_f_init) / dsk_t_init,
|
|
157 |
p_mem = fromIntegral mem_f_init / mem_t_init,
|
|
158 |
p_dsk = fromIntegral dsk_f_init / dsk_t_init,
|
|
159 | 159 |
p_rem = 0, |
160 | 160 |
p_cpu = 0, |
161 | 161 |
offline = offline_init, |
... | ... | |
191 | 191 |
setMdsk t val = t { m_dsk = val, |
192 | 192 |
lo_dsk = if val == noLimit |
193 | 193 |
then noLimitInt |
194 |
else floor (val * (t_dsk t)) }
|
|
194 |
else floor (val * t_dsk t) }
|
|
195 | 195 |
|
196 | 196 |
-- | Sets the max cpu usage ratio |
197 | 197 |
setMcpu :: Node -> Double -> Node |
198 |
setMcpu t val = t { m_cpu = val, hi_cpu = floor (val * (t_cpu t)) }
|
|
198 |
setMcpu t val = t { m_cpu = val, hi_cpu = floor (val * t_cpu t) }
|
|
199 | 199 |
|
200 | 200 |
-- | Computes the maximum reserved memory for peers from a peer map. |
201 | 201 |
computeMaxRes :: PeerMap.PeerMap -> PeerMap.Elem |
202 |
computeMaxRes new_peers = PeerMap.maxElem new_peers
|
|
202 |
computeMaxRes = PeerMap.maxElem
|
|
203 | 203 |
|
204 | 204 |
-- | Builds the peer map for a given node. |
205 | 205 |
buildPeers :: Node -> Instance.List -> Node |
... | ... | |
210 | 210 |
(slist t) |
211 | 211 |
pmap = PeerMap.accumArray (+) mdata |
212 | 212 |
new_rmem = computeMaxRes pmap |
213 |
new_failN1 = (f_mem t) <= new_rmem
|
|
214 |
new_prem = (fromIntegral new_rmem) / (t_mem t)
|
|
213 |
new_failN1 = f_mem t <= new_rmem
|
|
214 |
new_prem = fromIntegral new_rmem / t_mem t
|
|
215 | 215 |
in t {peers=pmap, failN1 = new_failN1, r_mem = new_rmem, p_rem = new_prem} |
216 | 216 |
|
217 | 217 |
-- | Assigns an instance to a node as primary without other updates. |
218 | 218 |
setPri :: Node -> T.Idx -> Node |
219 |
setPri t idx = t { plist = idx:(plist t) }
|
|
219 |
setPri t idx = t { plist = idx:plist t }
|
|
220 | 220 |
|
221 | 221 |
-- | Assigns an instance to a node as secondary without other updates. |
222 | 222 |
setSec :: Node -> T.Idx -> Node |
223 |
setSec t idx = t { slist = idx:(slist t) }
|
|
223 |
setSec t idx = t { slist = idx:slist t }
|
|
224 | 224 |
|
225 | 225 |
-- | Add primary cpus to a node |
226 | 226 |
addCpus :: Node -> Int -> Node |
227 | 227 |
addCpus t count = |
228 |
let new_count = (u_cpu t) + count
|
|
229 |
in t { u_cpu = new_count, p_cpu = (fromIntegral new_count) / (t_cpu t) }
|
|
228 |
let new_count = u_cpu t + count
|
|
229 |
in t { u_cpu = new_count, p_cpu = fromIntegral new_count / t_cpu t }
|
|
230 | 230 |
|
231 | 231 |
-- * Update functions |
232 | 232 |
|
233 | 233 |
-- | Sets the free memory. |
234 | 234 |
setFmem :: Node -> Int -> Node |
235 | 235 |
setFmem t new_mem = |
236 |
let new_n1 = new_mem <= (r_mem t)
|
|
237 |
new_mp = (fromIntegral new_mem) / (t_mem t)
|
|
236 |
let new_n1 = new_mem <= r_mem t
|
|
237 |
new_mp = fromIntegral new_mem / t_mem t
|
|
238 | 238 |
in |
239 | 239 |
t { f_mem = new_mem, failN1 = new_n1, p_mem = new_mp } |
240 | 240 |
|
... | ... | |
245 | 245 |
new_plist = delete iname (plist t) |
246 | 246 |
new_mem = f_mem t + Instance.mem inst |
247 | 247 |
new_dsk = f_dsk t + Instance.dsk inst |
248 |
new_mp = (fromIntegral new_mem) / (t_mem t)
|
|
249 |
new_dp = (fromIntegral new_dsk) / (t_dsk t)
|
|
250 |
new_failn1 = new_mem <= (r_mem t)
|
|
251 |
new_ucpu = (u_cpu t) - (Instance.vcpus inst)
|
|
252 |
new_rcpu = (fromIntegral new_ucpu) / (t_cpu t)
|
|
248 |
new_mp = fromIntegral new_mem / t_mem t
|
|
249 |
new_dp = fromIntegral new_dsk / t_dsk t
|
|
250 |
new_failn1 = new_mem <= r_mem t
|
|
251 |
new_ucpu = u_cpu t - Instance.vcpus inst
|
|
252 |
new_rcpu = fromIntegral new_ucpu / t_cpu t
|
|
253 | 253 |
in t {plist = new_plist, f_mem = new_mem, f_dsk = new_dsk, |
254 | 254 |
failN1 = new_failn1, p_mem = new_mp, p_dsk = new_dp, |
255 | 255 |
u_cpu = new_ucpu, p_cpu = new_rcpu} |
... | ... | |
263 | 263 |
new_dsk = f_dsk t + Instance.dsk inst |
264 | 264 |
old_peers = peers t |
265 | 265 |
old_peem = PeerMap.find pnode old_peers |
266 |
new_peem = old_peem - (Instance.mem inst)
|
|
266 |
new_peem = old_peem - Instance.mem inst
|
|
267 | 267 |
new_peers = PeerMap.add pnode new_peem old_peers |
268 | 268 |
old_rmem = r_mem t |
269 | 269 |
new_rmem = if old_peem < old_rmem then |
270 | 270 |
old_rmem |
271 | 271 |
else |
272 | 272 |
computeMaxRes new_peers |
273 |
new_prem = (fromIntegral new_rmem) / (t_mem t)
|
|
274 |
new_failn1 = (f_mem t) <= new_rmem
|
|
275 |
new_dp = (fromIntegral new_dsk) / (t_dsk t)
|
|
273 |
new_prem = fromIntegral new_rmem / t_mem t
|
|
274 |
new_failn1 = f_mem t <= new_rmem
|
|
275 |
new_dp = fromIntegral new_dsk / t_dsk t
|
|
276 | 276 |
in t {slist = new_slist, f_dsk = new_dsk, peers = new_peers, |
277 | 277 |
failN1 = new_failn1, r_mem = new_rmem, p_dsk = new_dp, |
278 | 278 |
p_rem = new_prem} |
... | ... | |
283 | 283 |
let iname = Instance.idx inst |
284 | 284 |
new_mem = f_mem t - Instance.mem inst |
285 | 285 |
new_dsk = f_dsk t - Instance.dsk inst |
286 |
new_failn1 = new_mem <= (r_mem t)
|
|
287 |
new_ucpu = (u_cpu t) + (Instance.vcpus inst)
|
|
288 |
new_pcpu = (fromIntegral new_ucpu) / (t_cpu t)
|
|
289 |
new_dp = (fromIntegral new_dsk) / (t_dsk t)
|
|
286 |
new_failn1 = new_mem <= r_mem t
|
|
287 |
new_ucpu = u_cpu t + Instance.vcpus inst
|
|
288 |
new_pcpu = fromIntegral new_ucpu / t_cpu t
|
|
289 |
new_dp = fromIntegral new_dsk / t_dsk t
|
|
290 | 290 |
l_cpu = m_cpu t |
291 | 291 |
in if new_mem <= 0 then T.OpFail T.FailMem |
292 | 292 |
else if new_dsk <= 0 || m_dsk t > new_dp then T.OpFail T.FailDisk |
293 |
else if (new_failn1 && not (failN1 t)) then T.OpFail T.FailMem
|
|
293 |
else if new_failn1 && not (failN1 t) then T.OpFail T.FailMem
|
|
294 | 294 |
else if l_cpu >= 0 && l_cpu < new_pcpu then T.OpFail T.FailCPU |
295 | 295 |
else |
296 |
let new_plist = iname:(plist t)
|
|
297 |
new_mp = (fromIntegral new_mem) / (t_mem t)
|
|
296 |
let new_plist = iname:plist t
|
|
297 |
new_mp = fromIntegral new_mem / t_mem t
|
|
298 | 298 |
r = t { plist = new_plist, f_mem = new_mem, f_dsk = new_dsk, |
299 | 299 |
failN1 = new_failn1, p_mem = new_mp, p_dsk = new_dp, |
300 | 300 |
u_cpu = new_ucpu, p_cpu = new_pcpu } |
... | ... | |
310 | 310 |
new_peem = PeerMap.find pdx old_peers + Instance.mem inst |
311 | 311 |
new_peers = PeerMap.add pdx new_peem old_peers |
312 | 312 |
new_rmem = max (r_mem t) new_peem |
313 |
new_prem = (fromIntegral new_rmem) / (t_mem t)
|
|
313 |
new_prem = fromIntegral new_rmem / t_mem t
|
|
314 | 314 |
new_failn1 = old_mem <= new_rmem |
315 |
new_dp = (fromIntegral new_dsk) / (t_dsk t)
|
|
315 |
new_dp = fromIntegral new_dsk / t_dsk t
|
|
316 | 316 |
in if new_dsk <= 0 || m_dsk t > new_dp then T.OpFail T.FailDisk |
317 |
else if (new_failn1 && not (failN1 t)) then T.OpFail T.FailMem
|
|
318 |
else let new_slist = iname:(slist t)
|
|
317 |
else if new_failn1 && not (failN1 t) then T.OpFail T.FailMem
|
|
318 |
else let new_slist = iname:slist t
|
|
319 | 319 |
r = t { slist = new_slist, f_dsk = new_dsk, |
320 | 320 |
peers = new_peers, failN1 = new_failn1, |
321 | 321 |
r_mem = new_rmem, p_dsk = new_dp, |
... | ... | |
352 | 352 |
nmem = n_mem t |
353 | 353 |
xmem = x_mem t |
354 | 354 |
fmem = f_mem t |
355 |
imem = (truncate tmem) - nmem - xmem - fmem
|
|
355 |
imem = truncate tmem - nmem - xmem - fmem
|
|
356 | 356 |
in |
357 | 357 |
if off |
358 | 358 |
then printf " - %-*s %57s %3d %3d" |
... | ... | |
362 | 362 |
\ %4.0f %4d %3d %3d %6.4f %6.4f %5.2f" |
363 | 363 |
(if off then '-' else if fn then '*' else ' ') |
364 | 364 |
mname (name t) tmem nmem imem xmem fmem (r_mem t) |
365 |
((t_dsk t) / 1024) ((f_dsk t) `div` 1024)
|
|
365 |
(t_dsk t / 1024) (f_dsk t `div` 1024)
|
|
366 | 366 |
(t_cpu t) (u_cpu t) |
367 | 367 |
pl sl mp dp cp |
Also available in: Unified diff