, getGroupOfNode
, getInstPrimaryNode
, getInstMinorsForNode
+ , getNetwork
, buildLinkIpInstnameMap
, instNodes
) where
instPrimaryNode inst `S.delete` instDiskNodes inst
-- | Get instances of a given node.
+-- The node is specified through its UUID.
getNodeInstances :: ConfigData -> String -> ([Instance], [Instance])
getNodeInstances cfg nname =
let all_inst = M.elems . fromContainer . configInstances $ cfg
maybe (err "not found after successfull match?!") Ok $
M.lookup fullname allitems
--- | Looks up a node.
+-- | Looks up a node by name or uuid.
getNode :: ConfigData -> String -> ErrorResult Node
-getNode cfg name = getItem "Node" name (fromContainer $ configNodes cfg)
+getNode cfg name =
+ let nodes = fromContainer (configNodes cfg)
+ in case getItem "Node" name nodes of
+ -- if not found by uuid, we need to look it up by name
+ Ok node -> Ok node
+ Bad _ -> let by_name = M.mapKeys
+ (nodeName . (M.!) nodes) nodes
+ in getItem "Node" name by_name
--- | Looks up an instance.
+-- | Looks up an instance by name or uuid.
getInstance :: ConfigData -> String -> ErrorResult Instance
getInstance cfg name =
- getItem "Instance" name (fromContainer $ configInstances cfg)
+ let instances = fromContainer (configInstances cfg)
+ in case getItem "Instance" name instances of
+ -- if not found by uuid, we need to look it up by name
+ Ok inst -> Ok inst
+ Bad _ -> let by_name = M.mapKeys
+ (instName . (M.!) instances) instances
+ in getItem "Instance" name by_name
--- | Looks up a node group. This is more tricky than for
--- node/instances since the groups map is indexed by uuid, not name.
+-- | Looks up a node group by name or uuid.
getGroup :: ConfigData -> String -> ErrorResult NodeGroup
getGroup cfg name =
let groups = fromContainer (configNodegroups cfg)
-- | Get (primary, secondary) instances of a given node group.
getGroupInstances :: ConfigData -> String -> ([Instance], [Instance])
getGroupInstances cfg gname =
- let gnodes = map nodeName (getGroupNodes cfg gname)
+ let gnodes = map nodeUuid (getGroupNodes cfg gname)
ginsts = map (getNodeInstances cfg) gnodes in
(concatMap fst ginsts, concatMap snd ginsts)
+-- | Looks up a network. If looking up by uuid fails, we look up
+-- by name.
+getNetwork :: ConfigData -> String -> ErrorResult Network
+getNetwork cfg name =
+ let networks = fromContainer (configNetworks cfg)
+ in case getItem "Network" name networks of
+ Ok net -> Ok net
+ Bad _ -> let by_name = M.mapKeys
+ (fromNonEmpty . networkName . (M.!) networks)
+ networks
+ in getItem "Network" name by_name
+
-- | Looks up an instance's primary node.
getInstPrimaryNode :: ConfigData -> String -> ErrorResult Node
getInstPrimaryNode cfg name =