Commit 0fc8e521 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement lookup of partial names in Config.hs



This uses the recently-moved functions to implement partial lookup of
names on getNode and getInstance, similar to the Python codebase.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 2fc5653f
......@@ -81,17 +81,27 @@ getInstancesIpByLink :: LinkIpMap -> String -> [String]
getInstancesIpByLink linkipmap link =
M.keys $ M.findWithDefault M.empty link linkipmap
-- | Generic lookup function that converts from a possible abbreviated
-- name to a full name.
getItem :: String -> String -> M.Map String a -> Result a
getItem kind name allitems = do
let lresult = lookupName (M.keys allitems) name
err = \details -> Bad $ kind ++ " name " ++ name ++ " " ++ details
fullname <- case lrMatchPriority lresult of
PartialMatch -> Ok $ lrContent lresult
ExactMatch -> Ok $ lrContent lresult
MultipleMatch -> err "has multiple matches"
FailMatch -> err "not found"
maybe (err "not found after successfull match?!") Ok $
M.lookup fullname allitems
-- | Looks up a node.
getNode :: ConfigData -> String -> Result Node
getNode cfg name =
maybe (Bad $ "Node " ++ name ++ " not found") Ok $
M.lookup name (configNodes cfg)
getNode cfg name = getItem "Node" name (configNodes cfg)
-- | Looks up an instance.
getInstance :: ConfigData -> String -> Result Instance
getInstance cfg name =
maybe (Bad $ "Instance " ++ name ++ " not found") Ok $
M.lookup name (configInstances cfg)
getInstance cfg name = getItem "Instance" name (configInstances cfg)
-- | Looks up an instance's primary node.
getInstPrimaryNode :: ConfigData -> String -> Result Node
......
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