From: Iustin Pop Date: Wed, 27 May 2009 19:53:51 +0000 (+0100) Subject: Add a separate function for looking up instances X-Git-Tag: htools-v0.1.2~25 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/5a1edeb69ddfbc9cf2c7ac5d4872fb1984a82c55?ds=sidebyside Add a separate function for looking up instances 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. --- diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index c45bdcd..bafde49 100644 --- a/Ganeti/HTools/IAlloc.hs +++ b/Ganeti/HTools/IAlloc.hs @@ -108,7 +108,7 @@ parseData body = 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' diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs index 1720bcb..0aac79a 100644 --- a/Ganeti/HTools/Loader.hs +++ b/Ganeti/HTools/Loader.hs @@ -9,6 +9,7 @@ module Ganeti.HTools.Loader , checkData , assignIndices , lookupNode + , lookupInstance , stripSuffix ) where @@ -29,6 +30,14 @@ lookupNode ktn inst node = 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)])