, pRem :: Double -- ^ Percent of reserved memory
, pCpu :: Double -- ^ Ratio of virtual to physical CPUs
, mDsk :: Double -- ^ Minimum free disk ratio
- , mCpu :: Double -- ^ Max ratio of virt-to-phys CPUs
, loDsk :: Int -- ^ Autocomputed from mDsk low disk
-- threshold
, hiCpu :: Int -- ^ Autocomputed from mCpu high cpu
, offline = offline_init
, xMem = 0
, mDsk = T.defReservedDiskRatio
- , mCpu = T.defVcpuRatio
, loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init
- , hiCpu = mCpuTohiCpu T.defVcpuRatio cpu_t_init
+ , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio T.defIPolicy) cpu_t_init
, utilPool = T.baseUtil
, utilLoad = T.zeroUtil
, pTags = Map.empty
setMdsk :: Node -> Double -> Node
setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) }
--- | Sets the max cpu usage ratio.
+-- | Sets the max cpu usage ratio. This will update the node's
+-- ipolicy, losing sharing (but it should be a seldomly done operation).
setMcpu :: Node -> Double -> Node
-setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
+setMcpu t val =
+ let new_ipol = (iPolicy t) { T.iPolicyVcpuRatio = val }
+ in t { hiCpu = mCpuTohiCpu val (tCpu t), iPolicy = new_ipol }
-- | Sets the policy.
setPolicy :: T.IPolicy -> Node -> Node
-setPolicy pol node = node { iPolicy = pol }
+setPolicy pol node =
+ node { iPolicy = pol
+ , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node) }
-- | Computes the maximum reserved memory for peers from a peer map.
computeMaxRes :: P.PeerMap -> P.Elem
buildPeers t il =
let mdata = map
(\i_idx -> let inst = Container.find i_idx il
- mem = if Instance.autoBalance inst
+ mem = if Instance.usesSecMem inst
then Instance.mem inst
else 0
in (Instance.pNode inst, mem))
, utilLoad = utilLoad t `T.addUtil` Instance.util inst
, pTags = addTags (pTags t) (Instance.tags inst)
}
- where new_count = uCpu t + Instance.vcpus inst
+ where new_count = Instance.applyIfOnline inst (+ Instance.vcpus inst)
+ (uCpu t )
-- | Assigns an instance to a node as secondary without other updates.
setSec :: Node -> Instance.Instance -> Node
else cur_dsk
old_peers = peers t
old_peem = P.find pnode old_peers
- new_peem = if Instance.autoBalance inst
+ new_peem = if Instance.usesSecMem inst
then old_peem - Instance.mem inst
else old_peem
new_peers = if new_peem > 0
new_ucpu = Instance.applyIfOnline inst (+ Instance.vcpus inst) (uCpu t)
new_pcpu = fromIntegral new_ucpu / tCpu t
new_dp = fromIntegral new_dsk / tDsk t
- l_cpu = mCpu t
+ l_cpu = T.iPolicyVcpuRatio $ iPolicy t
new_load = utilLoad t `T.addUtil` Instance.util inst
inst_tags = Instance.tags inst
old_tags = pTags t
old_peers = peers t
old_mem = fMem t
new_dsk = fDsk t - Instance.dsk inst
- secondary_needed_mem = if Instance.autoBalance inst &&
- not (Instance.instanceOffline inst)
+ secondary_needed_mem = if Instance.usesSecMem inst
then Instance.mem inst
else 0
new_peem = P.find pdx old_peers + secondary_needed_mem