/
resource_gslb_protocol_oper.go
218 lines (206 loc) · 7.82 KB
/
resource_gslb_protocol_oper.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
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 resourceGslbProtocolOper() *schema.Resource {
return &schema.Resource{
Description: "`thunder_gslb_protocol_oper`: Operational Status for the object protocol\n\n__PLACEHOLDER__",
ReadContext: resourceGslbProtocolOperRead,
Schema: map[string]*schema.Schema{
"oper": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"session_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"protocol_info": {
Type: schema.TypeString, Optional: true, Description: "",
},
"state": {
Type: schema.TypeString, Optional: true, Description: "",
},
"session_id": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"connection_succeeded": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"connection_failed": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"open_packet_sent": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"open_packet_received": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"open_session_succeeded": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"open_session_failed": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"sessions_dropped": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"retry": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"update_packet_sent": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"update_packet_received": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"keepalive_packet_sent": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"keepalive_packet_received": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"notify_packet_sent": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"notify_packet_received": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"message_header_error": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"secure_negotiation_success": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"secure_negotiation_fail": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"ssl_handshake_success": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"ssl_handshake_fail": {
Type: schema.TypeInt, Optional: true, Description: "",
},
"secure_state": {
Type: schema.TypeString, Optional: true, Description: "",
},
"secure_config": {
Type: schema.TypeString, Optional: true, Description: "",
},
},
},
},
},
},
},
},
}
}
func resourceGslbProtocolOperRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceGslbProtocolOperRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointGslbProtocolOper(d)
res, err := obj.Get(client.Token, client.Host, d.Id(), logger)
d.SetId(obj.GetId())
logger.Println(res)
GslbProtocolOperOper := setObjectGslbProtocolOperOper(res)
d.Set("oper", GslbProtocolOperOper)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func setObjectGslbProtocolOperOper(ret edpt.DataGslbProtocolOper) []interface{} {
return []interface{}{
map[string]interface{}{
"session_list": setSliceGslbProtocolOperOperSessionList(ret.DtGslbProtocolOper.Oper.SessionList),
},
}
}
func setSliceGslbProtocolOperOperSessionList(d []edpt.GslbProtocolOperOperSessionList) []map[string]interface{} {
result := []map[string]interface{}{}
for _, item := range d {
in := make(map[string]interface{})
in["protocol_info"] = item.ProtocolInfo
in["state"] = item.State
in["session_id"] = item.SessionId
in["connection_succeeded"] = item.ConnectionSucceeded
in["connection_failed"] = item.ConnectionFailed
in["open_packet_sent"] = item.OpenPacketSent
in["open_packet_received"] = item.OpenPacketReceived
in["open_session_succeeded"] = item.OpenSessionSucceeded
in["open_session_failed"] = item.OpenSessionFailed
in["sessions_dropped"] = item.SessionsDropped
in["retry"] = item.Retry
in["update_packet_sent"] = item.UpdatePacketSent
in["update_packet_received"] = item.UpdatePacketReceived
in["keepalive_packet_sent"] = item.KeepalivePacketSent
in["keepalive_packet_received"] = item.KeepalivePacketReceived
in["notify_packet_sent"] = item.NotifyPacketSent
in["notify_packet_received"] = item.NotifyPacketReceived
in["message_header_error"] = item.MessageHeaderError
in["secure_negotiation_success"] = item.SecureNegotiationSuccess
in["secure_negotiation_fail"] = item.SecureNegotiationFail
in["ssl_handshake_success"] = item.SslHandshakeSuccess
in["ssl_handshake_fail"] = item.SslHandshakeFail
in["secure_state"] = item.Secure_state
in["secure_config"] = item.Secure_config
result = append(result, in)
}
return result
}
func getObjectGslbProtocolOperOper(d []interface{}) edpt.GslbProtocolOperOper {
count1 := len(d)
var ret edpt.GslbProtocolOperOper
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.SessionList = getSliceGslbProtocolOperOperSessionList(in["session_list"].([]interface{}))
}
return ret
}
func getSliceGslbProtocolOperOperSessionList(d []interface{}) []edpt.GslbProtocolOperOperSessionList {
count1 := len(d)
ret := make([]edpt.GslbProtocolOperOperSessionList, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.GslbProtocolOperOperSessionList
oi.ProtocolInfo = in["protocol_info"].(string)
oi.State = in["state"].(string)
oi.SessionId = in["session_id"].(int)
oi.ConnectionSucceeded = in["connection_succeeded"].(int)
oi.ConnectionFailed = in["connection_failed"].(int)
oi.OpenPacketSent = in["open_packet_sent"].(int)
oi.OpenPacketReceived = in["open_packet_received"].(int)
oi.OpenSessionSucceeded = in["open_session_succeeded"].(int)
oi.OpenSessionFailed = in["open_session_failed"].(int)
oi.SessionsDropped = in["sessions_dropped"].(int)
oi.Retry = in["retry"].(int)
oi.UpdatePacketSent = in["update_packet_sent"].(int)
oi.UpdatePacketReceived = in["update_packet_received"].(int)
oi.KeepalivePacketSent = in["keepalive_packet_sent"].(int)
oi.KeepalivePacketReceived = in["keepalive_packet_received"].(int)
oi.NotifyPacketSent = in["notify_packet_sent"].(int)
oi.NotifyPacketReceived = in["notify_packet_received"].(int)
oi.MessageHeaderError = in["message_header_error"].(int)
oi.SecureNegotiationSuccess = in["secure_negotiation_success"].(int)
oi.SecureNegotiationFail = in["secure_negotiation_fail"].(int)
oi.SslHandshakeSuccess = in["ssl_handshake_success"].(int)
oi.SslHandshakeFail = in["ssl_handshake_fail"].(int)
oi.Secure_state = in["secure_state"].(string)
oi.Secure_config = in["secure_config"].(string)
ret = append(ret, oi)
}
return ret
}
func dataToEndpointGslbProtocolOper(d *schema.ResourceData) edpt.GslbProtocolOper {
var ret edpt.GslbProtocolOper
ret.Oper = getObjectGslbProtocolOperOper(d.Get("oper").([]interface{}))
return ret
}