diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index 52eaf12516f1c805735c36312d4e82a9e7899368..dc2c858431631cd87ad5780f742fef478327d729 100644 --- a/Ganeti/HTools/IAlloc.hs +++ b/Ganeti/HTools/IAlloc.hs @@ -64,7 +64,9 @@ parseInstance :: NameAssoc -- ^ The node name-to-index association list parseInstance ktn n a = do base <- parseBaseInstance n a nodes <- fromObj "nodes" a - pnode <- readEitherString $ head nodes + pnode <- if null nodes + then Bad $ "empty node list for instance " ++ n + else readEitherString $ head nodes pidx <- lookupNode ktn n pnode let snodes = tail nodes sidx <- (if null snodes then return Node.noSecondary @@ -141,8 +143,10 @@ parseData body = do other -> fail ("Invalid request type '" ++ other ++ "'") return $ Request rqtype map_n map_i ptags csf -formatRVal :: String -> RqType - -> [Node.AllocElement] -> JSValue +-- | Format the result +formatRVal :: String -> RqType -> [Node.AllocElement] -> JSValue +formatRVal _ _ [] = JSArray [] + formatRVal csf (Evacuate _) elems = let sols = map (\(_, inst, nl) -> let names = Instance.name inst : map Node.name nl @@ -155,7 +159,6 @@ formatRVal csf _ elems = nodes' = map ((++ csf) . Node.name) nodes in JSArray $ map (JSString . toJSString) nodes' - -- | Formats the response into a valid IAllocator response message. formatResponse :: Bool -- ^ Whether the request was successful -> String -- ^ Information text