-- * Type declarations
--- | The tag map type
+-- | The tag map type.
type TagMap = Map.Map String Int
-- | The node type.
type List = Container.Container Node
-- | A simple name for an allocation element (here just for logistic
--- reasons)
+-- reasons).
type AllocElement = (List, Instance.Instance, [Node], T.Score)
-- | Constant node index for a non-moveable instance.
-- * Helper functions
--- | Add a tag to a tagmap
+-- | Add a tag to a tagmap.
addTag :: TagMap -> String -> TagMap
addTag t s = Map.insertWith (+) s 1 t
--- | Add multiple tags
+-- | Add multiple tags.
addTags :: TagMap -> [String] -> TagMap
addTags = foldl' addTag
--- | Adjust or delete a tag from a tagmap
+-- | Adjust or delete a tag from a tagmap.
delTag :: TagMap -> String -> TagMap
delTag t s = Map.update (\v -> if v > 1
then Just (v-1)
else Nothing)
s t
--- | Remove multiple tags
+-- | Remove multiple tags.
delTags :: TagMap -> [String] -> TagMap
delTags = foldl' delTag
--- | Check if we can add a list of tags to a tagmap
+-- | Check if we can add a list of tags to a tagmap.
rejectAddTags :: TagMap -> [String] -> Bool
rejectAddTags t = any (`Map.member` t)
, group = group_init
}
--- | Conversion formula from mDsk\/tDsk to loDsk
+-- | Conversion formula from mDsk\/tDsk to loDsk.
mDskToloDsk :: Double -> Double -> Int
mDskToloDsk mval tdsk = floor (mval * tdsk)
--- | Conversion formula from mCpu\/tCpu to hiCpu
+-- | Conversion formula from mCpu\/tCpu to hiCpu.
mCpuTohiCpu :: Double -> Double -> Int
mCpuTohiCpu mval tcpu = floor (mval * tcpu)
setXmem :: Node -> Int -> Node
setXmem t val = t { xMem = val }
--- | Sets the max disk usage ratio
+-- | Sets the max disk usage ratio.
setMdsk :: Node -> Double -> Node
setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) }
--- | Sets the max cpu usage ratio
+-- | Sets the max cpu usage ratio.
setMcpu :: Node -> Double -> Node
setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
buildPeers t il =
let mdata = map
(\i_idx -> let inst = Container.find i_idx il
- mem = if Instance.auto_balance inst
+ mem = if Instance.autoBalance inst
then Instance.mem inst
else 0
in (Instance.pNode inst, mem))
new_dsk = fDsk t + Instance.dsk inst
old_peers = peers t
old_peem = P.find pnode old_peers
- new_peem = if Instance.auto_balance inst
+ new_peem = if Instance.autoBalance inst
then old_peem - Instance.mem inst
else old_peem
new_peers = if new_peem > 0
old_peers = peers t
old_mem = fMem t
new_dsk = fDsk t - Instance.dsk inst
- secondary_needed_mem = if Instance.auto_balance inst
+ secondary_needed_mem = if Instance.autoBalance inst
then Instance.mem inst
else 0
new_peem = P.find pdx old_peers + secondary_needed_mem
-- * Stats functions
--- | Computes the amount of available disk on a given node
+-- | Computes the amount of available disk on a given node.
availDisk :: Node -> Int
availDisk t =
let _f = fDsk t
then 0
else _f - _l
--- | Computes the amount of used disk on a given node
+-- | Computes the amount of used disk on a given node.
iDsk :: Node -> Int
iDsk t = truncate (tDsk t) - fDsk t
--- | Computes the amount of available memory on a given node
+-- | Computes the amount of available memory on a given node.
availMem :: Node -> Int
availMem t =
let _f = fMem t
then 0
else _f - _l
--- | Computes the amount of available memory on a given node
+-- | Computes the amount of available memory on a given node.
availCpu :: Node -> Int
availCpu t =
let _u = uCpu t
-- * Display functions
-showField :: Node -> String -> String
+-- | Return a field for a given node.
+showField :: Node -- ^ Node which we're querying
+ -> String -- ^ Field name
+ -> String -- ^ Field value as string
showField t field =
case field of
"idx" -> printf "%4d" $ idx t
"name" -> alias t
"fqdn" -> name t
- "status" -> if offline t then "-"
- else if failN1 t then "*" else " "
+ "status" -> case () of
+ _ | offline t -> "-"
+ | failN1 t -> "*"
+ | otherwise -> " "
"tmem" -> printf "%5.0f" $ tMem t
"nmem" -> printf "%5d" $ nMem t
"xmem" -> printf "%5d" $ xMem t
T.DynUtil { T.cpuWeight = uC, T.memWeight = uM,
T.dskWeight = uD, T.netWeight = uN } = utilLoad t
--- | Returns the header and numeric propery of a field
+-- | Returns the header and numeric propery of a field.
showHeader :: String -> (String, Bool)
showHeader field =
case field of
list fields t = map (showField t) fields
+-- | Constant holding the fields we're displaying by default.
defaultFields :: [String]
defaultFields =
[ "status", "name", "tmem", "nmem", "imem", "xmem", "fmem"
, "cload", "mload", "dload", "nload" ]
-- | Split a list of nodes into a list of (node group UUID, list of
--- associated nodes)
+-- associated nodes).
computeGroups :: [Node] -> [(T.Gdx, [Node])]
computeGroups nodes =
let nodes' = sortBy (comparing group) nodes