forked from pulse-vadc/go-vtm
/
config_glb_service.go
203 lines (165 loc) · 6.81 KB
/
config_glb_service.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
// Copyright (C) 2018, Pulse Secure, LLC.
// Licensed under the terms of the MPL 2.0. See LICENSE file for details.
// Go library for Pulse Virtual Traffic Manager REST version 6.0.
package vtm
import (
"encoding/json"
)
type GlbService struct {
connector *vtmConnector
GlbServiceProperties `json:"properties"`
}
func (vtm VirtualTrafficManager) GetGlbService(name string) (*GlbService, *vtmErrorResponse) {
if name == "" {
panic("Provided an empty \"name\" parameter to VirtualTrafficManager.GetGlbService(name)")
}
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/glb_services/" + name)
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
object := new(GlbService)
object.connector = conn
if err := json.NewDecoder(data).Decode(object); err != nil {
panic(err)
}
return object, nil
}
func (object GlbService) Apply() (*GlbService, *vtmErrorResponse) {
marshalled, err := json.Marshal(object)
if err != nil {
panic(err)
}
data, ok := object.connector.put(string(marshalled), STANDARD_OBJ)
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
if err := json.NewDecoder(data).Decode(&object); err != nil {
panic(err)
}
return &object, nil
}
func (vtm VirtualTrafficManager) NewGlbService(name string) *GlbService {
object := new(GlbService)
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/glb_services/" + name)
object.connector = conn
return object
}
func (vtm VirtualTrafficManager) DeleteGlbService(name string) *vtmErrorResponse {
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/glb_services/" + name)
data, ok := conn.delete()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return object
}
return nil
}
func (vtm VirtualTrafficManager) ListGlbServices() (*[]string, *vtmErrorResponse) {
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/glb_services")
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
objectList := new(vtmObjectChildren)
if err := json.NewDecoder(data).Decode(objectList); err != nil {
panic(err)
}
var stringList []string
for _, obj := range objectList.Children {
stringList = append(stringList, obj.Name)
}
return &stringList, nil
}
type GlbServiceProperties struct {
Basic struct {
// Defines the global load balancing algorithm to be used.
Algorithm *string `json:"algorithm,omitempty"`
// Do all monitors assigned to a location need to report success
// in order for it to be considered healthy?
AllMonitorsNeeded *bool `json:"all_monitors_needed,omitempty"`
// The last location to fail will be available as soon as it recovers.
Autorecovery *bool `json:"autorecovery,omitempty"`
// Enable/Disable automatic failback mode.
ChainedAutoFailback *bool `json:"chained_auto_failback,omitempty"`
// The locations this service operates for and defines the order
// in which locations fail.
ChainedLocationOrder *[]string `json:"chained_location_order,omitempty"`
// Locations recovering from a failure will become disabled.
DisableOnFailure *bool `json:"disable_on_failure,omitempty"`
// A table mapping domains to the private keys that authenticate
// them
DnssecKeys *GlbServiceDnssecKeysTable `json:"dnssec_keys,omitempty"`
// The domains shown here should be a list of Fully Qualified Domain
// Names that you would like to balance globally. Responses from
// the back end DNS servers for queries that do not match this list
// will be forwarded to the client unmodified. Note: "*" may be
// used as a wild card.
Domains *[]string `json:"domains,omitempty"`
// Enable/Disable our response manipulation of DNS.
Enabled *bool `json:"enabled,omitempty"`
// How much should the locality of visitors affect the choice of
// location used? This value is a percentage, 0% means that no locality
// information will be used, and 100% means that locality will always
// control which location is used. Values between the two extremes
// will act accordingly.
GeoEffect *int `json:"geo_effect,omitempty"`
// The response to be sent in case there are no locations available.
LastResortResponse *[]string `json:"last_resort_response,omitempty"`
// This is the list of locations for which this service is draining.
// A location that is draining will never serve any of its service
// IP addresses for this domain. This can be used to take a location
// off-line.
LocationDraining *[]string `json:"location_draining,omitempty"`
// Table containing location specific settings.
LocationSettings *GlbServiceLocationSettingsTable `json:"location_settings,omitempty"`
// Is location health optimistic? Set true to treat a location as
// healthy if any peer reports it as healthy, set false to treat
// a location as failed if any peer reports a monitor failure.
OptimisticLocationHealth *bool `json:"optimistic_location_health,omitempty"`
// Peer reported monitor state timeout in seconds.
PeerHealthTimeout *int `json:"peer_health_timeout,omitempty"`
// Return all or none of the IPs under complete failure.
ReturnIpsOnFail *bool `json:"return_ips_on_fail,omitempty"`
// Response rules to be applied in the context of the service, in
// order, comma separated.
Rules *[]string `json:"rules,omitempty"`
// The TTL for the DNS resource records handled by the GLB service.
Ttl *int `json:"ttl,omitempty"`
} `json:"basic"`
Log struct {
// Log connections to this GLB service?
Enabled *bool `json:"enabled,omitempty"`
// The filename the verbose query information should be logged to.
// Appliances will ignore this.
Filename *string `json:"filename,omitempty"`
// The format of the log lines.
Format *string `json:"format,omitempty"`
} `json:"log"`
}
type GlbServiceDnssecKeys struct {
// A domain authenticated by the associated private keys.
Domain *string `json:"domain,omitempty"`
// Private keys that authenticate the associated domain.
SslKey *[]string `json:"ssl_key,omitempty"`
}
type GlbServiceDnssecKeysTable []GlbServiceDnssecKeys
type GlbServiceLocationSettings struct {
// The IP addresses that are present in a location. If the Global
// Load Balancer decides to direct a DNS query to this location,
// then it will filter out all IPs that are not in this list.
Ips *[]string `json:"ips,omitempty"`
// Location to which the associated settings apply.
Location *string `json:"location,omitempty"`
// The monitors that are present in a location.
Monitors *[]string `json:"monitors,omitempty"`
// Weight for this location, for use by the weighted random algorithm.
Weight *int `json:"weight,omitempty"`
}
type GlbServiceLocationSettingsTable []GlbServiceLocationSettings