Revision 487e1962

b/htools/Ganeti/HTools/Node.hs
113 113
  , pRem     :: Double    -- ^ Percent of reserved memory
114 114
  , pCpu     :: Double    -- ^ Ratio of virtual to physical CPUs
115 115
  , mDsk     :: Double    -- ^ Minimum free disk ratio
116
  , mCpu     :: Double    -- ^ Max ratio of virt-to-phys CPUs
117 116
  , loDsk    :: Int       -- ^ Autocomputed from mDsk low disk
118 117
                          -- threshold
119 118
  , hiCpu    :: Int       -- ^ Autocomputed from mCpu high cpu
......
214 213
       , offline = offline_init
215 214
       , xMem = 0
216 215
       , mDsk = T.defReservedDiskRatio
217
       , mCpu = T.defVcpuRatio
218 216
       , loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init
219
       , hiCpu = mCpuTohiCpu T.defVcpuRatio cpu_t_init
217
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio T.defIPolicy) cpu_t_init
220 218
       , utilPool = T.baseUtil
221 219
       , utilLoad = T.zeroUtil
222 220
       , pTags = Map.empty
......
256 254
setMdsk :: Node -> Double -> Node
257 255
setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) }
258 256

  
259
-- | Sets the max cpu usage ratio.
257
-- | Sets the max cpu usage ratio. This will update the node's
258
-- ipolicy, losing sharing (but it should be a seldomly done operation).
260 259
setMcpu :: Node -> Double -> Node
261
setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
260
setMcpu t val =
261
  let new_ipol = (iPolicy t) { T.iPolicyVcpuRatio = val }
262
  in t { hiCpu = mCpuTohiCpu val (tCpu t), iPolicy = new_ipol }
262 263

  
263 264
-- | Sets the policy.
264 265
setPolicy :: T.IPolicy -> Node -> Node
265
setPolicy pol node = node { iPolicy = pol }
266
setPolicy pol node =
267
  node { iPolicy = pol
268
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node) }
266 269

  
267 270
-- | Computes the maximum reserved memory for peers from a peer map.
268 271
computeMaxRes :: P.PeerMap -> P.Elem
......
391 394
      new_ucpu = Instance.applyIfOnline inst (+ Instance.vcpus inst) (uCpu t)
392 395
      new_pcpu = fromIntegral new_ucpu / tCpu t
393 396
      new_dp = fromIntegral new_dsk / tDsk t
394
      l_cpu = mCpu t
397
      l_cpu = T.iPolicyVcpuRatio $ iPolicy t
395 398
      new_load = utilLoad t `T.addUtil` Instance.util inst
396 399
      inst_tags = Instance.tags inst
397 400
      old_tags = pTags t
b/htools/Ganeti/HTools/QC.hs
809 809

  
810 810
prop_Text_NodeLSIdempotent node =
811 811
  (Text.loadNode defGroupAssoc.
812
       Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==
812
       Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==?
813 813
  Just (Node.name n, n)
814 814
    -- override failN1 to what loadNode returns by default
815
    where n = node { Node.failN1 = True, Node.offline = False
816
                   , Node.iPolicy = Types.defIPolicy }
815
    where n = Node.setPolicy Types.defIPolicy $
816
              node { Node.failN1 = True, Node.offline = False }
817 817

  
818 818
prop_Text_ISpecIdempotent ispec =
819 819
  case Text.loadISpec "dummy" . Utils.sepSplit ',' .
......
942 942
    where newnode = Node.setXmem node xm
943 943

  
944 944
prop_Node_setMcpu node mc =
945
  Node.mCpu newnode ==? mc
945
  Types.iPolicyVcpuRatio (Node.iPolicy newnode) ==? mc
946 946
    where newnode = Node.setMcpu node mc
947 947

  
948 948
-- | Check that an instance add with too high memory or disk will be

Also available in: Unified diff