Correct properties of the cluster's file storage dir
[ganeti-local] / src / Ganeti / Config.hs
index 359c2d4..9eb016d 100644 (file)
@@ -42,7 +42,6 @@ module Ganeti.Config
     , getGroupNodes
     , getGroupInstances
     , getGroupOfNode
-    , getGroupConnections
     , getInstPrimaryNode
     , getInstMinorsForNode
     , getNetwork
@@ -52,7 +51,6 @@ module Ganeti.Config
 
 import Control.Monad (liftM)
 import Data.List (foldl')
-import Data.Maybe (fromMaybe, mapMaybe)
 import qualified Data.Map as M
 import qualified Data.Set as S
 import qualified Text.JSON as J
@@ -110,6 +108,7 @@ instSecondaryNodes inst =
   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
@@ -162,17 +161,29 @@ getItem kind name allitems = do
   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)
@@ -209,7 +220,7 @@ getGroupNodes cfg gname =
 -- | 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)
 
@@ -225,36 +236,6 @@ getNetwork cfg name =
                               networks
                 in getItem "Network" name by_name
 
--- | Given a network's UUID, this function lists all connections from
--- the network to nodegroups including the respective mode and links.
-getGroupConnections :: ConfigData -> String -> [(String, String, String)]
-getGroupConnections cfg network_uuid =
-  mapMaybe (getGroupConnection network_uuid)
-  ((M.elems . fromContainer . configNodegroups) cfg)
-
--- | Given a network's UUID and a node group, this function assembles
--- a tuple of the group's name, the mode and the link by which the
--- network is connected to the group. Returns 'Nothing' if the network
--- is not connected to the group.
-getGroupConnection :: String -> NodeGroup -> Maybe (String, String, String)
-getGroupConnection network_uuid group =
-  let networks = fromContainer . groupNetworks $ group
-  in case M.lookup network_uuid networks of
-    Nothing -> Nothing
-    Just network ->
-      Just (groupName group, getNicMode network, getNicLink network)
-
--- | Retrieves the network's mode and formats it human-readable,
--- also in case it is not available.
-getNicMode :: PartialNicParams -> String
-getNicMode nic_params =
-  maybe "-" nICModeToRaw $ nicpModeP nic_params
-
--- | Retrieves the network's link and formats it human-readable, also in
--- case it it not available.
-getNicLink :: PartialNicParams -> String
-getNicLink nic_params = fromMaybe "-" (nicpLinkP nic_params)
-
 -- | Looks up an instance's primary node.
 getInstPrimaryNode :: ConfigData -> String -> ErrorResult Node
 getInstPrimaryNode cfg name =