-
Notifications
You must be signed in to change notification settings - Fork 4
/
datasource_port_device_info.go
276 lines (272 loc) · 8.5 KB
/
datasource_port_device_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package provider
import (
"context"
"github.com/PacketFabric/terraform-provider-packetfabric/internal/packetfabric"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func dataSourcePortDeviceInfo() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourcePortDeviceInfoRead,
Schema: map[string]*schema.Schema{
"port_circuit_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The port circuit ID.",
},
"adjacent_router": {
Type: schema.TypeString,
Computed: true,
Description: "The adjcent router.",
},
"device_name": {
Type: schema.TypeString,
Computed: true,
Description: "The device name.",
},
"device_make": {
Type: schema.TypeString,
Computed: true,
Description: "The device make name.",
},
"admin_status": {
Type: schema.TypeString,
Computed: true,
Description: "The current admin status.",
},
"oper_status": {
Type: schema.TypeString,
Computed: true,
Description: "The current oerational status.",
},
"auto_negotiation": {
Type: schema.TypeBool,
Computed: true,
Description: "True if auto negotiation is on.",
},
"iface_name": {
Type: schema.TypeString,
Computed: true,
Description: "The interface name.",
},
"speed": {
Type: schema.TypeString,
Computed: true,
Description: "The port speed.",
},
"optics_diagnostics_lane_tx_power_dbm": {
Type: schema.TypeFloat,
Computed: true,
Description: "The optics diagnostics lane TX Power dbm.",
},
"optics_diagnostics_lane_tx_power": {
Type: schema.TypeFloat,
Computed: true,
Description: "The optics diagnostics lane TX Power.",
},
"optics_diagnostics_lane_index": {
Type: schema.TypeString,
Computed: true,
Description: "The optics diagnostics lane Index.",
},
"optics_diagnostics_lane_rx_power_dbm": {
Type: schema.TypeFloat,
Computed: true,
Description: "The optics diagnostics lane RX Power dbm.",
},
"optics_diagnostics_lane_rx_power": {
Type: schema.TypeFloat,
Computed: true,
Description: "The optics diagnostics lane RX Power.",
},
"optics_diagnostics_lane_bias_current": {
Type: schema.TypeFloat,
Computed: true,
Description: "The optics diagnostics lane bias current.",
},
"optics_diagnostics_lane_tx_status": {
Type: schema.TypeString,
Computed: true,
Description: "The optics diagnostics lane tx status.",
},
"optics_diagnostics_lane_rx_status": {
Type: schema.TypeString,
Computed: true,
Description: "The optics diagnostics lane rx status.",
},
"polltime": {
Type: schema.TypeInt,
Computed: true,
Description: "The port pool time.",
},
"time_flapped": {
Type: schema.TypeString,
Computed: true,
Description: "The port time flapped.",
},
"traffic_rx_bps": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic RX bps.",
},
"traffic_rx_bytes": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic RX bytes.",
},
"traffic_rx_ipv6_bytes": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic RX IPv6 bytes.",
},
"traffic_rx_ipv6_packets": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic RX IPv6 packets.",
},
"traffic_rx_packets": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic RX packets.",
},
"traffic_rx_pps": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic RX pps.",
},
"traffic_tx_bps": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic TX bps.",
},
"traffic_tx_bytes": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic TX bytes.",
},
"traffic_tx_ipv6_bytes": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic TX IPv6 bytes.",
},
"traffic_tx_ipv6_packets": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic TX IPv6 packets.",
},
"traffic_tx_packets": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic TX bytes.",
},
"traffic_tx_pps": {
Type: schema.TypeInt,
Computed: true,
Description: "The port traffic TX pps.",
},
"wiring_media": {
Type: schema.TypeString,
Computed: true,
Description: "The port wiring media.",
},
"wiring_module": {
Type: schema.TypeString,
Computed: true,
Description: "The port wiring module.",
},
"wiring_panel": {
Type: schema.TypeString,
Computed: true,
Description: "The port wiring panel.",
},
"wiring_position": {
Type: schema.TypeString,
Computed: true,
Description: "The port wiring position.",
},
"wiring_reach": {
Type: schema.TypeString,
Computed: true,
Description: "The port wiring reach.",
},
"wiring_type": {
Type: schema.TypeString,
Computed: true,
Description: "The port wiring type.",
},
"lag_speed": {
Type: schema.TypeInt,
Computed: true,
Description: "The port lag speed.",
},
"device_can_lag": {
Type: schema.TypeBool,
Computed: true,
Description: "True if device can lag.",
},
},
}
}
func dataSourcePortDeviceInfoRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*packetfabric.PFClient)
c.Ctx = ctx
var diags diag.Diagnostics
portCID, ok := d.GetOk("port_circuit_id")
if !ok {
return diag.Errorf("please provide a valid port circuti ID")
}
portInfo, err := c.GetPortDeviceInfo(portCID.(string))
if err != nil {
return diag.FromErr(err)
}
if portInfo != nil {
if portInfo.AdjacentRouter != nil {
_ = d.Set("adjacent_router", portInfo.AdjacentRouter)
}
_ = d.Set("device_name", portInfo.DeviceName)
_ = d.Set("device_make", portInfo.DeviceMake)
_ = d.Set("admin_status", portInfo.AdminStatus)
_ = d.Set("oper_status", portInfo.OperStatus)
_ = d.Set("auto_negotiation", portInfo.AutoNegotiation)
_ = d.Set("iface_name", portInfo.IfaceName)
_ = d.Set("speed", portInfo.Speed)
for _, optics := range portInfo.OpticsDiagnosticsLaneValues {
_ = d.Set("optics_diagnostics_lane_tx_power_dbm", optics.TxPowerDbm)
_ = d.Set("optics_diagnostics_lane_tx_power", optics.TxPower)
_ = d.Set("optics_diagnostics_lane_index", optics.LaneIndex)
_ = d.Set("optics_diagnostics_lane_rx_power_dbm", optics.RxPowerDbm)
_ = d.Set("optics_diagnostics_lane_rx_power", optics.RxPower)
_ = d.Set("optics_diagnostics_lane_bias_current", optics.BiasCurrent)
_ = d.Set("optics_diagnostics_lane_tx_status", optics.TxStatus)
_ = d.Set("optics_diagnostics_lane_rx_status", optics.RxStatus)
}
if portInfo.Polltime != nil {
_ = d.Set("polltime", portInfo.Polltime)
}
_ = d.Set("time_flapped", portInfo.TimeFlapped)
_ = d.Set("traffic_rx_bps", portInfo.TrafficRxBps)
_ = d.Set("traffic_rx_bytes", portInfo.TrafficRxBytes)
_ = d.Set("traffic_rx_ipv6_bytes", portInfo.TrafficRxIpv6Bytes)
_ = d.Set("traffic_rx_ipv6_packets", portInfo.TrafficRxIpv6Packets)
_ = d.Set("traffic_rx_packets", portInfo.TrafficRxPackets)
_ = d.Set("traffic_rx_pps", portInfo.TrafficRxPps)
_ = d.Set("traffic_tx_bps", portInfo.TrafficTxBps)
_ = d.Set("traffic_tx_bytes", portInfo.TrafficTxBytes)
_ = d.Set("traffic_tx_ipv6_bytes", portInfo.TrafficTxIpv6Bytes)
_ = d.Set("traffic_tx_ipv6_packets", portInfo.TrafficTxIpv6Packets)
_ = d.Set("traffic_tx_packets", portInfo.TrafficTxPackets)
_ = d.Set("traffic_tx_pps", portInfo.TrafficTxPps)
_ = d.Set("wiring_media", portInfo.WiringMedia)
_ = d.Set("wiring_module", portInfo.WiringModule)
_ = d.Set("wiring_panel", portInfo.WiringPanel)
_ = d.Set("wiring_position", portInfo.WiringPosition)
_ = d.Set("wiring_reach", portInfo.WiringReach)
_ = d.Set("wiring_type", portInfo.WiringType)
_ = d.Set("lag_speed", portInfo.LagSpeed)
_ = d.Set("device_can_lag", portInfo.DeviceCanLag)
}
d.SetId(portCID.(string))
return diags
}