Skip to content

Commit 9043777

Browse files
authored
added utilization and options field in network datasource (#489)
* added utilization and options field in network datasource * added options field in return fields
1 parent a373476 commit 9043777

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

docs/data-sources/infoblox_ipv4_network.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ The data source for the network object allows you to get the following parameter
66
* `cidr`: the network block which corresponds to the network, in CIDR notation. Example: `192.0.17.0/24`
77
* `comment`: a description of the network. This is a regular comment. Example: `Untrusted network`.
88
* `ext_attrs`: The set of extensible attributes, if any. The content is formatted as string of JSON map. Example: `"{\"Owner\":\"State Library\",\"Administrator\":\"unknown\"}"`.
9-
9+
* `options`: An array of DHCP option structs that lists the DHCP options associated with the object.
10+
```terraform
11+
options {
12+
name = "dhcp-lease-time"
13+
value = "43200"
14+
vendor_class = "DHCP"
15+
num = 51
16+
use_option = true
17+
}
18+
```
19+
* `utilization`: The network utilization in percentage. Example: `0`
1020

1121
For usage of filters, add the fields as keys and appropriate values to be passed to the keys like `name`, `view` corresponding to object.
1222
From the below list of supported arguments for filters, use only the searchable fields for retriving the matching records.

infoblox/datasource_infoblox_network.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,50 @@ func dataSourceNetwork() *schema.Resource {
4949
Computed: true,
5050
Description: "The Extensible attributes for network datasource, as a map in JSON format",
5151
},
52+
"utilization": {
53+
Type: schema.TypeInt,
54+
Computed: true,
55+
Description: "The utilization of the network",
56+
},
57+
"options": {
58+
Type: schema.TypeList,
59+
Computed: true,
60+
Description: "An array of DHCP option structs that lists the DHCP options associated with the object. An option sets the" +
61+
"value of a DHCP option that has been defined in an option space. DHCP options describe network configuration settings" +
62+
"and various services available on the network. These options occur as variable-length fields at the end of DHCP messages." +
63+
"When defining a DHCP option, at least a ‘name’ or a ‘num’ is required.",
64+
Elem: &schema.Resource{
65+
Schema: map[string]*schema.Schema{
66+
"name": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "Name of the DHCP option.",
70+
},
71+
"num": {
72+
Type: schema.TypeInt,
73+
Computed: true,
74+
Description: "The code of the DHCP option.",
75+
},
76+
"use_option": {
77+
Type: schema.TypeBool,
78+
Computed: true,
79+
Description: "Only applies to special options that are displayed separately from other options and have a use flag. " +
80+
"These options are: `routers`, `router-templates`, `domain-name-servers`, `domain-name`, `broadcast-address`, " +
81+
"`broadcast-address-offset`, `dhcp-lease-time`, `dhcp6.name-servers`",
82+
},
83+
"value": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Description: "Value of the DHCP option.",
87+
},
88+
"vendor_class": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Description: "The name of the space this DHCP option is associated to.",
92+
},
93+
},
94+
},
95+
},
5296
},
5397
},
5498
},
@@ -62,7 +106,7 @@ func dataSourceIPv4NetworkRead(ctx context.Context, d *schema.ResourceData, m in
62106
var diags diag.Diagnostics
63107

64108
n := &ibclient.Ipv4Network{}
65-
n.SetReturnFields(append(n.ReturnFields(), "extattrs"))
109+
n.SetReturnFields(append(n.ReturnFields(), "extattrs", "options", "utilization"))
66110

67111
filters := filterFromMap(d.Get("filters").(map[string]interface{}))
68112
qp := ibclient.NewQueryParams(false, filters)
@@ -115,6 +159,7 @@ func flattenIpv4Network(network ibclient.Ipv4Network) (map[string]interface{}, e
115159
"id": network.Ref,
116160
"network_view": network.NetworkView,
117161
"ext_attrs": string(ea),
162+
"utilization": network.Utilization,
118163
}
119164

120165
if network.Network != nil {
@@ -125,6 +170,9 @@ func flattenIpv4Network(network ibclient.Ipv4Network) (map[string]interface{}, e
125170
res["comment"] = *network.Comment
126171
}
127172

173+
if network.Options != nil {
174+
res["options"] = convertDhcpOptionsToInterface(network.Options)
175+
}
128176
return res, nil
129177
}
130178

@@ -154,6 +202,9 @@ func flattenIpv6Network(network ibclient.Ipv6Network) (map[string]interface{}, e
154202
res["comment"] = *network.Comment
155203
}
156204

205+
if network.Options != nil {
206+
res["options"] = convertDhcpOptionsToInterface(network.Options)
207+
}
157208
return res, nil
158209
}
159210

@@ -163,7 +214,7 @@ func dataSourceIPv6NetworkRead(ctx context.Context, d *schema.ResourceData, m in
163214
var diags diag.Diagnostics
164215

165216
n := &ibclient.Ipv6Network{}
166-
n.SetReturnFields(append(n.ReturnFields(), "extattrs"))
217+
n.SetReturnFields(append(n.ReturnFields(), "extattrs", "options"))
167218

168219
filters := filterFromMap(d.Get("filters").(map[string]interface{}))
169220
qp := ibclient.NewQueryParams(false, filters)

0 commit comments

Comments
 (0)