Revision 2d3d843d src/Ganeti/Query/Network.hs
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