Remove ktn/kti from first half of loader
authorIustin Pop <iustin@google.com>
Sat, 23 May 2009 23:43:38 +0000 (00:43 +0100)
committerIustin Pop <iustin@google.com>
Sat, 23 May 2009 23:43:38 +0000 (00:43 +0100)
This patch removes the ktn/kti lists from most parts of the first half
of the loading sequence. Some remain as the [(String, Int)] is the
nicest way to lookup names and get indices back.

Ganeti/HTools/IAlloc.hs
Ganeti/HTools/Loader.hs
Ganeti/HTools/Rapi.hs
Ganeti/HTools/Text.hs

index 0ead96f..674ef82 100644 (file)
@@ -101,7 +101,7 @@ parseData body = do
               ridx <- lookupNode kti rname rname
               return $ Relocate ridx
         other -> fail $ ("Invalid request type '" ++ other ++ "'")
-  (map_n, map_i, csf) <- mergeData (ktn, nl, kti, il)
+  (map_n, map_i, csf) <- mergeData (nl, il)
   return $ Request rqtype map_n map_i csf
 
 formatResponse :: Bool -> String -> [String] -> String
index b7dd606..2245f73 100644 (file)
@@ -21,11 +21,6 @@ import qualified Ganeti.HTools.Node as Node
 
 import Ganeti.HTools.Types
 
-
--- | Swap a list of @(a, b)@ into @(b, a)@
-swapPairs :: [(a, b)] -> [(b, a)]
-swapPairs = map (\ (a, b) -> (b, a))
-
 -- | Lookups a node into an assoc list
 lookupNode :: (Monad m) => NameAssoc -> String -> String -> m Int
 lookupNode ktn inst node =
@@ -82,12 +77,11 @@ stripSuffix sflen name = take ((length name) - sflen) name
 
 {-| Initializer function that loads the data from a node and list file
     and massages it into the correct format. -}
-mergeData :: ([(String, Int)], Node.AssocList,
-              [(String, Int)], Instance.AssocList) -- ^ Data from either
-                                                   -- Text.loadData
-                                                   -- or Rapi.loadData
+mergeData :: (Node.AssocList,
+              Instance.AssocList) -- ^ Data from either Text.loadData
+                                  -- or Rapi.loadData
           -> Result (NodeList, InstanceList, String)
-mergeData (ktn, nl, kti, il) = do
+mergeData (nl, il) = do
   let
       nl2 = fixNodes nl il
       il3 = Container.fromAssocList il
index ac0ff44..4f3b89b 100644 (file)
@@ -84,8 +84,7 @@ parseNode a = do
     return (name, node)
 
 loadData :: String -- ^ Cluster/URL to use as source
-         -> IO (Result (NameAssoc, Node.AssocList,
-                        NameAssoc, Instance.AssocList))
+         -> IO (Result (Node.AssocList, Instance.AssocList))
 loadData master = do -- IO monad
   let url = formatHost master
   node_body <- getUrl $ printf "%s/2/nodes?bulk=1" url
@@ -94,5 +93,5 @@ loadData master = do -- IO monad
     node_data <- node_body >>= getNodes
     let (node_names, node_idx) = assignIndices node_data
     inst_data <- inst_body >>= getInstances node_names
-    let (inst_names, inst_idx) = assignIndices inst_data
-    return (node_names, node_idx, inst_names, inst_idx)
+    let (_, inst_idx) = assignIndices inst_data
+    return (node_idx, inst_idx)
index 7c85db3..fdf1982 100644 (file)
@@ -75,8 +75,7 @@ loadTabular text_data convert_fn = do
 
 loadData :: String -- ^ Node data in string format
          -> String -- ^ Instance data in string format
-         -> IO (Result (NameAssoc, Node.AssocList,
-                        NameAssoc, Instance.AssocList))
+         -> IO (Result (Node.AssocList, Instance.AssocList))
 loadData nfile ifile = do -- IO monad
   ndata <- readFile nfile
   idata <- readFile ifile
@@ -84,5 +83,5 @@ loadData nfile ifile = do -- IO monad
     {- node file: name t_mem n_mem f_mem t_disk f_disk -}
     (ktn, nl) <- loadTabular ndata loadNode
     {- instance file: name mem disk status pnode snode -}
-    (kti, il) <- loadTabular idata (loadInst ktn)
-    return (ktn, nl, kti, il)
+    (_, il) <- loadTabular idata (loadInst ktn)
+    return (nl, il)