Skip to content

Commit

Permalink
datasource_network_utilization
Browse files Browse the repository at this point in the history
  • Loading branch information
AB3F3B8L committed Jan 8, 2025
1 parent 4916890 commit e021f30
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/data-sources/infoblox_ipv4_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/infoblox_ipv6_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
40 changes: 40 additions & 0 deletions infoblox/datasource_infoblox_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e021f30

Please sign in to comment.