Commit 6ff78049 authored by Iustin Pop's avatar Iustin Pop
Browse files

Convert some leftovers to NameAssoc



The type alias NameAssoc has been introduced a long time ago, but there
are some few not-yet-converted cases. In preparation for changes to that
type, let's make sure we use it consistently.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 646aa028
......@@ -7,7 +7,7 @@ has been loaded from external sources.
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009, 2010 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -76,14 +76,14 @@ data Request = Request RqType Node.List Instance.List [String]
-- * Functions
-- | Lookups a node into an assoc list.
lookupNode :: (Monad m) => [(String, Ndx)] -> String -> String -> m Ndx
lookupNode :: (Monad m) => NameAssoc -> String -> String -> m Ndx
lookupNode ktn inst node =
case lookup node ktn of
Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ inst
Just idx -> return idx
-- | Lookups an instance into an assoc list.
lookupInstance :: (Monad m) => [(String, Idx)] -> String -> m Idx
lookupInstance :: (Monad m) => NameAssoc -> String -> m Idx
lookupInstance kti inst =
case lookup inst kti of
Nothing -> fail $ "Unknown instance '" ++ inst ++ "'"
......
......@@ -85,7 +85,7 @@ getInstances :: NameAssoc
getInstances ktn arr = toArray arr >>= mapM (parseInstance ktn)
-- | Construct an instance from a JSON object.
parseInstance :: [(String, Ndx)]
parseInstance :: NameAssoc
-> JSValue
-> Result (String, Instance.Instance)
parseInstance ktn (JSArray [ name, disk, mem, vcpus
......
......@@ -4,7 +4,7 @@
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009, 2010 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -75,7 +75,7 @@ getNodes body = loadJSArray "Parsing node data" body >>=
mapM (parseNode . fromJSObject)
-- | Construct an instance from a JSON object.
parseInstance :: [(String, Ndx)]
parseInstance :: NameAssoc
-> [(String, JSValue)]
-> Result (String, Instance.Instance)
parseInstance ktn a = do
......
......@@ -113,7 +113,7 @@ loadNode s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
-- | Load an instance from a field list.
loadInst :: (Monad m) =>
[(String, Ndx)] -> [String] -> m (String, Instance.Instance)
NameAssoc -> [String] -> m (String, Instance.Instance)
loadInst ktn [name, mem, dsk, vcpus, status, pnode, snode, tags] = do
pidx <- lookupNode ktn name pnode
sidx <- (if null snode then return Node.noSecondary
......@@ -135,7 +135,7 @@ loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'"
-- a supplied conversion function.
loadTabular :: (Monad m, Element a) =>
[String] -> ([String] -> m (String, a))
-> m ([(String, Int)], [(Int, a)])
-> m (NameAssoc, [(Int, a)])
loadTabular lines_data convert_fn = do
let rows = map (sepSplit '|') lines_data
kerows <- mapM convert_fn rows
......
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