Revision 2d3d843d src/Ganeti/Config.hs

b/src/Ganeti/Config.hs
42 42
    , getGroupNodes
43 43
    , getGroupInstances
44 44
    , getGroupOfNode
45
    , getGroupConnections
46 45
    , getInstPrimaryNode
47 46
    , getInstMinorsForNode
48 47
    , getNetwork
......
52 51

  
53 52
import Control.Monad (liftM)
54 53
import Data.List (foldl')
55
import Data.Maybe (fromMaybe, mapMaybe)
56 54
import qualified Data.Map as M
57 55
import qualified Data.Set as S
58 56
import qualified Text.JSON as J
......
225 223
                              networks
226 224
                in getItem "Network" name by_name
227 225

  
228
-- | Given a network's UUID, this function lists all connections from
229
-- the network to nodegroups including the respective mode and links.
230
getGroupConnections :: ConfigData -> String -> [(String, String, String)]
231
getGroupConnections cfg network_uuid =
232
  mapMaybe (getGroupConnection network_uuid)
233
  ((M.elems . fromContainer . configNodegroups) cfg)
234

  
235
-- | Given a network's UUID and a node group, this function assembles
236
-- a tuple of the group's name, the mode and the link by which the
237
-- network is connected to the group. Returns 'Nothing' if the network
238
-- is not connected to the group.
239
getGroupConnection :: String -> NodeGroup -> Maybe (String, String, String)
240
getGroupConnection network_uuid group =
241
  let networks = fromContainer . groupNetworks $ group
242
  in case M.lookup network_uuid networks of
243
    Nothing -> Nothing
244
    Just network ->
245
      Just (groupName group, getNicMode network, getNicLink network)
246

  
247
-- | Retrieves the network's mode and formats it human-readable,
248
-- also in case it is not available.
249
getNicMode :: PartialNicParams -> String
250
getNicMode nic_params =
251
  maybe "-" nICModeToRaw $ nicpModeP nic_params
252

  
253
-- | Retrieves the network's link and formats it human-readable, also in
254
-- case it it not available.
255
getNicLink :: PartialNicParams -> String
256
getNicLink nic_params = fromMaybe "-" (nicpLinkP nic_params)
257

  
258 226
-- | Looks up an instance's primary node.
259 227
getInstPrimaryNode :: ConfigData -> String -> ErrorResult Node
260 228
getInstPrimaryNode cfg name =

Also available in: Unified diff