Revision 2724417c src/Ganeti/HTools/Instance.hs

b/src/Ganeti/HTools/Instance.hs
28 28

  
29 29
module Ganeti.HTools.Instance
30 30
  ( Instance(..)
31
  , Disk(..)
31 32
  , AssocList
32 33
  , List
33 34
  , create
......
45 46
  , setBoth
46 47
  , setMovable
47 48
  , specOf
49
  , getTotalSpindles
48 50
  , instBelowISpec
49 51
  , instAboveISpec
50 52
  , instMatchesPolicy
......
65 67
import Ganeti.Utils
66 68

  
67 69
-- * Type declarations
70
data Disk = Disk
71
  { dskSize     :: Int       -- ^ Size in bytes
72
  , dskSpindles :: Maybe Int -- ^ Number of spindles
73
  } deriving (Show, Eq)
68 74

  
69 75
-- | The instance type.
70 76
data Instance = Instance
......
72 78
  , alias        :: String    -- ^ The shortened name
73 79
  , mem          :: Int       -- ^ Memory of the instance
74 80
  , dsk          :: Int       -- ^ Total disk usage of the instance
75
  , disks        :: [Int]     -- ^ Sizes of the individual disks
81
  , disks        :: [Disk]    -- ^ Sizes of the individual disks
76 82
  , vcpus        :: Int       -- ^ Number of VCPUs
77 83
  , runSt        :: T.InstanceStatus -- ^ Original run status
78 84
  , pNode        :: T.Ndx     -- ^ Original primary node
......
165 171
--
166 172
-- Some parameters are not initialized by function, and must be set
167 173
-- later (via 'setIdx' for example).
168
create :: String -> Int -> Int -> [Int] -> Int -> T.InstanceStatus
174
create :: String -> Int -> Int -> [Disk] -> Int -> T.InstanceStatus
169 175
       -> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Int
170 176
       -> [Nic] -> Instance
171 177
create name_init mem_init dsk_init disks_init vcpus_init run_init tags_init
......
259 265
                                 else Ok inst { vcpus = v }
260 266
shrinkByType _ f = Bad $ "Unhandled failure mode " ++ show f
261 267

  
268
-- | Get the number of disk spindles
269
getTotalSpindles :: Instance -> Maybe Int
270
getTotalSpindles inst =
271
  foldr (liftM2 (+) . dskSpindles ) (Just 0) (disks inst)
272

  
262 273
-- | Return the spec of an instance.
263 274
specOf :: Instance -> T.RSpec
264 275
specOf Instance { mem = m, dsk = d, vcpus = c } =
......
270 281
instBelowISpec :: Instance -> T.ISpec -> T.OpResult ()
271 282
instBelowISpec inst ispec
272 283
  | mem inst > T.iSpecMemorySize ispec = Bad T.FailMem
273
  | any (> T.iSpecDiskSize ispec) (disks inst) = Bad T.FailDisk
284
  | any (> T.iSpecDiskSize ispec) (map dskSize $ disks inst) = Bad T.FailDisk
274 285
  | vcpus inst > T.iSpecCpuCount ispec = Bad T.FailCPU
275 286
  | otherwise = Ok ()
276 287

  
......
278 289
instAboveISpec :: Instance -> T.ISpec -> T.OpResult ()
279 290
instAboveISpec inst ispec
280 291
  | mem inst < T.iSpecMemorySize ispec = Bad T.FailMem
281
  | any (< T.iSpecDiskSize ispec) (disks inst) = Bad T.FailDisk
292
  | any (< T.iSpecDiskSize ispec) (map dskSize $ disks inst) = Bad T.FailDisk
282 293
  | vcpus inst < T.iSpecCpuCount ispec = Bad T.FailCPU
283 294
  | otherwise = Ok ()
284 295

  

Also available in: Unified diff