From 2d3d843de3026f8facbcf3d482a91fffdd12fc83 Mon Sep 17 00:00:00 2001 From: Helga Velroyen <helgav@google.com> Date: Mon, 28 Jan 2013 16:06:57 +0100 Subject: [PATCH] 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: Helga Velroyen <helgav@google.com> Reviewed-by: Michele Tartara <mtartara@google.com> --- src/Ganeti/Config.hs | 32 -------------------------------- src/Ganeti/Query/Network.hs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Ganeti/Config.hs b/src/Ganeti/Config.hs index 359c2d4dd..18dce62b1 100644 --- a/src/Ganeti/Config.hs +++ b/src/Ganeti/Config.hs @@ -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 = diff --git a/src/Ganeti/Query/Network.hs b/src/Ganeti/Query/Network.hs index f7c6f0dbf..010168747 100644 --- a/src/Ganeti/Query/Network.hs +++ b/src/Ganeti/Query/Network.hs @@ -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) + -- GitLab