/
data_source_stats_traffic_ips_ip_gateway.go
112 lines (89 loc) · 3.17 KB
/
data_source_stats_traffic_ips_ip_gateway.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
// Copyright (C) 2018-2022, Pulse Secure, LLC.
// Licensed under the terms of the MPL 2.0. See LICENSE file for details.
// Data Source Object TrafficIpsIpGateway
package main
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
vtm "github.com/pulse-vadc/go-vtm/8.1"
)
func dataSourceTrafficIpsIpGatewayStatistics() *schema.Resource {
return &schema.Resource{
Read: dataSourceTrafficIpsIpGatewayStatisticsRead,
Schema: map[string]*schema.Schema{
// Number of ARP messages sent for raised Traffic IP Addresses.
"arp_message": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// Number of ping requests sent to the gateway machine.
"gateway_ping_requests": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// Number of ping responses received from the gateway machine.
"gateway_ping_responses": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// Number of ping requests sent to the backend nodes.
"node_ping_requests": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// Number of ping responses received from the backend nodes.
"node_ping_responses": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// The number of traffic IP addresses on this system (includes IPv4
// and IPv6 addresses).
"number_inet46": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// The number of traffic IP addresses currently raised on this system
// (includes IPv4 and IPv6 addresses).
"number_raised_inet46": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
// Number of ping response errors.
"ping_response_errors": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
},
}
}
func dataSourceTrafficIpsIpGatewayStatisticsRead(d *schema.ResourceData, tm interface{}) (readError error) {
object, err := tm.(*vtm.VirtualTrafficManager).GetTrafficIpsIpGatewayStatistics()
if err != nil {
return fmt.Errorf("Failed to read vtm_ip_gateway: %v", err.ErrorText)
}
var lastAssignedField string
defer func() {
r := recover()
if r != nil {
readError = fmt.Errorf("Field '%s' missing from vTM configuration", lastAssignedField)
}
}()
lastAssignedField = "arp_message"
d.Set("arp_message", int(*object.Statistics.ArpMessage))
lastAssignedField = "gateway_ping_requests"
d.Set("gateway_ping_requests", int(*object.Statistics.GatewayPingRequests))
lastAssignedField = "gateway_ping_responses"
d.Set("gateway_ping_responses", int(*object.Statistics.GatewayPingResponses))
lastAssignedField = "node_ping_requests"
d.Set("node_ping_requests", int(*object.Statistics.NodePingRequests))
lastAssignedField = "node_ping_responses"
d.Set("node_ping_responses", int(*object.Statistics.NodePingResponses))
lastAssignedField = "number_inet46"
d.Set("number_inet46", int(*object.Statistics.NumberInet46))
lastAssignedField = "number_raised_inet46"
d.Set("number_raised_inet46", int(*object.Statistics.NumberRaisedInet46))
lastAssignedField = "ping_response_errors"
d.Set("ping_response_errors", int(*object.Statistics.PingResponseErrors))
d.SetId("ip_gateway")
return nil
}