Cleanup HTools.Types/BasicTypes imports
[ganeti-local] / htools / Ganeti / HTools / Instance.hs
index 4b5924e..b78eaa6 100644 (file)
@@ -54,12 +54,14 @@ module Ganeti.HTools.Instance
   , 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
 
@@ -79,6 +81,7 @@ data Instance = Instance
   , 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
@@ -137,7 +140,12 @@ localStorageTemplates = [ T.DTDrbd8, T.DTPlain ]
 -- 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)]
@@ -152,9 +160,10 @@ type List = Container.Container 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
@@ -169,6 +178,7 @@ create name_init mem_init dsk_init vcpus_init run_init tags_init
            , movable = supportsMoves dt
            , autoBalance = auto_balance_init
            , diskTemplate = dt
+           , spindleUse = su
            }
 
 -- | Changes the index.
@@ -224,20 +234,20 @@ setMovable t m = t { movable = m }
 
 -- | 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
@@ -267,7 +277,7 @@ instMatchesPolicy :: Instance -> T.IPolicy -> T.OpResult ()
 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
 
@@ -296,3 +306,7 @@ usesLocalStorage = (`elem` localStorageTemplates) . diskTemplate
 -- | 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