From 318c0a6c950081e75ff21dba65022a95b4ed6e81 Mon Sep 17 00:00:00 2001
From: Klaus Aehlig <aehlig@google.com>
Date: Thu, 2 May 2013 18:22:39 +0200
Subject: [PATCH] Make mkNodeGraph ignore edges to non-present nodes

Change the behavior of mkNodeGraph to tacitly ignore all instances
where one of the nodes is not in the list of nodes. In this way, we
can construct sub-graphs by filtering the nodes and ignoring any
possibly added isolated nodes for the missing indexes.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 src/Ganeti/HTools/Node.hs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/Ganeti/HTools/Node.hs b/src/Ganeti/HTools/Node.hs
index 83a3dee46..a55c3f808 100644
--- a/src/Ganeti/HTools/Node.hs
+++ b/src/Ganeti/HTools/Node.hs
@@ -586,7 +586,10 @@ nodesToBounds nl = liftM2 (,) nmin nmax
 -- Returns Nothing if the node list is empty.
 mkNodeGraph :: List -> Instance.List -> Maybe Graph.Graph
 mkNodeGraph nl il =
-  liftM (`Graph.buildG` instancesToEdges il) (nodesToBounds nl)
+  liftM (`Graph.buildG` (filterValid . instancesToEdges $ il))
+  (nodesToBounds nl)
+  where
+    filterValid = filter (\(x,y) -> IntMap.member x nl && IntMap.member y nl)
 
 -- * Display functions
 
-- 
GitLab