Revision 2d3d843d

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 =
b/src/Ganeti/Query/Network.hs
29 29
  ) where
30 30

  
31 31
import qualified Data.Map as Map
32
import Data.Maybe (fromMaybe, mapMaybe)
32 33

  
33
import Ganeti.Config
34
import Ganeti.JSON
34 35
import Ganeti.Network
35 36
import Ganeti.Objects
36 37
import Ganeti.Query.Language
37 38
import Ganeti.Query.Common
38 39
import Ganeti.Query.Types
40
import Ganeti.Types
39 41

  
40 42
data NetworkRuntime = NetworkRuntime
41 43

  
......
83 85

  
84 86
-- TODO: the following fields are not implemented yet: external_reservations,
85 87
-- inst_cnt, inst_list
88

  
89
-- | Given a network's UUID, this function lists all connections from
90
-- the network to nodegroups including the respective mode and links.
91
getGroupConnections :: ConfigData -> String -> [(String, String, String)]
92
getGroupConnections cfg network_uuid =
93
  mapMaybe (getGroupConnection network_uuid)
94
  ((Map.elems . fromContainer . configNodegroups) cfg)
95

  
96
-- | Given a network's UUID and a node group, this function assembles
97
-- a tuple of the group's name, the mode and the link by which the
98
-- network is connected to the group. Returns 'Nothing' if the network
99
-- is not connected to the group.
100
getGroupConnection :: String -> NodeGroup -> Maybe (String, String, String)
101
getGroupConnection network_uuid group =
102
  let networks = fromContainer . groupNetworks $ group
103
  in case Map.lookup network_uuid networks of
104
    Nothing -> Nothing
105
    Just net ->
106
      Just (groupName group, getNicMode net, getNicLink net)
107

  
108
-- | Retrieves the network's mode and formats it human-readable,
109
-- also in case it is not available.
110
getNicMode :: PartialNicParams -> String
111
getNicMode nic_params =
112
  maybe "-" nICModeToRaw $ nicpModeP nic_params
113

  
114
-- | Retrieves the network's link and formats it human-readable, also in
115
-- case it it not available.
116
getNicLink :: PartialNicParams -> String
117
getNicLink nic_params = fromMaybe "-" (nicpLinkP nic_params)
118

  

Also available in: Unified diff