From e021f30e2f1eb41edd7bb4ab4f82117089483b9c Mon Sep 17 00:00:00 2001 From: AB3F3B8L Date: Wed, 8 Jan 2025 17:49:15 +0100 Subject: [PATCH] datasource_network_utilization --- docs/data-sources/infoblox_ipv4_network.md | 1 + docs/data-sources/infoblox_ipv6_network.md | 3 +- infoblox/datasource_infoblox_network.go | 40 +++++++++++++++++++ .../v2/objects_generated.go | 3 ++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/data-sources/infoblox_ipv4_network.md b/docs/data-sources/infoblox_ipv4_network.md index eb8097d15..4d61ad96a 100644 --- a/docs/data-sources/infoblox_ipv4_network.md +++ b/docs/data-sources/infoblox_ipv4_network.md @@ -6,6 +6,7 @@ The data source for the network object allows you to get the following parameter * `cidr`: the network block which corresponds to the network, in CIDR notation. Example: `192.0.17.0/24` * `comment`: a description of the network. This is a regular comment. Example: `Untrusted network`. * `ext_attrs`: The set of extensible attributes, if any. The content is formatted as string of JSON map. Example: `"{\"Owner\":\"State Library\",\"Administrator\":\"unknown\"}"`. +* `gateway`: the gateway IP defined in network options (routers'). Example: `192.0.17.1` For usage of filters, add the fields as keys and appropriate values to be passed to the keys like `name`, `view` corresponding to object. diff --git a/docs/data-sources/infoblox_ipv6_network.md b/docs/data-sources/infoblox_ipv6_network.md index cb1253350..5bf245376 100644 --- a/docs/data-sources/infoblox_ipv6_network.md +++ b/docs/data-sources/infoblox_ipv6_network.md @@ -6,7 +6,8 @@ The data source for the network object allows you to get the following parameter * `cidr`: the network block which corresponds to the network, in CIDR notation. Example: `2002:1f93:0:4::/96` * `comment`: a description of the network. This is a regular comment. Example: `Untrusted network`. * `ext_attrs`: The set of extensible attributes, if any. The content is formatted as string of JSON map. Example: `"{\"Owner\":\"State Library\",\"Administrator\":\"unknown\"}"`. - +* `gateway`: the gateway IP defined in network options (routers'). Example: `192.0.17.1` +* `utilization`: The network utilization in percentage * 10. Example: `500` for `50%` of network utilization To retrieve information about IPv6 network that match the specified filters, use the `filters` argument and specify the parameters mentioned in the below table. These are the searchable parameters of the corresponding object in Infoblox NIOS WAPI. If you do not specify any parameter, the data source retrieves information about all host records in the NIOS Grid. diff --git a/infoblox/datasource_infoblox_network.go b/infoblox/datasource_infoblox_network.go index 6c52b87d6..c3308a63d 100644 --- a/infoblox/datasource_infoblox_network.go +++ b/infoblox/datasource_infoblox_network.go @@ -49,6 +49,16 @@ func dataSourceNetwork() *schema.Resource { Computed: true, Description: "The Extensible attributes for network datasource, as a map in JSON format", }, + "gateway": { + Type: schema.TypeString, + Optional: true, + Description: "The Gateway IP Address (identified using Options routers)", + }, + "utilization": { + Type: schema.TypeString, + Computed: true, + Description: "The network utilization in percentage", + }, }, }, }, @@ -63,6 +73,8 @@ func dataSourceIPv4NetworkRead(ctx context.Context, d *schema.ResourceData, m in n := &ibclient.Ipv4Network{} n.SetReturnFields(append(n.ReturnFields(), "extattrs")) + n.SetReturnFields(append(n.ReturnFields(), "options")) + n.SetReturnFields(append(n.ReturnFields(), "utilization")) filters := filterFromMap(d.Get("filters").(map[string]interface{})) qp := ibclient.NewQueryParams(false, filters) @@ -124,6 +136,19 @@ func flattenIpv4Network(network ibclient.Ipv4Network) (map[string]interface{}, e if network.Comment != nil { res["comment"] = *network.Comment } + + if network.Utilization != 0 { + res["utilization"] = fmt.Sprintf("%d", network.Utilization) + } + + if network.Options != nil { + for _, opt := range network.Options { + if opt.Name == "routers" { + res["gateway"] = opt.Value + break + } + } + } return res, nil } @@ -154,6 +179,19 @@ func flattenIpv6Network(network ibclient.Ipv6Network) (map[string]interface{}, e res["comment"] = *network.Comment } + if network.Utilization != 0 { + res["utilization"] = fmt.Sprintf("%d", &network.Utilization) + } + + if network.Options != nil { + for _, opt := range network.Options { + if opt.Name == "routers" { + res["gateway"] = opt.Value + break + } + } + } + return res, nil } @@ -164,6 +202,8 @@ func dataSourceIPv6NetworkRead(ctx context.Context, d *schema.ResourceData, m in n := &ibclient.Ipv6Network{} n.SetReturnFields(append(n.ReturnFields(), "extattrs")) + n.SetReturnFields(append(n.ReturnFields(), "options")) + n.SetReturnFields(append(n.ReturnFields(), "utilization")) filters := filterFromMap(d.Get("filters").(map[string]interface{})) qp := ibclient.NewQueryParams(false, filters) diff --git a/vendor/github.com/infobloxopen/infoblox-go-client/v2/objects_generated.go b/vendor/github.com/infobloxopen/infoblox-go-client/v2/objects_generated.go index 0bf69a4d7..58438438a 100644 --- a/vendor/github.com/infobloxopen/infoblox-go-client/v2/objects_generated.go +++ b/vendor/github.com/infobloxopen/infoblox-go-client/v2/objects_generated.go @@ -8054,6 +8054,9 @@ type Ipv6Network struct { // The list of zones associated with this network. ZoneAssociations []*Zoneassociation `json:"zone_associations,omitempty"` + + // The network utilization in percentage. + Utilization uint32 `json:"utilization,omitempty"` } func (Ipv6Network) ObjectType() string {