From 5a1edeb69ddfbc9cf2c7ac5d4872fb1984a82c55 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 27 May 2009 20:53:51 +0100 Subject: [PATCH] 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. --- Ganeti/HTools/IAlloc.hs | 2 +- Ganeti/HTools/Loader.hs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index c45bdcd27..bafde4975 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 1720bcb6f..0aac79af7 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)]) -- GitLab