+-- | Looks up a node group. This is more tricky than for
+-- node/instances since the groups map is indexed by uuid, not name.
+getGroup :: ConfigData -> String -> ErrorResult NodeGroup
+getGroup cfg name =
+ let groups = fromContainer (configNodegroups cfg)
+ in case getItem "NodeGroup" name groups of
+ -- if not found by uuid, we need to look it up by name, slow
+ Ok grp -> Ok grp
+ Bad _ -> let by_name = M.mapKeys
+ (groupName . (M.!) groups) groups
+ in getItem "NodeGroup" name by_name
+
+-- | Computes a node group's node params.
+getGroupNdParams :: ConfigData -> NodeGroup -> FilledNDParams
+getGroupNdParams cfg ng =
+ fillNDParams (clusterNdparams $ configCluster cfg) (groupNdparams ng)
+
+-- | Computes a node group's ipolicy.
+getGroupIpolicy :: ConfigData -> NodeGroup -> FilledIPolicy
+getGroupIpolicy cfg ng =
+ fillIPolicy (clusterIpolicy $ configCluster cfg) (groupIpolicy ng)
+
+-- | Computes a group\'s (merged) disk params.
+getGroupDiskParams :: ConfigData -> NodeGroup -> DiskParams
+getGroupDiskParams cfg ng =
+ Container $
+ fillDict (fromContainer . clusterDiskparams $ configCluster cfg)
+ (fromContainer $ groupDiskparams ng) []
+
+-- | Get nodes of a given node group.
+getGroupNodes :: ConfigData -> String -> [Node]
+getGroupNodes cfg gname =
+ let all_nodes = M.elems . fromContainer . configNodes $ cfg in
+ filter ((==gname) . nodeGroup) all_nodes
+
+-- | Get (primary, secondary) instances of a given node group.
+getGroupInstances :: ConfigData -> String -> ([Instance], [Instance])
+getGroupInstances cfg gname =
+ let gnodes = map nodeName (getGroupNodes cfg gname)
+ ginsts = map (getNodeInstances cfg) gnodes in
+ (concatMap fst ginsts, concatMap snd ginsts)
+