, specOf
, shrinkByType
, runningStates
+ , requiredNodes
+ , allNodes
) where
import qualified Ganeti.HTools.Types as T
import qualified Ganeti.HTools.Container as Container
+import qualified Ganeti.Constants as C
-- * Type declarations
--- | The instance type
+-- | The instance type.
data Instance = Instance
{ name :: String -- ^ The instance name
, alias :: String -- ^ The shortened name
, idx :: T.Idx -- ^ Internal index
, util :: T.DynUtil -- ^ Dynamic resource usage
, movable :: Bool -- ^ Can the instance be moved?
- , auto_balance :: Bool -- ^ Is the instance auto-balanced?
+ , autoBalance :: Bool -- ^ Is the instance auto-balanced?
, tags :: [String] -- ^ List of instance tags
+ , diskTemplate :: T.DiskTemplate -- ^ The disk template of the instance
} deriving (Show, Read)
instance T.Element Instance where
setIdx = setIdx
allNames n = [name n, alias n]
--- | Running instance states.
+-- | Constant holding the running instance states.
runningStates :: [String]
-runningStates = ["running", "ERROR_up"]
+runningStates = [C.inststRunning, C.inststErrorup]
-- | 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 -> String
- -> [String] -> Bool -> T.Ndx -> T.Ndx -> Instance
+ -> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Instance
create name_init mem_init dsk_init vcpus_init run_init tags_init
- auto_balance_init pn sn =
+ auto_balance_init pn sn dt =
Instance { name = name_init
, alias = name_init
, mem = mem_init
, util = T.baseUtil
, tags = tags_init
, movable = True
- , auto_balance = auto_balance_init
+ , autoBalance = auto_balance_init
+ , diskTemplate = dt
}
-- | Changes the index.
specOf :: Instance -> T.RSpec
specOf Instance { mem = m, dsk = d, vcpus = c } =
T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d }
+
+-- | Computed the number of nodes for a given disk template
+requiredNodes :: T.DiskTemplate -> Int
+requiredNodes T.DTDrbd8 = 2
+requiredNodes _ = 1
+
+-- | Computes all nodes of an instance.
+allNodes :: Instance -> [T.Ndx]
+allNodes inst = case diskTemplate inst of
+ T.DTDrbd8 -> [pNode inst, sNode inst]
+ _ -> [pNode inst]