forked from f5devcentral/go-bigip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtm.go
More file actions
752 lines (683 loc) · 29.2 KB
/
gtm.go
File metadata and controls
752 lines (683 loc) · 29.2 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/*
Original work Copyright © 2015 Scott Ware
Modifications Copyright 2019 F5 Networks Inc
Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
package bigip
import (
"encoding/json"
"log"
)
const (
uriGtm = "gtm"
uriServer = "server"
uriDatacenter = "datacenter"
uriGtmmonitor = "monitor"
uriPoolA = "pool/a"
uriWideIp = "wideip"
)
type Datacenters struct {
Datacenters []GTMDatacenter `json:"items"`
}
type GTMWideIP struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
AppService string `json:"appService,omitempty"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Enabled bool `json:"enabled,omitempty"`
FailureRcode string `json:"failureRcode,omitempty"`
FailureRcodeResponse string `json:"failureRcodeResponse,omitempty"`
FailureRcodeTTL int `json:"failureRcodeTtl,omitempty"`
LastResortPool string `json:"lastResortPool,omitempty"`
LoadBalancingDecisionLogVerbosity []string `json:"loadBalancingDecisionLogVerbosity,omitempty"`
MinimalResponse string `json:"minimalResponse,omitempty"`
PersistCidrIpv4 int `json:"persistCidrIpv4,omitempty"`
PersistCidrIpv6 int `json:"persistCidrIpv6,omitempty"`
Persistence string `json:"persistence,omitempty"`
PoolLbMode string `json:"poolLbMode,omitempty"`
TopologyPreferEdns0ClientSubnet string `json:"topologyPreferEdns0ClientSubnet,omitempty"`
TTLPersistence int `json:"ttlPersistence,omitempty"`
Aliases []string `json:"aliases,omitempty"`
// Not in the spec, but returned by the API
// Setting this field atomically updates all members.
//Pools *[]GTMWideIPPool `json:"pools,omitempty"`
}
// type Datacenter struct {
// Name string `json:"name,omitempty"`
// Description string `json:"description,omitempty"`
// Contact string `json:"contact,omitempty"`
// App_service string `json:"appService,omitempty"`
// Disabled bool `json:"disabled,omitempty"`
// Enabled bool `json:"enabled,omitempty"`
// Prober_pool string `json:"proberPool,omitempty"`
// }
type GTMDatacenter struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Contact string `json:"contact,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Location string `json:"location,omitempty"`
ProberFallback string `json:"proberFallback,omitempty"`
ProberPreference string `json:"proberPreference,omitempty"`
}
type Gtmmonitors struct {
Gtmmonitors []Gtmmonitor `json:"items"`
}
type Gtmmonitor struct {
Name string `json:"name,omitempty"`
Defaults_from string `json:"defaultsFrom,omitempty"`
Interval int `json:"interval,omitempty"`
Probe_timeout int `json:"probeTimeout,omitempty"`
Recv string `json:"recv,omitempty"`
Send string `json:"send,omitempty"`
}
type Servers struct {
Servers []Server `json:"items"`
}
type Server struct {
Name string
Datacenter string
Description string
Monitor string
Virtual_server_discovery string
Product string
Enabled bool
Disabled bool
Addresses []ServerAddresses
GTMVirtual_Server []VSrecord
ExposeRouteDomains string
IqAllowPath string
IqAllowServiceCheck string
IqAllowSnmp string
LinkDiscovery string
ProberFallback string
ProberPreference string
ProberPool string
LimitCpuUsage int
LimitCpuUsageStatus string
LimitMaxBps int
LimitMaxBpsStatus string
LimitMaxConnections int
LimitMaxConnectionsStatus string
LimitMaxPps int
LimitMaxPpsStatus string
LimitMemAvail int
LimitMemAvailStatus string
}
type serverDTO struct {
Name string `json:"name"`
Datacenter string `json:"datacenter,omitempty"`
Description string `json:"description,omitempty"`
Monitor string `json:"monitor,omitempty"`
Virtual_server_discovery string `json:"virtualServerDiscovery,omitempty"`
Product string `json:"product,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
ExposeRouteDomains string `json:"exposeRouteDomains,omitempty"`
IqAllowPath string `json:"iqAllowPath,omitempty"`
IqAllowServiceCheck string `json:"iqAllowServiceCheck,omitempty"`
IqAllowSnmp string `json:"iqAllowSnmp,omitempty"`
LinkDiscovery string `json:"linkDiscovery,omitempty"`
ProberFallback string `json:"proberFallback,omitempty"`
ProberPreference string `json:"proberPreference,omitempty"`
ProberPool string `json:"proberPool,omitempty"`
LimitCpuUsage int `json:"limitCpuUsage,omitempty"`
LimitCpuUsageStatus string `json:"limitCpuUsageStatus,omitempty"`
LimitMaxBps int `json:"limitMaxBps,omitempty"`
LimitMaxBpsStatus string `json:"limitMaxBpsStatus,omitempty"`
LimitMaxConnections int `json:"limitMaxConnections,omitempty"`
LimitMaxConnectionsStatus string `json:"limitMaxConnectionsStatus,omitempty"`
LimitMaxPps int `json:"limitMaxPps,omitempty"`
LimitMaxPpsStatus string `json:"limitMaxPpsStatus,omitempty"`
LimitMemAvail int `json:"limitMemAvail,omitempty"`
LimitMemAvailStatus string `json:"limitMemAvailStatus,omitempty"`
Addresses []ServerAddresses `json:"addresses,omitempty"`
GTMVirtual_Server struct {
Items []VSrecord `json:"items,omitempty"`
} `json:"virtualServersReference,omitempty"`
}
func (p *Server) MarshalJSON() ([]byte, error) {
return json.Marshal(serverDTO{
Name: p.Name,
Datacenter: p.Datacenter,
Description: p.Description,
Monitor: p.Monitor,
Virtual_server_discovery: p.Virtual_server_discovery,
Product: p.Product,
Enabled: p.Enabled,
Disabled: p.Disabled,
ExposeRouteDomains: p.ExposeRouteDomains,
IqAllowPath: p.IqAllowPath,
IqAllowServiceCheck: p.IqAllowServiceCheck,
IqAllowSnmp: p.IqAllowSnmp,
LinkDiscovery: p.LinkDiscovery,
ProberFallback: p.ProberFallback,
ProberPreference: p.ProberPreference,
ProberPool: p.ProberPool,
LimitCpuUsage: p.LimitCpuUsage,
LimitCpuUsageStatus: p.LimitCpuUsageStatus,
LimitMaxBps: p.LimitMaxBps,
LimitMaxBpsStatus: p.LimitMaxBpsStatus,
LimitMaxConnections: p.LimitMaxConnections,
LimitMaxConnectionsStatus: p.LimitMaxConnectionsStatus,
LimitMaxPps: p.LimitMaxPps,
LimitMaxPpsStatus: p.LimitMaxPpsStatus,
LimitMemAvail: p.LimitMemAvail,
LimitMemAvailStatus: p.LimitMemAvailStatus,
Addresses: p.Addresses,
GTMVirtual_Server: struct {
Items []VSrecord `json:"items,omitempty"`
}{Items: p.GTMVirtual_Server},
})
}
func (p *Server) UnmarshalJSON(b []byte) error {
var dto serverDTO
err := json.Unmarshal(b, &dto)
if err != nil {
return err
}
p.Name = dto.Name
p.Datacenter = dto.Datacenter
p.Description = dto.Description
p.Monitor = dto.Monitor
p.Virtual_server_discovery = dto.Virtual_server_discovery
p.Product = dto.Product
p.Enabled = dto.Enabled
p.Disabled = dto.Disabled
p.ExposeRouteDomains = dto.ExposeRouteDomains
p.IqAllowPath = dto.IqAllowPath
p.IqAllowServiceCheck = dto.IqAllowServiceCheck
p.IqAllowSnmp = dto.IqAllowSnmp
p.LinkDiscovery = dto.LinkDiscovery
p.ProberFallback = dto.ProberFallback
p.ProberPreference = dto.ProberPreference
p.ProberPool = dto.ProberPool
p.LimitCpuUsage = dto.LimitCpuUsage
p.LimitCpuUsageStatus = dto.LimitCpuUsageStatus
p.LimitMaxBps = dto.LimitMaxBps
p.LimitMaxBpsStatus = dto.LimitMaxBpsStatus
p.LimitMaxConnections = dto.LimitMaxConnections
p.LimitMaxConnectionsStatus = dto.LimitMaxConnectionsStatus
p.LimitMaxPps = dto.LimitMaxPps
p.LimitMaxPpsStatus = dto.LimitMaxPpsStatus
p.LimitMemAvail = dto.LimitMemAvail
p.LimitMemAvailStatus = dto.LimitMemAvailStatus
p.Addresses = dto.Addresses
p.GTMVirtual_Server = dto.GTMVirtual_Server.Items
return nil
}
type ServerAddressess struct {
Items []ServerAddresses `json:"items,omitempty"`
}
type ServerAddresses struct {
Name string `json:"name"`
Device_name string `json:"deviceName,omitempty"`
Translation string `json:"translation,omitempty"`
}
type VSrecords struct {
Items []VSrecord `json:"items,omitempty"`
}
type VSrecord struct {
Name string `json:"name"`
FullPath string `json:"fullPath,omitempty"`
Destination string `json:"destination,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
TranslationAddress string `json:"translationAddress,omitempty"`
TranslationPort int `json:"translationPort,omitempty"`
Monitor string `json:"monitor,omitempty"`
LimitMaxBps int `json:"limitMaxBps,omitempty"`
LimitMaxBpsStatus string `json:"limitMaxBpsStatus,omitempty"`
LimitMaxConnections int `json:"limitMaxConnections,omitempty"`
LimitMaxConnectionsStatus string `json:"limitMaxConnectionsStatus,omitempty"`
LimitMaxPps int `json:"limitMaxPps,omitempty"`
LimitMaxPpsStatus string `json:"limitMaxPpsStatus,omitempty"`
DependsOn string `json:"dependsOn,omitempty"`
}
type GtmPools struct {
Pools []GtmPool `json:"items"`
}
type GtmPool struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
AlternateMode string `json:"alternateMode,omitempty"`
DynamicRatio string `json:"dynamicRatio,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
FallbackIp string `json:"fallbackIp,omitempty"`
FallbackMode string `json:"fallbackMode,omitempty"`
LoadBalancingMode string `json:"loadBalancingMode,omitempty"`
ManualResume string `json:"manualResume,omitempty"`
MaxAnswersReturned int `json:"maxAnswersReturned,omitempty"`
Monitor string `json:"monitor,omitempty"`
QosHitRatio int `json:"qosHitRatio,omitempty"`
QosHops int `json:"qosHops,omitempty"`
QosKilobytesSecond int `json:"qosKilobytesSecond,omitempty"`
QosLcs int `json:"qosLcs,omitempty"`
QosPacketRate int `json:"qosPacketRate,omitempty"`
QosRtt int `json:"qosRtt,omitempty"`
QosTopology int `json:"qosTopology,omitempty"`
QosVsCapacity int `json:"qosVsCapacity,omitempty"`
QosVsScore int `json:"qosVsScore,omitempty"`
Ttl int `json:"ttl,omitempty"`
LimitMaxBps int `json:"limitMaxBps,omitempty"`
LimitMaxBpsStatus string `json:"limitMaxBpsStatus,omitempty"`
LimitMaxConnections int `json:"limitMaxConnections,omitempty"`
LimitMaxConnectionsStatus string `json:"limitMaxConnectionsStatus,omitempty"`
LimitMaxPps int `json:"limitMaxPps,omitempty"`
LimitMaxPpsStatus string `json:"limitMaxPpsStatus,omitempty"`
MinMembersUpMode string `json:"minMembersUpMode,omitempty"`
MinMembersUpValue int `json:"minMembersUpValue,omitempty"`
VerifyMemberAvailability string `json:"verifyMemberAvailability,omitempty"`
Members []GtmPoolMembers
// Legacy fields for backward compatibility
Load_balancing_mode string `json:"load_balancing_mode,omitempty"`
Max_answers_returned int `json:"max_answers_returned,omitempty"`
Alternate_mode string `json:"alternate_mode,omitempty"`
Fallback_ip string `json:"fallback_ip,omitempty"`
Fallback_mode string `json:"fallback_mode,omitempty"`
}
type gtmPoolDTO struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
AlternateMode string `json:"alternateMode,omitempty"`
DynamicRatio string `json:"dynamicRatio,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
FallbackIp string `json:"fallbackIp,omitempty"`
FallbackMode string `json:"fallbackMode,omitempty"`
LoadBalancingMode string `json:"loadBalancingMode,omitempty"`
ManualResume string `json:"manualResume,omitempty"`
MaxAnswersReturned int `json:"maxAnswersReturned,omitempty"`
Monitor string `json:"monitor,omitempty"`
QosHitRatio int `json:"qosHitRatio,omitempty"`
QosHops int `json:"qosHops,omitempty"`
QosKilobytesSecond int `json:"qosKilobytesSecond,omitempty"`
QosLcs int `json:"qosLcs,omitempty"`
QosPacketRate int `json:"qosPacketRate,omitempty"`
QosRtt int `json:"qosRtt,omitempty"`
QosTopology int `json:"qosTopology,omitempty"`
QosVsCapacity int `json:"qosVsCapacity,omitempty"`
QosVsScore int `json:"qosVsScore,omitempty"`
Ttl int `json:"ttl,omitempty"`
LimitMaxBps int `json:"limitMaxBps,omitempty"`
LimitMaxBpsStatus string `json:"limitMaxBpsStatus,omitempty"`
LimitMaxConnections int `json:"limitMaxConnections,omitempty"`
LimitMaxConnectionsStatus string `json:"limitMaxConnectionsStatus,omitempty"`
LimitMaxPps int `json:"limitMaxPps,omitempty"`
LimitMaxPpsStatus string `json:"limitMaxPpsStatus,omitempty"`
MinMembersUpMode string `json:"minMembersUpMode,omitempty"`
MinMembersUpValue int `json:"minMembersUpValue,omitempty"`
VerifyMemberAvailability string `json:"verifyMemberAvailability,omitempty"`
MembersReference struct {
Items []GtmPoolMembers `json:"items,omitempty"`
} `json:"membersReference,omitempty"`
// Legacy fields for backward compatibility
Load_balancing_mode string `json:"load_balancing_mode,omitempty"`
Max_answers_returned int `json:"max_answers_returned,omitempty"`
Alternate_mode string `json:"alternate_mode,omitempty"`
Fallback_ip string `json:"fallback_ip,omitempty"`
Fallback_mode string `json:"fallback_mode,omitempty"`
}
func (p *GtmPool) MarshalJSON() ([]byte, error) {
return json.Marshal(gtmPoolDTO{
Name: p.Name,
Partition: p.Partition,
FullPath: p.FullPath,
Generation: p.Generation,
AlternateMode: p.AlternateMode,
DynamicRatio: p.DynamicRatio,
Enabled: p.Enabled,
Disabled: p.Disabled,
FallbackIp: p.FallbackIp,
FallbackMode: p.FallbackMode,
LoadBalancingMode: p.LoadBalancingMode,
ManualResume: p.ManualResume,
MaxAnswersReturned: p.MaxAnswersReturned,
Monitor: p.Monitor,
QosHitRatio: p.QosHitRatio,
QosHops: p.QosHops,
QosKilobytesSecond: p.QosKilobytesSecond,
QosLcs: p.QosLcs,
QosPacketRate: p.QosPacketRate,
QosRtt: p.QosRtt,
QosTopology: p.QosTopology,
QosVsCapacity: p.QosVsCapacity,
QosVsScore: p.QosVsScore,
Ttl: p.Ttl,
LimitMaxBps: p.LimitMaxBps,
LimitMaxBpsStatus: p.LimitMaxBpsStatus,
LimitMaxConnections: p.LimitMaxConnections,
LimitMaxConnectionsStatus: p.LimitMaxConnectionsStatus,
LimitMaxPps: p.LimitMaxPps,
LimitMaxPpsStatus: p.LimitMaxPpsStatus,
MinMembersUpMode: p.MinMembersUpMode,
MinMembersUpValue: p.MinMembersUpValue,
VerifyMemberAvailability: p.VerifyMemberAvailability,
MembersReference: struct {
Items []GtmPoolMembers `json:"items,omitempty"`
}{Items: p.Members},
Load_balancing_mode: p.Load_balancing_mode,
Max_answers_returned: p.Max_answers_returned,
Alternate_mode: p.Alternate_mode,
Fallback_ip: p.Fallback_ip,
Fallback_mode: p.Fallback_mode,
})
}
func (p *GtmPool) UnmarshalJSON(b []byte) error {
var dto gtmPoolDTO
err := json.Unmarshal(b, &dto)
if err != nil {
return err
}
p.Name = dto.Name
p.Partition = dto.Partition
p.FullPath = dto.FullPath
p.Generation = dto.Generation
p.AlternateMode = dto.AlternateMode
p.DynamicRatio = dto.DynamicRatio
p.Enabled = dto.Enabled
p.Disabled = dto.Disabled
p.FallbackIp = dto.FallbackIp
p.FallbackMode = dto.FallbackMode
p.LoadBalancingMode = dto.LoadBalancingMode
p.ManualResume = dto.ManualResume
p.MaxAnswersReturned = dto.MaxAnswersReturned
p.Monitor = dto.Monitor
p.QosHitRatio = dto.QosHitRatio
p.QosHops = dto.QosHops
p.QosKilobytesSecond = dto.QosKilobytesSecond
p.QosLcs = dto.QosLcs
p.QosPacketRate = dto.QosPacketRate
p.QosRtt = dto.QosRtt
p.QosTopology = dto.QosTopology
p.QosVsCapacity = dto.QosVsCapacity
p.QosVsScore = dto.QosVsScore
p.Ttl = dto.Ttl
p.LimitMaxBps = dto.LimitMaxBps
p.LimitMaxBpsStatus = dto.LimitMaxBpsStatus
p.LimitMaxConnections = dto.LimitMaxConnections
p.LimitMaxConnectionsStatus = dto.LimitMaxConnectionsStatus
p.LimitMaxPps = dto.LimitMaxPps
p.LimitMaxPpsStatus = dto.LimitMaxPpsStatus
p.MinMembersUpMode = dto.MinMembersUpMode
p.MinMembersUpValue = dto.MinMembersUpValue
p.VerifyMemberAvailability = dto.VerifyMemberAvailability
p.Members = dto.MembersReference.Items
p.Load_balancing_mode = dto.Load_balancing_mode
p.Max_answers_returned = dto.Max_answers_returned
p.Alternate_mode = dto.Alternate_mode
p.Fallback_ip = dto.Fallback_ip
p.Fallback_mode = dto.Fallback_mode
return nil
}
type GtmPoolMembers struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
SubPath string `json:"subPath,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
LimitMaxBps int `json:"limitMaxBps,omitempty"`
LimitMaxBpsStatus string `json:"limitMaxBpsStatus,omitempty"`
LimitMaxConnections int `json:"limitMaxConnections,omitempty"`
LimitMaxConnectionsStatus string `json:"limitMaxConnectionsStatus,omitempty"`
LimitMaxPps int `json:"limitMaxPps,omitempty"`
LimitMaxPpsStatus string `json:"limitMaxPpsStatus,omitempty"`
MemberOrder int `json:"memberOrder,omitempty"`
Monitor string `json:"monitor,omitempty"`
Ratio int `json:"ratio,omitempty"`
}
func (b *BigIP) Gtmmonitors() (*Gtmmonitor, error) {
var gtmmonitor Gtmmonitor
err, _ := b.getForEntity(>mmonitor, uriGtm, uriGtmmonitor, uriHttp)
if err != nil {
return nil, err
}
return >mmonitor, nil
}
func (b *BigIP) CreateGtmmonitor(name, defaults_from string, interval, probeTimeout int, recv, send string) error {
config := &Gtmmonitor{
Name: name,
Defaults_from: defaults_from,
Interval: interval,
Probe_timeout: probeTimeout,
Recv: recv,
Send: send,
}
return b.post(config, uriGtm, uriGtmmonitor, uriHttp)
}
func (b *BigIP) ModifyGtmmonitor(*Gtmmonitor) error {
return b.patch(uriGtm, uriGtmmonitor, uriHttp)
}
func (b *BigIP) DeleteGtmmonitor(name string) error {
return b.delete(uriGtm, uriGtmmonitor, uriHttp, name)
}
func (b *BigIP) CreateGtmserver(p *Server) error {
log.Println(" what is the complete payload ", p)
return b.post(p, uriGtm, uriServer)
}
// Update an existing policy.
func (b *BigIP) UpdateGtmserver(name string, p *Server) error {
return b.put(p, uriGtm, uriServer, name)
}
// Delete a policy by name.
func (b *BigIP) DeleteGtmserver(name string) error {
return b.delete(uriGtm, uriServer, name)
}
func (b *BigIP) GetGtmserver(name string) (*Server, error) {
var p Server
err, ok := b.getForEntity(&p, uriGtm, uriServer, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
// Fetch virtual servers separately as they are returned via reference
var vsResponse struct {
Items []VSrecord `json:"items"`
}
err, ok = b.getForEntity(&vsResponse, uriGtm, uriServer, name, "virtual-servers")
if err != nil {
log.Printf("[DEBUG] Error fetching GTM server virtual servers for %s: %v", name, err)
} else if ok && len(vsResponse.Items) > 0 {
p.GTMVirtual_Server = vsResponse.Items
log.Printf("[DEBUG] Fetched %d virtual servers for GTM server %s", len(vsResponse.Items), name)
}
return &p, nil
}
// GetGTMServerVirtualServers retrieves all virtual servers for a GTM server
func (b *BigIP) GetGTMServerVirtualServers(serverName string) ([]VSrecord, error) {
var response struct {
Items []VSrecord `json:"items"`
}
err, ok := b.getForEntity(&response, uriGtm, uriServer, serverName, "virtual-servers")
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return response.Items, nil
}
// GetGTMServerVirtualServer retrieves a specific virtual server from a GTM server
func (b *BigIP) GetGTMServerVirtualServer(serverName, vsName string) (*VSrecord, error) {
var vs VSrecord
err, ok := b.getForEntity(&vs, uriGtm, uriServer, serverName, "virtual-servers", vsName)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &vs, nil
}
// CreateGTMServerVirtualServer creates a virtual server on a GTM server
func (b *BigIP) CreateGTMServerVirtualServer(serverName string, vs *VSrecord) error {
return b.post(vs, uriGtm, uriServer, serverName, "virtual-servers")
}
// ModifyGTMServerVirtualServer updates a virtual server on a GTM server
func (b *BigIP) ModifyGTMServerVirtualServer(serverName, vsName string, vs *VSrecord) error {
return b.put(vs, uriGtm, uriServer, serverName, "virtual-servers", vsName)
}
// DeleteGTMServerVirtualServer removes a virtual server from a GTM server
func (b *BigIP) DeleteGTMServerVirtualServer(serverName, vsName string) error {
return b.delete(uriGtm, uriServer, serverName, "virtual-servers", vsName)
}
// func (b *BigIP) CreatePool_a(name, monitor, load_balancing_mode string, max_answers_returned int, alternate_mode, fallback_ip, fallback_mode string, members []string) error {
// config := &Pool{
// Name: name,
// Monitor: monitor,
// Load_balancing_mode: load_balancing_mode,
// Max_answers_returned: max_answers_returned,
// Alternate_mode: alternate_mode,
// Fallback_ip: fallback_ip,
// Fallback_mode: fallback_mode,
// Members: members,
// }
// log.Println("in poola now", config)
// return b.patch(config, uriGtm, uriPoolA)
// }
// func (b *BigIP) ModifyPool_a(config *GtmPool) error {
// return b.put(config, uriGtm, uriPoolA)
// }
// func (b *BigIP) Pool_as() (*GtmPool, error) {
// var pool GtmPool
// err, _ := b.getForEntity(&pool, uriGtm, uriPoolA)
// if err != nil {
// return nil, err
// }
// return &pool, nil
// }
// AddGTMPool creates a new GTM pool
func (b *BigIP) AddGTMPool(config *GtmPool, poolType string) error {
return b.post(config, uriGtm, "pool", poolType)
}
// GetGTMPool retrieves a GTM pool by name
func (b *BigIP) GetGTMPool(fullPath string, poolType string) (*GtmPool, error) {
var pool GtmPool
err, ok := b.getForEntity(&pool, uriGtm, "pool", poolType, fullPath)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
// Fetch members separately using the same path pattern as LTM pools
var membersResponse struct {
Items []GtmPoolMembers `json:"items"`
}
log.Printf("[DEBUG] Attempting to fetch members for GTM pool: %s, type: %s, path: gtm/pool/%s/%s/members", fullPath, poolType, poolType, fullPath)
err, ok = b.getForEntity(&membersResponse, uriGtm, "pool", poolType, fullPath, "members")
if err != nil {
log.Printf("[DEBUG] Error fetching GTM pool members for %s: %v", fullPath, err)
// Don't fail - pool might not have members or endpoint might not be accessible
} else if ok {
log.Printf("[DEBUG] Members response OK, found %d items", len(membersResponse.Items))
if len(membersResponse.Items) > 0 {
pool.Members = membersResponse.Items
log.Printf("[DEBUG] Fetched %d members for GTM pool %s", len(membersResponse.Items), fullPath)
} else {
log.Printf("[DEBUG] No members found for GTM pool %s", fullPath)
}
} else {
log.Printf("[DEBUG] Members fetch returned ok=false for pool %s", fullPath)
}
return &pool, nil
}
// ModifyGTMPool updates a GTM pool
func (b *BigIP) ModifyGTMPool(fullPath string, config *GtmPool, poolType string) error {
return b.put(config, uriGtm, "pool", poolType, fullPath)
}
// DeleteGTMPool removes a GTM pool
func (b *BigIP) DeleteGTMPool(fullPath string, poolType string) error {
return b.delete(uriGtm, "pool", poolType, fullPath)
}
func (b *BigIP) CreateGTMWideIP(config *GTMWideIP, recordType string) error {
return b.post(config, uriGtm, uriWideIp, recordType)
}
func (b *BigIP) DeleteGTMWideIP(fullPath string, recordType string) error {
return b.delete(uriGtm, uriWideIp, recordType, fullPath)
}
func (b *BigIP) ModifyGTMWideIP(fullPath string, config *GTMWideIP, recordType string) error {
return b.put(config, uriGtm, uriWideIp, recordType, fullPath)
}
// GetGTMWideIP get's a WideIP by name
func (b *BigIP) GetGTMWideIP(name string, recordType string) (*GTMWideIP, error) {
var w GTMWideIP
err, ok := b.getForEntity(&w, uriGtm, uriWideIp, string(recordType), name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &w, nil
}
// CreateGTMDatacenter creates a new GTM datacenter
func (b *BigIP) CreateGTMDatacenter(config *GTMDatacenter) error {
return b.post(config, uriGtm, uriDatacenter)
}
// GetGTMDatacenter retrieves a GTM datacenter by full path
func (b *BigIP) GetGTMDatacenter(fullPath string) (*GTMDatacenter, error) {
var dc GTMDatacenter
err, ok := b.getForEntity(&dc, uriGtm, uriDatacenter, fullPath)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &dc, nil
}
// ModifyGTMDatacenter updates a GTM datacenter
func (b *BigIP) ModifyGTMDatacenter(fullPath string, config *GTMDatacenter) error {
return b.put(config, uriGtm, uriDatacenter, fullPath)
}
// DeleteGTMDatacenter removes a GTM datacenter
func (b *BigIP) DeleteGTMDatacenter(fullPath string) error {
return b.delete(uriGtm, uriDatacenter, fullPath)
}
// func (b *BigIP) GetDatacenters() (*GTMDatacenter, error) {
// var datacenter GTMDatacenter
// err, _ := b.getForEntity(&datacenter, uriGtm, uriDatacenter)
// if err != nil {
// return nil, err
// }
// return &datacenter, nil
// }
// func (b *BigIP) CreateDatacenter(name, description, contact, app_service string, enabled, disabled bool, prober_pool string) error {
// config := >MDatacenter{
// Name: name,
// Description: description,
// Contact: contact,
// App_service: app_service,
// Enabled: enabled,
// Disabled: disabled,
// Prober_pool: prober_pool,
// }
// return b.post(config, uriGtm, uriDatacenter)
// }
// func (b *BigIP) ModifyDatacenter(*GTMDatacenter) error {
// return b.patch(uriGtm, uriDatacenter)
// }
// func (b *BigIP) DeleteDatacenter(name string) error {
// return b.delete(uriGtm, uriDatacenter, name)
// }