From 94e05c32479017bf4882a18e933551f74d491b9e Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 27 Nov 2009 16:13:12 +0100 Subject: [PATCH] Introduce support for reading the cluster tags While these are not actually populated from the backends, and all the programs ignore them, this patch contains the changes in the function types required. --- Ganeti/HTools/ExtLoader.hs | 6 +++--- Ganeti/HTools/IAlloc.hs | 2 +- Ganeti/HTools/Loader.hs | 11 +++++------ Ganeti/HTools/Luxi.hs | 4 ++-- Ganeti/HTools/Rapi.hs | 4 ++-- Ganeti/HTools/Simu.hs | 4 ++-- Ganeti/HTools/Text.hs | 4 ++-- hbal.hs | 2 +- hscan.hs | 2 +- hspace.hs | 2 +- 10 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Ganeti/HTools/ExtLoader.hs b/Ganeti/HTools/ExtLoader.hs index bd2e01ad5..94c787bd0 100644 --- a/Ganeti/HTools/ExtLoader.hs +++ b/Ganeti/HTools/ExtLoader.hs @@ -83,7 +83,7 @@ parseUtilisation line = -- | External tool data loader from a variety of sources. loadExternalData :: Options - -> IO (Node.List, Instance.List, String) + -> IO (Node.List, Instance.List, [String], String) loadExternalData opts = do (env_node, env_inst) <- parseEnv () let nodef = if optNodeSet opts then optNodeFile opts @@ -131,7 +131,7 @@ loadExternalData opts = do | otherwise -> wrapIO $ Text.loadData nodef instf let ldresult = input_data >>= Loader.mergeData util_data' exTags - (loaded_nl, il, csf) <- + (loaded_nl, il, tags, csf) <- (case ldresult of Ok x -> return x Bad s -> do @@ -144,4 +144,4 @@ loadExternalData opts = do hPutStrLn stderr "Warning: cluster has inconsistent data:" hPutStrLn stderr . unlines . map (printf " - %s") $ fix_msgs - return (fixed_nl, il, csf) + return (fixed_nl, il, tags, csf) diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index 3215cb33c..be9d5063d 100644 --- a/Ganeti/HTools/IAlloc.hs +++ b/Ganeti/HTools/IAlloc.hs @@ -110,7 +110,7 @@ parseData body = do iobj <- mapM (\(x,y) -> asJSObject y >>= parseInstance ktn x . fromJSObject) idata let (kti, il) = assignIndices iobj - (map_n, map_i, csf) <- mergeData [] [] (nl, il) + (map_n, map_i, _, csf) <- mergeData [] [] (nl, il, []) req_nodes <- fromObj "required_nodes" request optype <- fromObj "type" request rqtype <- diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs index 35be6ffb3..c1ad0a70f 100644 --- a/Ganeti/HTools/Loader.hs +++ b/Ganeti/HTools/Loader.hs @@ -140,11 +140,10 @@ stripSuffix sflen name = take (length name - sflen) name -- list and massages it into the correct format. mergeData :: [(String, DynUtil)] -- ^ Instance utilisation data -> [String] -- ^ Exclusion tags - -> (Node.AssocList, - Instance.AssocList) -- ^ Data from either Text.loadData - -- or Rapi.loadData - -> Result (Node.List, Instance.List, String) -mergeData um extags (nl, il) = + -> (Node.AssocList, Instance.AssocList, [String]) + -- ^ Data from backends + -> Result (Node.List, Instance.List, [String], String) +mergeData um extags (nl, il, tags) = let il2 = Container.fromAssocList il il3 = foldl' (\im (name, n_util) -> case Container.findByName im name of @@ -163,7 +162,7 @@ mergeData um extags (nl, il) = csl = length common_suffix snl = Container.map (\n -> setName n (stripSuffix csl $ nameOf n)) nl3 sil = Container.map (\i -> setName i (stripSuffix csl $ nameOf i)) il4 - in Ok (snl, sil, common_suffix) + in Ok (snl, sil, tags, common_suffix) -- | Checks the cluster data for consistency. checkData :: Node.List -> Instance.List diff --git a/Ganeti/HTools/Luxi.hs b/Ganeti/HTools/Luxi.hs index c2e8bdb53..f60cce09a 100644 --- a/Ganeti/HTools/Luxi.hs +++ b/Ganeti/HTools/Luxi.hs @@ -144,7 +144,7 @@ parseNode v = fail ("Invalid node query result: " ++ show v) -- | Builds the cluster data from an URL. loadData :: String -- ^ Unix socket to use as source - -> IO (Result (Node.AssocList, Instance.AssocList)) + -> IO (Result (Node.AssocList, Instance.AssocList, [String])) loadData master = E.bracket (L.getClient master) @@ -157,5 +157,5 @@ loadData master = let (node_names, node_idx) = assignIndices node_data inst_data <- instances >>= getInstances node_names let (_, inst_idx) = assignIndices inst_data - return (node_idx, inst_idx) + return (node_idx, inst_idx, []) ) diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs index d8595725e..261b29095 100644 --- a/Ganeti/HTools/Rapi.hs +++ b/Ganeti/HTools/Rapi.hs @@ -114,7 +114,7 @@ parseNode a = do -- | Builds the cluster data from an URL. loadData :: String -- ^ Cluster or URL to use as source - -> IO (Result (Node.AssocList, Instance.AssocList)) + -> IO (Result (Node.AssocList, Instance.AssocList, [String])) loadData master = do -- IO monad let url = formatHost master node_body <- getUrl $ printf "%s/2/nodes?bulk=1" url @@ -124,4 +124,4 @@ loadData master = do -- IO monad let (node_names, node_idx) = assignIndices node_data inst_data <- inst_body >>= getInstances node_names let (_, inst_idx) = assignIndices inst_data - return (node_idx, inst_idx) + return (node_idx, inst_idx, []) diff --git a/Ganeti/HTools/Simu.hs b/Ganeti/HTools/Simu.hs index ee0e66a9d..d82216871 100644 --- a/Ganeti/HTools/Simu.hs +++ b/Ganeti/HTools/Simu.hs @@ -52,7 +52,7 @@ parseDesc desc = -- | Builds the cluster data from node\/instance files. loadData :: String -- ^ Cluster description in text format - -> IO (Result (Node.AssocList, Instance.AssocList)) + -> IO (Result (Node.AssocList, Instance.AssocList, [String])) loadData ndata = -- IO monad, just for consistency with the other loaders return $ do (cnt, disk, mem, cpu) <- parseDesc ndata @@ -63,4 +63,4 @@ loadData ndata = -- IO monad, just for consistency with the other loaders (fromIntegral cpu) False in (idx, Node.setIdx n idx) ) [1..cnt] - return (nodes, []) + return (nodes, [], []) diff --git a/Ganeti/HTools/Text.hs b/Ganeti/HTools/Text.hs index cd82aa812..efe8b48f1 100644 --- a/Ganeti/HTools/Text.hs +++ b/Ganeti/HTools/Text.hs @@ -91,7 +91,7 @@ loadTabular text_data convert_fn = do -- | Builds the cluster data from node\/instance files. loadData :: String -- ^ Node data in string format -> String -- ^ Instance data in string format - -> IO (Result (Node.AssocList, Instance.AssocList)) + -> IO (Result (Node.AssocList, Instance.AssocList, [String])) loadData nfile ifile = do -- IO monad ndata <- readFile nfile idata <- readFile ifile @@ -100,4 +100,4 @@ loadData nfile ifile = do -- IO monad (ktn, nl) <- loadTabular ndata loadNode {- instance file: name mem disk status pnode snode -} (_, il) <- loadTabular idata (loadInst ktn) - return (nl, il) + return (nl, il, []) diff --git a/hbal.hs b/hbal.hs index c2a58882b..51ca704c4 100644 --- a/hbal.hs +++ b/hbal.hs @@ -187,7 +187,7 @@ main = do verbose = optVerbose opts shownodes = optShowNodes opts - (fixed_nl, il, csf) <- loadExternalData opts + (fixed_nl, il, _, csf) <- loadExternalData opts let offline_names = optOffline opts all_nodes = Container.elems fixed_nl diff --git a/hscan.hs b/hscan.hs index 1d5ef9cb2..0469eaeed 100644 --- a/hscan.hs +++ b/hscan.hs @@ -142,7 +142,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 (isJust shownodes) $ diff --git a/hspace.hs b/hspace.hs index 3ee89ee13..018317de9 100644 --- a/hspace.hs +++ b/hspace.hs @@ -216,7 +216,7 @@ main = do ispec = optISpec opts shownodes = optShowNodes opts - (fixed_nl, il, csf) <- loadExternalData opts + (fixed_nl, il, _, csf) <- loadExternalData opts printKeys $ map (\(a, fn) -> ("SPEC_" ++ a, fn ispec)) specData printKeys [ ("SPEC_RQN", printf "%d" (optINodes opts)) ] -- GitLab