Commit 2d3d843d authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Moving network query helper functions to Network.hs



So far, a couple of helper function for the network
queries resided in Config.hs. I figured it makes more
sense to move them to Query/Network.hs, since they are
very tailored to that purpose.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent ae960018
......@@ -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
......@@ -225,36 +223,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 =
......
......@@ -29,13 +29,15 @@ module Ganeti.Query.Network
) where
import qualified Data.Map as Map
import Data.Maybe (fromMaybe, mapMaybe)
import Ganeti.Config
import Ganeti.JSON
import Ganeti.Network
import Ganeti.Objects
import Ganeti.Query.Language
import Ganeti.Query.Common
import Ganeti.Query.Types
import Ganeti.Types
data NetworkRuntime = NetworkRuntime
......@@ -83,3 +85,34 @@ networkFieldsMap =
-- TODO: the following fields are not implemented yet: external_reservations,
-- inst_cnt, inst_list
-- | 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)
((Map.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 Map.lookup network_uuid networks of
Nothing -> Nothing
Just net ->
Just (groupName group, getNicMode net, getNicLink net)
-- | 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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment