, requiredNodes
, allNodes
, usesLocalStorage
+ , mirrorType
) where
+import Ganeti.BasicTypes
import qualified Ganeti.HTools.Types as T
import qualified Ganeti.HTools.Container as Container
-import Ganeti.HTools.Utils
+import Ganeti.Utils
-- * Type declarations
, autoBalance :: Bool -- ^ Is the instance auto-balanced?
, tags :: [String] -- ^ List of instance tags
, diskTemplate :: T.DiskTemplate -- ^ The disk template of the instance
+ , spindleUse :: Int -- ^ The numbers of used spindles
} deriving (Show, Read, Eq)
instance T.Element Instance where
-- instance. Further the movable state can be restricted more due to
-- user choices, etc.
movableDiskTemplates :: [T.DiskTemplate]
-movableDiskTemplates = [ T.DTDrbd8, T.DTBlock, T.DTSharedFile ]
+movableDiskTemplates =
+ [ T.DTDrbd8
+ , T.DTBlock
+ , T.DTSharedFile
+ , T.DTRbd
+ ]
-- | A simple name for the int, instance association list.
type AssocList = [(T.Idx, Instance)]
-- Some parameters are not initialized by function, and must be set
-- later (via 'setIdx' for example).
create :: String -> Int -> Int -> Int -> T.InstanceStatus
- -> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Instance
+ -> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Int
+ -> Instance
create name_init mem_init dsk_init vcpus_init run_init tags_init
- auto_balance_init pn sn dt =
+ auto_balance_init pn sn dt su =
Instance { name = name_init
, alias = name_init
, mem = mem_init
, movable = supportsMoves dt
, autoBalance = auto_balance_init
, diskTemplate = dt
+ , spindleUse = su
}
-- | Changes the index.
-- | Try to shrink the instance based on the reason why we can't
-- allocate it.
-shrinkByType :: Instance -> T.FailMode -> T.Result Instance
+shrinkByType :: Instance -> T.FailMode -> Result Instance
shrinkByType inst T.FailMem = let v = mem inst - T.unitMem
in if v < T.unitMem
- then T.Bad "out of memory"
- else T.Ok inst { mem = v }
+ then Bad "out of memory"
+ else Ok inst { mem = v }
shrinkByType inst T.FailDisk = let v = dsk inst - T.unitDsk
in if v < T.unitDsk
- then T.Bad "out of disk"
- else T.Ok inst { dsk = v }
+ then Bad "out of disk"
+ else Ok inst { dsk = v }
shrinkByType inst T.FailCPU = let v = vcpus inst - T.unitCpu
in if v < T.unitCpu
- then T.Bad "out of vcpus"
- else T.Ok inst { vcpus = v }
-shrinkByType _ f = T.Bad $ "Unhandled failure mode " ++ show f
+ then Bad "out of vcpus"
+ else Ok inst { vcpus = v }
+shrinkByType _ f = Bad $ "Unhandled failure mode " ++ show f
-- | Return the spec of an instance.
specOf :: Instance -> T.RSpec
instMatchesPolicy inst ipol = do
instAboveISpec inst (T.iPolicyMinSpec ipol)
instBelowISpec inst (T.iPolicyMaxSpec ipol)
- if (diskTemplate inst `elem` T.iPolicyDiskTemplates ipol)
+ if diskTemplate inst `elem` T.iPolicyDiskTemplates ipol
then T.OpGood ()
else T.OpFail T.FailDisk
-- | Checks whether a given disk template supported moves.
supportsMoves :: T.DiskTemplate -> Bool
supportsMoves = (`elem` movableDiskTemplates)
+
+-- | A simple wrapper over 'T.templateMirrorType'.
+mirrorType :: Instance -> T.MirrorType
+mirrorType = T.templateMirrorType . diskTemplate