+-- | Removes node groups which can't accommodate the instance
+filterValidGroups :: [(Group.Group, (Node.List, Instance.List))]
+ -> Instance.Instance
+ -> ([(Group.Group, (Node.List, Instance.List))], [String])
+filterValidGroups [] _ = ([], [])
+filterValidGroups (ng:ngs) inst =
+ let (valid_ngs, msgs) = filterValidGroups ngs inst
+ hasNetwork nic = case Nic.network nic of
+ Just net -> net `elem` Group.networks (fst ng)
+ Nothing -> True
+ hasRequiredNetworks = all hasNetwork (Instance.nics inst)
+ in if hasRequiredNetworks
+ then (ng:valid_ngs, msgs)
+ else (valid_ngs,
+ ("group " ++ Group.name (fst ng) ++
+ " is not connected to a network required by instance " ++
+ Instance.name inst):msgs)
+