From ae960018ae45eedcae140b639fe0ad7a27e4d047 Mon Sep 17 00:00:00 2001
From: Helga Velroyen <helgav@google.com>
Date: Fri, 25 Jan 2013 14:36:10 +0100
Subject: [PATCH] More fields for network queries

This adds more fields to the network queries:
- group_cnt, free_count, reserved_count, and map

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 src/Ganeti/Query/Network.hs | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/Ganeti/Query/Network.hs b/src/Ganeti/Query/Network.hs
index 07241553f..f7c6f0dbf 100644
--- a/src/Ganeti/Query/Network.hs
+++ b/src/Ganeti/Query/Network.hs
@@ -31,6 +31,7 @@ module Ganeti.Query.Network
 import qualified Data.Map as Map
 
 import Ganeti.Config
+import Ganeti.Network
 import Ganeti.Objects
 import Ganeti.Query.Language
 import Ganeti.Query.Common
@@ -54,9 +55,22 @@ networkFields =
      FieldSimple (rsMaybeUnavail . networkMacPrefix), QffNormal)
   , (FieldDefinition "network_type" "NetworkType" QFTOther "Network type",
      FieldSimple (rsMaybeUnavail . networkNetworkType), QffNormal)
+  , (FieldDefinition "free_count" "FreeCount" QFTOther "Number of free IPs",
+     FieldSimple (rsMaybeNoData . fmap getFreeCount . createAddressPool),
+     QffNormal)
+  , (FieldDefinition "map" "Map" QFTText "Map of the network's reserved IPs",
+     FieldSimple (rsMaybeNoData . fmap getMap . createAddressPool),
+     QffNormal)
+  , (FieldDefinition "reserved_count" "ReservedCount" QFTOther
+       "Number of reserved IPs",
+     FieldSimple (rsMaybeNoData . fmap getReservedCount . createAddressPool),
+     QffNormal)
   , (FieldDefinition "group_list" "GroupList" QFTOther "List of node groups",
      FieldConfig (\cfg -> rsNormal . getGroupConnections cfg . networkUuid),
-       QffNormal)
+     QffNormal)
+  , (FieldDefinition "group_cnt" "GroupCount" QFTOther "Number of node groups",
+     FieldConfig (\cfg -> rsNormal . length . getGroupConnections cfg
+       . networkUuid), QffNormal)
   ] ++
   uuidFields "Network" ++
   serialFields "Network" ++
@@ -68,5 +82,4 @@ networkFieldsMap =
   Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) networkFields
 
 -- TODO: the following fields are not implemented yet: external_reservations,
--- free_count, group_cnt, inst_cnt, inst_list, map, reserved_count, serial_no,
--- tags, uuid
+-- inst_cnt, inst_list
-- 
GitLab