Fix hspace's KM metrics
[ganeti-local] / Ganeti / HTools / Instance.hs
index fe64d63..c091f62 100644 (file)
@@ -36,8 +36,10 @@ module Ganeti.HTools.Instance
     , setPri
     , setSec
     , setBoth
+    , setMovable
     , specOf
     , shrinkByType
+    , runningStates
     ) where
 
 import qualified Ganeti.HTools.Types as T
@@ -56,6 +58,8 @@ data Instance = Instance { name :: String    -- ^ The instance name
                          , 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
@@ -74,6 +78,10 @@ unitDsk = 256
 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)]
 
@@ -86,18 +94,21 @@ 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 -> 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.baseUtil
+             , tags = tags_init
+             , movable = True
              }
 
 -- | Changes the index.
@@ -137,6 +148,11 @@ setBoth :: Instance  -- ^ the original instance
          -> 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