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
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 =
{-| 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
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
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)
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
{- 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)