Commit 86ea20e8 authored by Iustin Pop's avatar Iustin Pop
Browse files

Simplify the codeflow in hscan.hs



We change processData to just load the data, and return a simpler
type.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent c0e31451
...@@ -38,7 +38,6 @@ import Text.Printf (printf) ...@@ -38,7 +38,6 @@ import Text.Printf (printf)
import qualified Ganeti.HTools.Container as Container import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Cluster as Cluster import qualified Ganeti.HTools.Cluster as Cluster
import qualified Ganeti.HTools.Group as Group
import qualified Ganeti.HTools.Node as Node import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Instance as Instance import qualified Ganeti.HTools.Instance as Instance
#ifndef NO_CURL #ifndef NO_CURL
...@@ -89,26 +88,25 @@ fixSlash :: String -> String ...@@ -89,26 +88,25 @@ fixSlash :: String -> String
fixSlash = map (\x -> if x == '/' then '_' else x) fixSlash = map (\x -> if x == '/' then '_' else x)
-- | Generates serialized data from loader input -- | Generates serialized data from loader input.
processData :: Result ClusterData processData :: Result ClusterData -> Result ClusterData
-> Result (Group.List, Node.List, Instance.List, String)
processData input_data = do processData input_data = do
cdata@(ClusterData gl nl il _) <- input_data >>= mergeData [] [] [] cdata@(ClusterData _ nl il _) <- input_data >>= mergeData [] [] []
let (_, fix_nl) = checkData nl il let (_, fix_nl) = checkData nl il
adata = serializeCluster cdata return cdata { cdNodes = fix_nl }
return (gl, fix_nl, il, adata)
-- | Writes cluster data out -- | Writes cluster data out
writeData :: Int writeData :: Int
-> String -> String
-> Options -> Options
-> Result (Group.List, Node.List, Instance.List, String) -> Result ClusterData
-> IO Bool -> IO Bool
writeData _ name _ (Bad err) = writeData _ name _ (Bad err) =
printf "\nError for %s: failed to load data. Details:\n%s\n" name err >> printf "\nError for %s: failed to load data. Details:\n%s\n" name err >>
return False return False
writeData nlen name opts (Ok (_, nl, il, adata)) = do writeData nlen name opts (Ok cdata) = do
let (ClusterData _ nl il _) = cdata
printf "%-*s " nlen name :: IO () printf "%-*s " nlen name :: IO ()
hFlush stdout hFlush stdout
let shownodes = optShowNodes opts let shownodes = optShowNodes opts
...@@ -118,7 +116,7 @@ writeData nlen name opts (Ok (_, nl, il, adata)) = do ...@@ -118,7 +116,7 @@ writeData nlen name opts (Ok (_, nl, il, adata)) = do
hFlush stdout hFlush stdout
when (isJust shownodes) $ when (isJust shownodes) $
putStr $ Cluster.printNodes nl (fromJust shownodes) putStr $ Cluster.printNodes nl (fromJust shownodes)
writeFile (oname <.> "data") adata writeFile (oname <.> "data") (serializeCluster cdata)
return True return True
-- | Main function. -- | Main function.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment