hail: do not allocate on offline/drained nodes
authorIustin Pop <iustin@google.com>
Mon, 25 May 2009 18:50:54 +0000 (19:50 +0100)
committerIustin Pop <iustin@google.com>
Mon, 25 May 2009 18:50:54 +0000 (19:50 +0100)
This patch implements filtering out of the offline/drained nodes and
fixes a bug in IAllocator.hs parsing (similar to an older bug in Rapi.hs
from where the code was copied).

Ganeti/HTools/IAlloc.hs
hail.hs

index bd762d1..9e19fe9 100644 (file)
@@ -69,7 +69,7 @@ parseNode n a = do
     dtotal <- fromObj "total_disk" a
     dfree <- fromObj "free_disk" a
     offline <- fromObj "offline" a
-    drained <- fromObj "offline" a
+    drained <- fromObj "drained" a
     return $ (name, Node.create n mtotal mnode mfree dtotal dfree
                       (offline || drained))
 
diff --git a/hail.hs b/hail.hs
index b879ae1..217c799 100644 (file)
--- a/hail.hs
+++ b/hail.hs
@@ -51,6 +51,10 @@ options =
       "show help"
     ]
 
+-- | Compute online nodes from a NodeList
+getOnline :: NodeList -> [Node.Node]
+getOnline = filter (not . Node.offline) . Container.elems
+
 -- | Try to allocate an instance on the cluster
 tryAlloc :: (Monad m) =>
             NodeList
@@ -59,7 +63,7 @@ tryAlloc :: (Monad m) =>
          -> Int
          -> m [(Maybe NodeList, [Node.Node])]
 tryAlloc nl _ inst 2 =
-    let all_nodes = Container.elems nl
+    let all_nodes = getOnline nl
         all_pairs = liftM2 (,) all_nodes all_nodes
         ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y) all_pairs
         sols = map (\(p, s) ->
@@ -68,7 +72,7 @@ tryAlloc nl _ inst 2 =
     in return sols
 
 tryAlloc nl _ inst 1 =
-    let all_nodes = Container.elems nl
+    let all_nodes = getOnline nl
         sols = map (\p -> (fst $ Cluster.allocateOnSingle nl inst p, [p]))
                all_nodes
     in return sols
@@ -86,7 +90,7 @@ tryReloc :: (Monad m) =>
          -> [Int]
          -> m [(Maybe NodeList, [Node.Node])]
 tryReloc nl il xid 1 ex_idx =
-    let all_nodes = Container.elems nl
+    let all_nodes = getOnline nl
         inst = Container.find xid il
         valid_nodes = filter (not . flip elem ex_idx . idx) all_nodes
         valid_idxes = map Node.idx valid_nodes