diff --git a/Ganeti/HTools/CLI.hs b/Ganeti/HTools/CLI.hs index 8f177da00d86c17814825f95ee9bb767533d0a1d..7a216cc138561a9d6fce685abf02e33d160b629e 100644 --- a/Ganeti/HTools/CLI.hs +++ b/Ganeti/HTools/CLI.hs @@ -98,7 +98,7 @@ shTemplate = -- | External tool data loader from a variety of sources loadExternalData :: (EToolOptions a) => a - -> IO (NodeList, InstanceList, String, NameList, NameList) + -> IO (NodeList, InstanceList, String) loadExternalData opts = do (env_node, env_inst) <- parseEnv () let nodef = if nodeSet opts then nodeFile opts @@ -111,7 +111,7 @@ loadExternalData opts = do host -> Rapi.loadData host let ldresult = input_data >>= Loader.mergeData - (loaded_nl, il, csf, ktn, kti) <- + (loaded_nl, il, csf) <- (case ldresult of Ok x -> return x Bad s -> do @@ -124,4 +124,4 @@ loadExternalData opts = do putStrLn "Warning: cluster has inconsistent data:" putStrLn . unlines . map (\s -> printf " - %s" s) $ fix_msgs - return (fixed_nl, il, csf, ktn, kti) + return (fixed_nl, il, csf) diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index 8803a0ceb4a0fc35b37c21e37f90ae6e2e1796b9..0ead96fd155c5a41564d7a5d8b2da62e663a2360 100644 --- a/Ganeti/HTools/IAlloc.hs +++ b/Ganeti/HTools/IAlloc.hs @@ -26,7 +26,7 @@ data RqType | Relocate Int deriving (Show) -data Request = Request RqType NodeList InstanceList String NameList NameList +data Request = Request RqType NodeList InstanceList String deriving (Show) parseBaseInstance :: String @@ -101,8 +101,8 @@ parseData body = do ridx <- lookupNode kti rname rname return $ Relocate ridx other -> fail $ ("Invalid request type '" ++ other ++ "'") - (map_n, map_i, csf, xtn, xti) <- mergeData (ktn, nl, kti, il) - return $ Request rqtype map_n map_i csf xtn xti + (map_n, map_i, csf) <- mergeData (ktn, nl, kti, il) + return $ Request rqtype map_n map_i csf formatResponse :: Bool -> String -> [String] -> String formatResponse success info nodes = diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs index ca58d4cc5ad52d60aa475d9cd143faac4ed5ee2f..b7dd606d3971d536504c461da7c5a04cc3a1d774 100644 --- a/Ganeti/HTools/Loader.hs +++ b/Ganeti/HTools/Loader.hs @@ -68,13 +68,10 @@ fixNodes nl il = -- | Compute the longest common suffix of a NameList list that -- | starts with a dot -longestDomain :: NameList -> String +longestDomain :: [String] -> String longestDomain [] = "" -longestDomain ((_,x):xs) = - let - onlyStrings = snd $ unzip xs - in - foldr (\ suffix accu -> if all (isSuffixOf suffix) onlyStrings +longestDomain (x:xs) = + foldr (\ suffix accu -> if all (isSuffixOf suffix) xs then suffix else accu) "" $ filter (isPrefixOf ".") (tails x) @@ -89,22 +86,20 @@ mergeData :: ([(String, Int)], Node.AssocList, [(String, Int)], Instance.AssocList) -- ^ Data from either -- Text.loadData -- or Rapi.loadData - -> Result (NodeList, InstanceList, String, NameList, NameList) + -> Result (NodeList, InstanceList, String) mergeData (ktn, nl, kti, il) = do let nl2 = fixNodes nl il il3 = Container.fromAssocList il nl3 = Container.fromAssocList (map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl2))) nl2) - xtn = swapPairs ktn - xti = swapPairs kti - common_suffix = longestDomain (xti ++ xtn) + node_names = map Node.name $ Container.elems nl3 + inst_names = map Instance.name $ Container.elems il3 + common_suffix = longestDomain (node_names ++ inst_names) csl = length common_suffix - stn = map (\(x, y) -> (x, stripSuffix csl y)) xtn - sti = map (\(x, y) -> (x, stripSuffix csl y)) xti snl = Container.map (\n -> setName n (stripSuffix csl $ name n)) nl3 sil = Container.map (\i -> setName i (stripSuffix csl $ name i)) il3 - return (snl, sil, common_suffix, stn, sti) + return (snl, sil, common_suffix) -- | Check cluster data for consistency checkData :: NodeList -> InstanceList diff --git a/hbal.hs b/hbal.hs index 7f0ae28d24420130c4d565d7eabdb60b36244f21..3f217e1a4627b159ea75e2f144db8995dad2513e 100644 --- a/hbal.hs +++ b/hbal.hs @@ -181,7 +181,7 @@ main = do let oneline = optOneline opts verbose = optVerbose opts - (fixed_nl, il, csf, _, _) <- CLI.loadExternalData opts + (fixed_nl, il, csf) <- CLI.loadExternalData opts let offline_names = optOffline opts all_nodes = Container.elems fixed_nl diff --git a/hn1.hs b/hn1.hs index 962558f80b2ddcf94535f606785ebabe78870728..4b3064e7e7f91042369c74842df9fc72a1af1915 100644 --- a/hn1.hs +++ b/hn1.hs @@ -145,7 +145,7 @@ main = do hPutStrLn stderr "Error: this program doesn't take any arguments." exitWith $ ExitFailure 1 - (nl, il, csf, _, _) <- CLI.loadExternalData opts + (nl, il, csf) <- CLI.loadExternalData opts printf "Loaded %d nodes, %d instances\n" (Container.size nl) diff --git a/hscan.hs b/hscan.hs index fab3bdbb5964af669a2bf0552877c0a5eaaf5f87..5189b589debc24233cef8364d94a4b0a64aebab7 100644 --- a/hscan.hs +++ b/hscan.hs @@ -6,7 +6,6 @@ module Main (main) where import Data.List import Data.Function -import Data.Maybe(fromJust) import Monad import System import System.IO @@ -162,7 +161,7 @@ main = do Bad err -> printf "\nError: failed to load data. \ \Details:\n%s\n" err Ok x -> do - let (nl, il, csf, _, _) = x + let (nl, il, csf) = x (_, fix_nl) = Loader.checkData nl il putStrLn $ printCluster fix_nl il when (optShowNodes opts) $ do