Fix hspace's KM metrics
[ganeti-local] / Ganeti / HTools / Types.hs
index 8b08235..fb6493e 100644 (file)
@@ -27,6 +27,18 @@ module Ganeti.HTools.Types
     ( Idx
     , Ndx
     , NameAssoc
+    , Score
+    , Weight
+    , RSpec(..)
+    , DynUtil(..)
+    , zeroUtil
+    , baseUtil
+    , addUtil
+    , subUtil
+    , Placement
+    , IMove(..)
+    , MoveJob
+    , JobSet
     , Result(..)
     , Element(..)
     , FailMode(..)
@@ -45,6 +57,65 @@ type Ndx = Int
 -- | The type used to hold name-to-idx mappings.
 type NameAssoc = [(String, Int)]
 
+-- | A separate name for the cluster score type.
+type Score = Double
+
+-- | A separate name for a weight metric.
+type Weight = Double
+
+-- | The resource spec type.
+data RSpec = RSpec
+    { rspecCpu  :: Int  -- ^ Requested VCPUs
+    , rspecMem  :: Int  -- ^ Requested memory
+    , rspecDsk  :: Int  -- ^ Requested disk
+    } deriving (Show, Eq)
+
+-- | The dynamic resource specs of a machine (i.e. load or load
+-- capacity, as opposed to size).
+data DynUtil = DynUtil
+    { cpuWeight :: Weight -- ^ Standardised CPU usage
+    , memWeight :: Weight -- ^ Standardised memory load
+    , dskWeight :: Weight -- ^ Standardised disk I\/O usage
+    , netWeight :: Weight -- ^ Standardised network usage
+    } deriving (Show)
+
+-- | Initial empty utilisation
+zeroUtil :: DynUtil
+zeroUtil = DynUtil { cpuWeight = 0, memWeight = 0
+                   , dskWeight = 0, netWeight = 0 }
+
+baseUtil :: DynUtil
+baseUtil = DynUtil { cpuWeight = 1, memWeight = 1
+                   , dskWeight = 1, netWeight = 1 }
+
+addUtil :: DynUtil -> DynUtil -> DynUtil
+addUtil (DynUtil a1 a2 a3 a4) (DynUtil b1 b2 b3 b4) =
+    DynUtil (a1+b1) (a2+b2) (a3+b3) (a4+b4)
+
+subUtil :: DynUtil -> DynUtil -> DynUtil
+subUtil (DynUtil a1 a2 a3 a4) (DynUtil b1 b2 b3 b4) =
+    DynUtil (a1-b1) (a2-b2) (a3-b3) (a4-b4)
+
+-- | The description of an instance placement. It contains the
+-- instance index, the new primary and secondary node, the move being
+-- performed and the score of the cluster after the move.
+type Placement = (Idx, Ndx, Ndx, IMove, Score)
+
+-- | An instance move definition
+data IMove = Failover                -- ^ Failover the instance (f)
+           | ReplacePrimary Ndx      -- ^ Replace primary (f, r:np, f)
+           | ReplaceSecondary Ndx    -- ^ Replace secondary (r:ns)
+           | ReplaceAndFailover Ndx  -- ^ Replace secondary, failover (r:np, f)
+           | FailoverAndReplace Ndx  -- ^ Failover, replace secondary (f, r:ns)
+             deriving (Show)
+
+-- | Formatted solution output for one move (involved nodes and
+-- commands
+type MoveJob = ([Ndx], Idx, IMove, [String])
+
+-- | A list of command elements
+type JobSet = [MoveJob]
+
 -- | Connection timeout (when using non-file methods).
 connTimeout :: Int
 connTimeout = 15
@@ -76,6 +147,7 @@ data FailMode = FailMem  -- ^ Failed due to not enough RAM
               | FailDisk -- ^ Failed due to not enough disk
               | FailCPU  -- ^ Failed due to not enough CPU capacity
               | FailN1   -- ^ Failed due to not passing N1 checks
+              | FailTags -- ^ Failed due to tag exclusion
                 deriving (Eq, Enum, Bounded, Show)
 
 -- | List with failure statistics