From: Iustin Pop Date: Sat, 23 May 2009 23:36:36 +0000 (+0100) Subject: Remove the ktn/kti from second half of loading X-Git-Tag: htools-v0.1.1~17 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/8472a321e402c2c47751f4eba3c1af0b613639a9 Remove the ktn/kti from second half of loading This removes the return of ktn/kti from Loader.mergeData and associated functions. --- diff --git a/Ganeti/HTools/CLI.hs b/Ganeti/HTools/CLI.hs index 8f177da..7a216cc 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 8803a0c..0ead96f 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 ca58d4c..b7dd606 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 7f0ae28..3f217e1 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 962558f..4b3064e 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 fab3bdb..5189b58 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