Add a separate function for looking up instances
authorIustin Pop <iustin@google.com>
Wed, 27 May 2009 19:53:51 +0000 (20:53 +0100)
committerIustin Pop <iustin@google.com>
Wed, 27 May 2009 19:53:51 +0000 (20:53 +0100)
Currently we (wrongly) use lookupNode to lookup instances, just because
the name assoc list has the same type. This patch adds a separate
function for it.

Ganeti/HTools/IAlloc.hs
Ganeti/HTools/Loader.hs

index c45bdcd..bafde49 100644 (file)
@@ -108,7 +108,7 @@ parseData body = do
               return $ Allocate io req_nodes
         "relocate" ->
             do
               return $ Allocate io req_nodes
         "relocate" ->
             do
-              ridx <- lookupNode kti rname rname
+              ridx <- lookupInstance kti rname
               ex_nodes <- fromObj "relocate_from" request
               let ex_nodes' = map (stripSuffix $ length csf) ex_nodes
               ex_idex <- mapM (Container.findByName map_n) ex_nodes'
               ex_nodes <- fromObj "relocate_from" request
               let ex_nodes' = map (stripSuffix $ length csf) ex_nodes
               ex_idex <- mapM (Container.findByName map_n) ex_nodes'
index 1720bcb..0aac79a 100644 (file)
@@ -9,6 +9,7 @@ module Ganeti.HTools.Loader
     , checkData
     , assignIndices
     , lookupNode
     , checkData
     , assignIndices
     , lookupNode
+    , lookupInstance
     , stripSuffix
     ) where
 
     , stripSuffix
     ) where
 
@@ -29,6 +30,14 @@ lookupNode ktn inst node =
       Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ inst
       Just idx -> return idx
 
       Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ inst
       Just idx -> return idx
 
+-- | Lookups an instance into an assoc list
+lookupInstance :: (Monad m) => [(String, Idx)] -> String -> m Idx
+lookupInstance kti inst =
+    case lookup inst kti of
+      Nothing -> fail $ "Unknown instance '" ++ inst ++ "'"
+      Just idx -> return idx
+
+-- | Given a list of elements (and their names), assign indices to them
 assignIndices :: (Element a) =>
                  [(String, a)]
               -> (NameAssoc, [(Int, a)])
 assignIndices :: (Element a) =>
                  [(String, a)]
               -> (NameAssoc, [(Int, a)])