module Ganeti.HTools.Node
(
- Node(failN1, idx, t_mem, n_mem, f_mem, t_dsk, f_dsk,
+ Node(failN1, name, idx, t_mem, n_mem, f_mem, t_dsk, f_dsk,
p_mem, p_dsk, p_rem,
plist, slist, offline)
-- * Constructor
-- ** Finalization after data loading
, buildPeers
, setIdx
+ , setName
, setOffline
, setXmem
, setFmem
, setSec
-- * Formatting
, list
+ -- * Misc stuff
+ , AssocList
+ , noSecondary
) where
import Data.List
import qualified Ganeti.HTools.Instance as Instance
import qualified Ganeti.HTools.PeerMap as PeerMap
-import Ganeti.HTools.Utils
-
-data Node = Node { t_mem :: Double -- ^ total memory (MiB)
+data Node = Node { name :: String -- ^ the node name
+ , t_mem :: Double -- ^ total memory (MiB)
, n_mem :: Int -- ^ node memory (MiB)
, f_mem :: Int -- ^ free memory (MiB)
, x_mem :: Int -- ^ unaccounted memory (MiB)
-- score computations
} deriving (Show)
+-- | A simple name for the int, node association list
+type AssocList = [(Int, Node)]
+
+-- | Constant node index for a non-moveable instance
+noSecondary :: Int
+noSecondary = -1
+
{- | Create a new node.
The index and the peers maps are empty, and will be need to be update
later via the 'setIdx' and 'buildPeers' functions.
-}
-create :: Double -> Int -> Int -> Double -> Int -> Node
-create mem_t_init mem_n_init mem_f_init dsk_t_init dsk_f_init =
+create :: String -> Double -> Int -> Int -> Double -> Int -> Bool -> Node
+create name_init mem_t_init mem_n_init mem_f_init
+ dsk_t_init dsk_f_init offline_init =
Node
{
+ name = name_init,
t_mem = mem_t_init,
n_mem = mem_n_init,
f_mem = mem_f_init,
p_mem = (fromIntegral mem_f_init) / mem_t_init,
p_dsk = (fromIntegral dsk_f_init) / dsk_t_init,
p_rem = 0,
- offline = False,
+ offline = offline_init,
x_mem = 0
}
setIdx :: Node -> Int -> Node
setIdx t i = t {idx = i}
+-- | Changes the name
+-- This is used only during the building of the data structures.
+setName t s = t {name = s}
+
-- | Sets the offline attribute
setOffline :: Node -> Bool -> Node
setOffline t val = t { offline = val }
-- | Sets the free memory
setFmem :: Node -> Int -> Node
-setFmem t val = t { f_mem = val }
+setFmem t new_mem =
+ let new_n1 = computeFailN1 (r_mem t) new_mem (f_dsk t)
+ new_mp = (fromIntegral new_mem) / (t_mem t)
+ in
+ t { f_mem = new_mem, failN1 = new_n1, p_mem = new_mp }
-- | Given the rmem, free memory and disk, computes the failn1 status.
computeFailN1 :: Int -> Int -> Int -> Bool