/
resource_snmp_server_SNMPv1_v2c_user_oid.go
205 lines (191 loc) · 6.75 KB
/
resource_snmp_server_SNMPv1_v2c_user_oid.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
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceSnmpServerSnmpv1V2cUserOid() *schema.Resource {
return &schema.Resource{
Description: "`thunder_snmp_server_SNMPv1_v2c_user_oid`: Define a remote entity to which user belongs\n\n__PLACEHOLDER__",
CreateContext: resourceSnmpServerSnmpv1V2cUserOidCreate,
UpdateContext: resourceSnmpServerSnmpv1V2cUserOidUpdate,
ReadContext: resourceSnmpServerSnmpv1V2cUserOidRead,
DeleteContext: resourceSnmpServerSnmpv1V2cUserOidDelete,
Schema: map[string]*schema.Schema{
"oid_val": {
Type: schema.TypeString, Required: true, Description: "specific the oid (The oid value, object-key)",
},
"remote": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"host_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_host": {
Type: schema.TypeString, Optional: true, Description: "DNS remote host",
},
"ipv4_mask": {
Type: schema.TypeString, Optional: true, Description: "IPV4 mask",
},
},
},
},
"ipv4_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ipv4_host": {
Type: schema.TypeString, Optional: true, Description: "IPV4 remote host",
},
"ipv4_mask": {
Type: schema.TypeString, Optional: true, Description: "IPV4 mask",
},
},
},
},
"ipv6_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ipv6_host": {
Type: schema.TypeString, Optional: true, Description: "IPV6 remote host",
},
"ipv6_mask": {
Type: schema.TypeInt, Optional: true, Description: "IPV6 mask",
},
},
},
},
},
},
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"user": {
Type: schema.TypeString, Required: true, Description: "User",
},
},
}
}
func resourceSnmpServerSnmpv1V2cUserOidCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceSnmpServerSnmpv1V2cUserOidCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointSnmpServerSnmpv1V2cUserOid(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceSnmpServerSnmpv1V2cUserOidRead(ctx, d, meta)
}
return diags
}
func resourceSnmpServerSnmpv1V2cUserOidUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceSnmpServerSnmpv1V2cUserOidUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointSnmpServerSnmpv1V2cUserOid(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceSnmpServerSnmpv1V2cUserOidRead(ctx, d, meta)
}
return diags
}
func resourceSnmpServerSnmpv1V2cUserOidDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceSnmpServerSnmpv1V2cUserOidDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointSnmpServerSnmpv1V2cUserOid(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceSnmpServerSnmpv1V2cUserOidRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceSnmpServerSnmpv1V2cUserOidRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointSnmpServerSnmpv1V2cUserOid(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getObjectSnmpServerSnmpv1V2cUserOidRemote(d []interface{}) edpt.SnmpServerSnmpv1V2cUserOidRemote {
count1 := len(d)
var ret edpt.SnmpServerSnmpv1V2cUserOidRemote
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.HostList = getSliceSnmpServerSnmpv1V2cUserOidRemoteHostList(in["host_list"].([]interface{}))
ret.Ipv4List = getSliceSnmpServerSnmpv1V2cUserOidRemoteIpv4List(in["ipv4_list"].([]interface{}))
ret.Ipv6List = getSliceSnmpServerSnmpv1V2cUserOidRemoteIpv6List(in["ipv6_list"].([]interface{}))
}
return ret
}
func getSliceSnmpServerSnmpv1V2cUserOidRemoteHostList(d []interface{}) []edpt.SnmpServerSnmpv1V2cUserOidRemoteHostList {
count1 := len(d)
ret := make([]edpt.SnmpServerSnmpv1V2cUserOidRemoteHostList, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.SnmpServerSnmpv1V2cUserOidRemoteHostList
oi.DnsHost = in["dns_host"].(string)
oi.Ipv4Mask = in["ipv4_mask"].(string)
ret = append(ret, oi)
}
return ret
}
func getSliceSnmpServerSnmpv1V2cUserOidRemoteIpv4List(d []interface{}) []edpt.SnmpServerSnmpv1V2cUserOidRemoteIpv4List {
count1 := len(d)
ret := make([]edpt.SnmpServerSnmpv1V2cUserOidRemoteIpv4List, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.SnmpServerSnmpv1V2cUserOidRemoteIpv4List
oi.Ipv4Host = in["ipv4_host"].(string)
oi.Ipv4Mask = in["ipv4_mask"].(string)
ret = append(ret, oi)
}
return ret
}
func getSliceSnmpServerSnmpv1V2cUserOidRemoteIpv6List(d []interface{}) []edpt.SnmpServerSnmpv1V2cUserOidRemoteIpv6List {
count1 := len(d)
ret := make([]edpt.SnmpServerSnmpv1V2cUserOidRemoteIpv6List, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.SnmpServerSnmpv1V2cUserOidRemoteIpv6List
oi.Ipv6Host = in["ipv6_host"].(string)
oi.Ipv6Mask = in["ipv6_mask"].(int)
ret = append(ret, oi)
}
return ret
}
func dataToEndpointSnmpServerSnmpv1V2cUserOid(d *schema.ResourceData) edpt.SnmpServerSnmpv1V2cUserOid {
var ret edpt.SnmpServerSnmpv1V2cUserOid
ret.Inst.OidVal = d.Get("oid_val").(string)
ret.Inst.Remote = getObjectSnmpServerSnmpv1V2cUserOidRemote(d.Get("remote").([]interface{}))
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
ret.Inst.User = d.Get("user").(string)
return ret
}