, setPri
, setSec
, setBoth
+ , setMovable
, specOf
, shrinkByType
+ , runningStates
) where
import qualified Ganeti.HTools.Types as T
, sNode :: T.Ndx -- ^ Original secondary node
, idx :: T.Idx -- ^ Internal index
, util :: T.DynUtil -- ^ Dynamic resource usage
+ , movable :: Bool -- ^ Can the instance be moved?
+ , tags :: [String] -- ^ List of instance tags
} deriving (Show)
instance T.Element Instance where
unitCpu :: Int
unitCpu = 1
+-- | Running instance states.
+runningStates :: [String]
+runningStates = ["running", "ERROR_up"]
+
-- | 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 -> T.Ndx -> T.Ndx -> Instance
-create name_init mem_init dsk_init vcpus_init run_init pn sn =
+create :: String -> Int -> Int -> Int -> String
+ -> [String] -> T.Ndx -> T.Ndx -> Instance
+create name_init mem_init dsk_init vcpus_init run_init tags_init pn sn =
Instance { name = name_init
, mem = mem_init
, dsk = dsk_init
, vcpus = vcpus_init
- , running = run_init == "running" || run_init == "ERROR_up"
+ , running = run_init `elem` runningStates
, runSt = run_init
, pNode = pn
, sNode = sn
, idx = -1
- , util = T.zeroUtil
+ , util = T.baseUtil
+ , tags = tags_init
+ , movable = True
}
-- | Changes the index.
-> Instance -- ^ the modified instance
setBoth t p s = t { pNode = p, sNode = s }
+setMovable :: Instance -- ^ The original instance
+ -> Bool -- ^ New movable flag
+ -> Instance -- ^ The modified instance
+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