From: Helga Velroyen Date: Mon, 28 Jan 2013 16:06:37 +0000 (+0100) Subject: Add fields 'inst_cnt' and 'inst_list' to network queries X-Git-Tag: v2.8.0beta1~468 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/125df9a836d7a9facf9828459737490b99e32692 Add fields 'inst_cnt' and 'inst_list' to network queries This adds the fields 'inst_cnt' and 'inst_list' to the Haskell implementation of the network queries. Signed-off-by: Helga Velroyen Reviewed-by: Michele Tartara --- diff --git a/src/Ganeti/Query/Network.hs b/src/Ganeti/Query/Network.hs index 0101687..6ba0ce4 100644 --- a/src/Ganeti/Query/Network.hs +++ b/src/Ganeti/Query/Network.hs @@ -73,6 +73,12 @@ networkFields = , (FieldDefinition "group_cnt" "GroupCount" QFTOther "Number of node groups", FieldConfig (\cfg -> rsNormal . length . getGroupConnections cfg . networkUuid), QffNormal) + , (FieldDefinition "inst_list" "InstanceList" QFTOther "List of instances", + FieldConfig (\cfg -> rsNormal . getInstances cfg . networkUuid), + QffNormal) + , (FieldDefinition "inst_cnt" "InstanceCount" QFTOther "Number of instances", + FieldConfig (\cfg -> rsNormal . length . getInstances cfg + . networkUuid), QffNormal) ] ++ uuidFields "Network" ++ serialFields "Network" ++ @@ -116,3 +122,13 @@ getNicMode nic_params = getNicLink :: PartialNicParams -> String getNicLink nic_params = fromMaybe "-" (nicpLinkP nic_params) +-- | Retrieves the network's instances' names. +getInstances :: ConfigData -> String -> [String] +getInstances cfg network_uuid = + map instName (filter (instIsConnected network_uuid) + ((Map.elems . fromContainer . configInstances) cfg)) + +-- | Helper function that checks if an instance is linked to the given network. +instIsConnected :: String -> Instance -> Bool +instIsConnected network_uuid inst = + network_uuid `elem` map networkUuid (mapMaybe nicNetwork (instNics inst))