diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index c45bdcd279e722d704f5a0052e3101e58393196d..bafde4975c491e4ec450870b5f096d17cfb25891 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 1720bcb6f1420f3c7e2771b529d1a2517e204e7b..0aac79af7df3f5ddaad45bc2a9aecb75b2f46f87 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)])