IAlloc: read group uuid from the input message
[ganeti-local] / Ganeti / HTools / Types.hs
index fb6493e..7cab641 100644 (file)
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2009 Google Inc.
+Copyright (C) 2009, 2010 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -35,6 +35,12 @@ module Ganeti.HTools.Types
     , baseUtil
     , addUtil
     , subUtil
+    , defVcpuRatio
+    , defReservedDiskRatio
+    , unitMem
+    , unitCpu
+    , unitDsk
+    , unknownField
     , Placement
     , IMove(..)
     , MoveJob
@@ -77,7 +83,7 @@ data DynUtil = DynUtil
     , memWeight :: Weight -- ^ Standardised memory load
     , dskWeight :: Weight -- ^ Standardised disk I\/O usage
     , netWeight :: Weight -- ^ Standardised network usage
-    } deriving (Show)
+    } deriving (Show, Eq)
 
 -- | Initial empty utilisation
 zeroUtil :: DynUtil
@@ -113,6 +119,10 @@ data IMove = Failover                -- ^ Failover the instance (f)
 -- commands
 type MoveJob = ([Ndx], Idx, IMove, [String])
 
+-- | Unknown field in table output
+unknownField :: String
+unknownField = "<unknown field>"
+
 -- | A list of command elements
 type JobSet = [MoveJob]
 
@@ -124,6 +134,26 @@ connTimeout = 15
 queryTimeout :: Int
 queryTimeout = 60
 
+-- | Default vcpu-to-pcpu ratio (randomly chosen value).
+defVcpuRatio :: Double
+defVcpuRatio = 64
+
+-- | Default max disk usage ratio.
+defReservedDiskRatio :: Double
+defReservedDiskRatio = 0
+
+-- | Base memory unit.
+unitMem :: Int
+unitMem = 64
+
+-- | Base disk unit.
+unitDsk :: Int
+unitDsk = 256
+
+-- | Base vcpus unit.
+unitCpu :: Int
+unitCpu = 1
+
 {-|
 
 This is similar to the JSON library Result type - *very* similar, but
@@ -156,6 +186,7 @@ type FailStats = [(FailMode, Int)]
 -- | Either-like data-type customized for our failure modes
 data OpResult a = OpFail FailMode -- ^ Failed operation
                 | OpGood a        -- ^ Success operation
+                  deriving (Show)
 
 instance Monad OpResult where
     (OpGood x) >>= fn = fn x
@@ -166,9 +197,17 @@ instance Monad OpResult where
 class Element a where
     -- | Returns the name of the element
     nameOf  :: a -> String
+    -- | Returns all the known names of the element
+    allNames :: a -> [String]
     -- | Returns the index of the element
     idxOf   :: a -> Int
-    -- | Updates the name of the element
-    setName :: a -> String -> a
+    -- | Updates the alias of the element
+    setAlias :: a -> String -> a
+    -- | Compute the alias by stripping a given suffix (domain) from
+    -- | the name
+    computeAlias :: String -> a -> a
+    computeAlias dom e = setAlias e alias
+        where alias = take (length name - length dom) name
+              name = nameOf e
     -- | Updates the index of the element
     setIdx  :: a -> Int -> a