projects
/
ganeti-local
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Convert Text.serializeCluster to ClusterData
[ganeti-local]
/
Ganeti
/
HTools
/
Node.hs
diff --git
a/Ganeti/HTools/Node.hs
b/Ganeti/HTools/Node.hs
index
88a6000
..
73162e6
100644
(file)
--- a/
Ganeti/HTools/Node.hs
+++ b/
Ganeti/HTools/Node.hs
@@
-66,11
+66,13
@@
module Ganeti.HTools.Node
, AssocList
, AllocElement
, noSecondary
, AssocList
, AllocElement
, noSecondary
+ , computeGroups
) where
import Data.List hiding (group)
import qualified Data.Map as Map
import qualified Data.Foldable as Foldable
) where
import Data.List hiding (group)
import qualified Data.Map as Map
import qualified Data.Foldable as Foldable
+import Data.Ord (comparing)
import Text.Printf (printf)
import qualified Ganeti.HTools.Container as Container
import Text.Printf (printf)
import qualified Ganeti.HTools.Container as Container
@@
-119,7
+121,7
@@
data Node = Node
, utilPool :: T.DynUtil -- ^ Total utilisation capacity
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
, pTags :: TagMap -- ^ Map of primary instance tags and their count
, utilPool :: T.DynUtil -- ^ Total utilisation capacity
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
, pTags :: TagMap -- ^ Map of primary instance tags and their count
- , group :: T.GroupID -- ^ The node's group (as UUID)
+ , group :: T.Gdx -- ^ The node's group (index)
} deriving (Show, Eq)
instance T.Element Node where
} deriving (Show, Eq)
instance T.Element Node where
@@
-137,7
+139,7
@@
type List = Container.Container Node
-- | A simple name for an allocation element (here just for logistic
-- reasons)
-- | A simple name for an allocation element (here just for logistic
-- reasons)
-type AllocElement = (List, Instance.Instance, [Node])
+type AllocElement = (List, Instance.Instance, [Node], T.Score)
-- | Constant node index for a non-moveable instance.
noSecondary :: T.Ndx
-- | Constant node index for a non-moveable instance.
noSecondary :: T.Ndx
@@
-183,7
+185,7
@@
conflictingPrimaries (Node { pTags = t }) = Foldable.sum t - Map.size t
-- The index and the peers maps are empty, and will be need to be
-- update later via the 'setIdx' and 'buildPeers' functions.
create :: String -> Double -> Int -> Int -> Double
-- The index and the peers maps are empty, and will be need to be
-- update later via the 'setIdx' and 'buildPeers' functions.
create :: String -> Double -> Int -> Int -> Double
- -> Int -> Double -> Bool -> String -> Node
+ -> Int -> Double -> Bool -> T.Gdx -> Node
create name_init mem_t_init mem_n_init mem_f_init
dsk_t_init dsk_f_init cpu_t_init offline_init group_init =
Node { name = name_init
create name_init mem_t_init mem_n_init mem_f_init
dsk_t_init dsk_f_init cpu_t_init offline_init group_init =
Node { name = name_init
@@
-485,7
+487,6
@@
showField t field =
"ptags" -> intercalate "," . map (\(k, v) -> printf "%s=%d" k v) .
Map.toList $ pTags t
"peermap" -> show $ peers t
"ptags" -> intercalate "," . map (\(k, v) -> printf "%s=%d" k v) .
Map.toList $ pTags t
"peermap" -> show $ peers t
- "group.uuid" -> group t
_ -> T.unknownField
where
T.DynUtil { T.cpuWeight = uC, T.memWeight = uM,
_ -> T.unknownField
where
T.DynUtil { T.cpuWeight = uC, T.memWeight = uM,
@@
-524,7
+525,7
@@
showHeader field =
"nload" -> ("lNet", True)
"ptags" -> ("PrimaryTags", False)
"peermap" -> ("PeerMap", False)
"nload" -> ("lNet", True)
"ptags" -> ("PrimaryTags", False)
"peermap" -> ("PeerMap", False)
- "group.uuid" -> ("GroupUUID", False)
+ -- TODO: add node fields (group.uuid, group)
_ -> (T.unknownField, False)
-- | String converter for the node list functionality.
_ -> (T.unknownField, False)
-- | String converter for the node list functionality.
@@
-538,3
+539,11
@@
defaultFields =
, "rmem", "tdsk", "fdsk", "tcpu", "ucpu", "pcnt", "scnt"
, "pfmem", "pfdsk", "rcpu"
, "cload", "mload", "dload", "nload" ]
, "rmem", "tdsk", "fdsk", "tcpu", "ucpu", "pcnt", "scnt"
, "pfmem", "pfdsk", "rcpu"
, "cload", "mload", "dload", "nload" ]
+
+-- | Split a list of nodes into a list of (node group UUID, list of
+-- associated nodes)
+computeGroups :: [Node] -> [(T.Gdx, [Node])]
+computeGroups nodes =
+ let nodes' = sortBy (comparing group) nodes
+ nodes'' = groupBy (\a b -> group a == group b) nodes'
+ in map (\nl -> (group (head nl), nl)) nodes''