Revision 8bc34c7b htools/Ganeti/HTools/Node.hs

b/htools/Ganeti/HTools/Node.hs
101 101
  , fDsk     :: Int       -- ^ Free disk space (MiB)
102 102
  , tCpu     :: Double    -- ^ Total CPU count
103 103
  , uCpu     :: Int       -- ^ Used VCPU count
104
  , spindleCount :: Int   -- ^ Node spindles (spindle_count node parameter)
104 105
  , pList    :: [T.Idx]   -- ^ List of primary instance indices
105 106
  , sList    :: [T.Idx]   -- ^ List of secondary instance indices
106 107
  , idx      :: T.Ndx     -- ^ Internal index for book-keeping
......
117 118
                          -- threshold
118 119
  , hiCpu    :: Int       -- ^ Autocomputed from mCpu high cpu
119 120
                          -- threshold
121
  , hiSpindles :: Double  -- ^ Auto-computed from policy spindle_ratio
122
                          -- and the node spindle count
123
  , instSpindles :: Double -- ^ Spindles used by instances
120 124
  , offline  :: Bool      -- ^ Whether the node should not be used for
121 125
                          -- allocations and skipped from score
122 126
                          -- computations
......
188 192
-- The index and the peers maps are empty, and will be need to be
189 193
-- update later via the 'setIdx' and 'buildPeers' functions.
190 194
create :: String -> Double -> Int -> Int -> Double
191
       -> Int -> Double -> Bool -> T.Gdx -> Node
195
       -> Int -> Double -> Bool -> Int -> T.Gdx -> Node
192 196
create name_init mem_t_init mem_n_init mem_f_init
193
       dsk_t_init dsk_f_init cpu_t_init offline_init group_init =
197
       dsk_t_init dsk_f_init cpu_t_init offline_init spindles_init
198
       group_init =
194 199
  Node { name = name_init
195 200
       , alias = name_init
196 201
       , tMem = mem_t_init
......
199 204
       , tDsk = dsk_t_init
200 205
       , fDsk = dsk_f_init
201 206
       , tCpu = cpu_t_init
207
       , spindleCount = spindles_init
202 208
       , uCpu = 0
203 209
       , pList = []
204 210
       , sList = []
......
215 221
       , mDsk = T.defReservedDiskRatio
216 222
       , loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init
217 223
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio T.defIPolicy) cpu_t_init
224
       , hiSpindles = computeHiSpindles (T.iPolicySpindleRatio T.defIPolicy)
225
                      spindles_init
226
       , instSpindles = 0
218 227
       , utilPool = T.baseUtil
219 228
       , utilLoad = T.zeroUtil
220 229
       , pTags = Map.empty
......
230 239
mCpuTohiCpu :: Double -> Double -> Int
231 240
mCpuTohiCpu mval = floor . (mval *)
232 241

  
242
-- | Conversiojn formula from spindles and spindle ratio to hiSpindles.
243
computeHiSpindles :: Double -> Int -> Double
244
computeHiSpindles spindle_ratio = (spindle_ratio *) . fromIntegral
245

  
233 246
-- | Changes the index.
234 247
--
235 248
-- This is used only during the building of the data structures.
......
265 278
setPolicy :: T.IPolicy -> Node -> Node
266 279
setPolicy pol node =
267 280
  node { iPolicy = pol
268
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node) }
281
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node)
282
       , hiSpindles = computeHiSpindles (T.iPolicySpindleRatio pol)
283
                      (spindleCount node)
284
       }
269 285

  
270 286
-- | Computes the maximum reserved memory for peers from a peer map.
271 287
computeMaxRes :: P.PeerMap -> P.Elem

Also available in: Unified diff