-
Notifications
You must be signed in to change notification settings - Fork 2
/
anomalies_by_node.go
179 lines (172 loc) · 7.09 KB
/
anomalies_by_node.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
package blueprint
import (
"context"
"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/attr"
dataSourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type anomalyNodeSummary struct {
NodeName types.String `tfsdk:"node_name"`
SystemId types.String `tfsdk:"system_id"`
Total types.Int64 `tfsdk:"total"`
Arp types.Int64 `tfsdk:"arp"`
Bgp types.Int64 `tfsdk:"bgp"`
BlueprintRendering types.Int64 `tfsdk:"blueprint_rendering"`
Cabling types.Int64 `tfsdk:"cabling"`
Config types.Int64 `tfsdk:"config"`
Counter types.Int64 `tfsdk:"counter"`
Deployment types.Int64 `tfsdk:"deployment"`
Hostname types.Int64 `tfsdk:"hostname"`
Interface types.Int64 `tfsdk:"interface"`
Lag types.Int64 `tfsdk:"lag"`
Liveness types.Int64 `tfsdk:"liveness"`
Mac types.Int64 `tfsdk:"mac"`
Mlag types.Int64 `tfsdk:"mlag"`
Probe types.Int64 `tfsdk:"probe"`
Route types.Int64 `tfsdk:"route"`
Series types.Int64 `tfsdk:"series"`
Streaming types.Int64 `tfsdk:"streaming"`
}
func (o anomalyNodeSummary) attrTypes() map[string]attr.Type {
return map[string]attr.Type{
"node_name": types.StringType,
"system_id": types.StringType,
"total": types.Int64Type,
"arp": types.Int64Type,
"bgp": types.Int64Type,
"blueprint_rendering": types.Int64Type,
"cabling": types.Int64Type,
"config": types.Int64Type,
"counter": types.Int64Type,
"deployment": types.Int64Type,
"hostname": types.Int64Type,
"interface": types.Int64Type,
"lag": types.Int64Type,
"liveness": types.Int64Type,
"mac": types.Int64Type,
"mlag": types.Int64Type,
"probe": types.Int64Type,
"route": types.Int64Type,
"series": types.Int64Type,
"streaming": types.Int64Type,
}
}
func (o anomalyNodeSummary) dataSourceAttributes() map[string]dataSourceSchema.Attribute {
return map[string]dataSourceSchema.Attribute{
"node_name": dataSourceSchema.StringAttribute{
MarkdownDescription: "Name of the Node experiencing Anomalies.",
Computed: true,
},
"system_id": dataSourceSchema.StringAttribute{
MarkdownDescription: "System ID of the Node experiencing Anomalies.",
Computed: true,
},
"total": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Total number of Anomalies related to the Node.",
Computed: true,
},
"arp": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of ARP Anomalies related to the Node.",
Computed: true,
},
"bgp": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of BGP Anomalies related to the Node.",
Computed: true,
},
"blueprint_rendering": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Blueprint Rendering Anomalies related to the Node.",
Computed: true,
},
"cabling": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Cabling Anomalies related to the Node.",
Computed: true,
},
"config": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Config Anomalies related to the Node.",
Computed: true,
},
"counter": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Counter Anomalies related to the Node.",
Computed: true,
},
"deployment": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Deployment Anomalies related to the Node.",
Computed: true,
},
"hostname": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Hostname Anomalies related to the Node.",
Computed: true,
},
"interface": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Interface Anomalies related to the Node.",
Computed: true,
},
"lag": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of LAG Anomalies related to the Node.",
Computed: true,
},
"liveness": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Liveness Anomalies related to the Node.",
Computed: true,
},
"mac": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of MAC Anomalies related to the Node.",
Computed: true,
},
"mlag": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of MLAG Anomalies related to the Node.",
Computed: true,
},
"probe": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Probe Anomalies related to the Node.",
Computed: true,
},
"route": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Route Anomalies related to the Node.",
Computed: true,
},
"series": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Series Anomalies related to the Node.",
Computed: true,
},
"streaming": dataSourceSchema.Int64Attribute{
MarkdownDescription: "Number of Streaming Anomalies related to the Node.",
Computed: true,
},
}
}
func (o *anomalyNodeSummary) loadApiData(_ context.Context, in *apstra.BlueprintNodeAnomalyCounts, _ *diag.Diagnostics) {
o.NodeName = types.StringValue(in.Node)
o.SystemId = types.StringValue(in.SystemId.String())
o.Total = types.Int64Value(int64(in.All))
o.Arp = types.Int64Value(int64(in.Arp))
o.Bgp = types.Int64Value(int64(in.Bgp))
o.BlueprintRendering = types.Int64Value(int64(in.BlueprintRendering))
o.Cabling = types.Int64Value(int64(in.Cabling))
o.Config = types.Int64Value(int64(in.Config))
o.Counter = types.Int64Value(int64(in.Counter))
o.Deployment = types.Int64Value(int64(in.Deployment))
o.Hostname = types.Int64Value(int64(in.Hostname))
o.Interface = types.Int64Value(int64(in.Interface))
o.Lag = types.Int64Value(int64(in.Lag))
o.Liveness = types.Int64Value(int64(in.Liveness))
o.Mac = types.Int64Value(int64(in.Mac))
o.Mlag = types.Int64Value(int64(in.Mlag))
o.Probe = types.Int64Value(int64(in.Probe))
o.Route = types.Int64Value(int64(in.Route))
o.Series = types.Int64Value(int64(in.Series))
o.Streaming = types.Int64Value(int64(in.Streaming))
}
func newAnomalyNodeSummarySet(ctx context.Context, in []apstra.BlueprintNodeAnomalyCounts, diags *diag.Diagnostics) types.Set {
nodeSummaries := make([]anomalyNodeSummary, len(in))
for i, nodeSummary := range in {
nodeSummaries[i].loadApiData(ctx, &nodeSummary, diags)
}
if diags.HasError() {
return types.SetNull(types.ObjectType{AttrTypes: anomalyNodeSummary{}.attrTypes()})
}
return utils.SetValueOrNull(ctx, types.ObjectType{AttrTypes: anomalyNodeSummary{}.attrTypes()}, nodeSummaries, diags)
}