forked from contiv-experimental/contivmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contivModel.go
5802 lines (4632 loc) · 155 KB
/
contivModel.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
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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// contivModel.go
// This file is auto generated by modelgen tool
// Do not edit this file manually
package contivModel
import (
"encoding/json"
"errors"
log "github.com/Sirupsen/logrus"
"github.com/contiv/objdb/modeldb"
"github.com/gorilla/mux"
"net/http"
"regexp"
"sync"
)
type HttpApiFunc func(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error)
type AciGw struct {
// every object has a key
Key string `json:"key,omitempty"`
EnforcePolicies string `json:"enforcePolicies,omitempty"` // Enforce security policy
IncludeCommonTenant string `json:"includeCommonTenant,omitempty"` // Include common tenant when searching for objects
Name string `json:"name,omitempty"` // name of this block(must be 'aciGw')
NodeBindings string `json:"nodeBindings,omitempty"` // List of ACI complete nodes to be bound
PathBindings string `json:"pathBindings,omitempty"` // List of ACI fabric ports connected to cluster
PhysicalDomain string `json:"physicalDomain,omitempty"` // Name of the physical domain
}
type AciGwOper struct {
NumAppProfiles int `json:"numAppProfiles,omitempty"` //
}
type AciGwInspect struct {
Config AciGw
Oper AciGwOper
}
type AppProfile struct {
// every object has a key
Key string `json:"key,omitempty"`
AppProfileName string `json:"appProfileName,omitempty"` // Application Profile Name
EndpointGroups []string `json:"endpointGroups,omitempty"`
TenantName string `json:"tenantName,omitempty"` // Tenant Name
// add link-sets and links
LinkSets AppProfileLinkSets `json:"link-sets,omitempty"`
Links AppProfileLinks `json:"links,omitempty"`
}
type AppProfileLinkSets struct {
EndpointGroups map[string]modeldb.Link `json:"EndpointGroups,omitempty"`
}
type AppProfileLinks struct {
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type AppProfileInspect struct {
Config AppProfile
}
type Bgp struct {
// every object has a key
Key string `json:"key,omitempty"`
As string `json:"as,omitempty"` // AS id
Hostname string `json:"hostname,omitempty"` // host name
Neighbor string `json:"neighbor,omitempty"` // Bgp neighbor
NeighborAs string `json:"neighbor-as,omitempty"` // AS id
Routerip string `json:"routerip,omitempty"` // Bgp router intf ip
}
type BgpOper struct {
AdminStatus string `json:"adminStatus,omitempty"` // admin status
NeighborStatus string `json:"neighborStatus,omitempty"` // neighbor status
NumRoutes int `json:"numRoutes,omitempty"` // number of routes
Routes []string `json:"routes,omitempty"`
}
type BgpInspect struct {
Config Bgp
Oper BgpOper
}
type EndpointOper struct {
// oper object key (present for oper only objects)
Key string `json:"key,omitempty"`
ContainerID string `json:"containerID,omitempty"` //
ContainerName string `json:"containerName,omitempty"` //
EndpointGroupID int `json:"endpointGroupId,omitempty"` //
EndpointGroupKey string `json:"endpointGroupKey,omitempty"` //
EndpointID string `json:"endpointID,omitempty"` //
HomingHost string `json:"homingHost,omitempty"` //
IntfName string `json:"intfName,omitempty"` //
IpAddress []string `json:"ipAddress,omitempty"`
Labels string `json:"labels,omitempty"` //
MacAddress string `json:"macAddress,omitempty"` //
Network string `json:"network,omitempty"` //
ServiceName string `json:"serviceName,omitempty"` //
VirtualPort string `json:"virtualPort,omitempty"` //
VtepIP string `json:"vtepIP,omitempty"` //
}
type EndpointInspect struct {
Oper EndpointOper
}
type EndpointGroup struct {
// every object has a key
Key string `json:"key,omitempty"`
ExtContractsGrps []string `json:"extContractsGrps,omitempty"`
GroupName string `json:"groupName,omitempty"` // Group name
NetProfile string `json:"netProfile,omitempty"` // Network profile name
NetworkName string `json:"networkName,omitempty"` // Network
Policies []string `json:"policies,omitempty"`
TenantName string `json:"tenantName,omitempty"` // Tenant
// add link-sets and links
LinkSets EndpointGroupLinkSets `json:"link-sets,omitempty"`
Links EndpointGroupLinks `json:"links,omitempty"`
}
type EndpointGroupLinkSets struct {
ExtContractsGrps map[string]modeldb.Link `json:"ExtContractsGrps,omitempty"`
MatchRules map[string]modeldb.Link `json:"MatchRules,omitempty"`
Policies map[string]modeldb.Link `json:"Policies,omitempty"`
Services map[string]modeldb.Link `json:"Services,omitempty"`
}
type EndpointGroupLinks struct {
AppProfile modeldb.Link `json:"AppProfile,omitempty"`
NetProfile modeldb.Link `json:"NetProfile,omitempty"`
Network modeldb.Link `json:"Network,omitempty"`
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type EndpointGroupOper struct {
Endpoints []EndpointOper `json:"endpoints,omitempty"`
ExternalPktTag int `json:"externalPktTag,omitempty"` // external packet tag
NumEndpoints int `json:"numEndpoints,omitempty"` // number of endpoints
PktTag int `json:"pktTag,omitempty"` // internal packet tag
}
type EndpointGroupInspect struct {
Config EndpointGroup
Oper EndpointGroupOper
}
type ExtContractsGroup struct {
// every object has a key
Key string `json:"key,omitempty"`
Contracts []string `json:"contracts,omitempty"`
ContractsGroupName string `json:"contractsGroupName,omitempty"` // Contracts group name
ContractsType string `json:"contractsType,omitempty"` // Contracts type
TenantName string `json:"tenantName,omitempty"` // Tenant name
// add link-sets and links
LinkSets ExtContractsGroupLinkSets `json:"link-sets,omitempty"`
}
type ExtContractsGroupLinkSets struct {
EndpointGroups map[string]modeldb.Link `json:"EndpointGroups,omitempty"`
}
type ExtContractsGroupInspect struct {
Config ExtContractsGroup
}
type Global struct {
// every object has a key
Key string `json:"key,omitempty"`
ArpMode string `json:"arpMode,omitempty"` // ARP Mode
FwdMode string `json:"fwdMode,omitempty"` // Forwarding Mode
Name string `json:"name,omitempty"` // name of this block(must be 'global')
NetworkInfraType string `json:"networkInfraType,omitempty"` // Network infrastructure type
PvtSubnet string `json:"pvtSubnet,omitempty"` // Private Subnet used by host bridge
Vlans string `json:"vlans,omitempty"` // Allowed vlan range
Vxlans string `json:"vxlans,omitempty"` // Allwed vxlan range
}
type GlobalOper struct {
ClusterMode string `json:"clusterMode,omitempty"` //
DefaultNetwork string `json:"defaultNetwork,omitempty"` //
FreeVXLANsStart int `json:"freeVXLANsStart,omitempty"` //
NumNetworks int `json:"numNetworks,omitempty"` //
VlansInUse string `json:"vlansInUse,omitempty"` //
VxlansInUse string `json:"vxlansInUse,omitempty"` //
}
type GlobalInspect struct {
Config Global
Oper GlobalOper
}
type Netprofile struct {
// every object has a key
Key string `json:"key,omitempty"`
DSCP int `json:"DSCP,omitempty"` // DSCP
Bandwidth string `json:"bandwidth,omitempty"` // Allocated bandwidth
Burst int `json:"burst,omitempty"` // burst size
ProfileName string `json:"profileName,omitempty"` // Network profile name
TenantName string `json:"tenantName,omitempty"` // Tenant name
// add link-sets and links
LinkSets NetprofileLinkSets `json:"link-sets,omitempty"`
Links NetprofileLinks `json:"links,omitempty"`
}
type NetprofileLinkSets struct {
EndpointGroups map[string]modeldb.Link `json:"EndpointGroups,omitempty"`
}
type NetprofileLinks struct {
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type NetprofileInspect struct {
Config Netprofile
}
type Network struct {
// every object has a key
Key string `json:"key,omitempty"`
Encap string `json:"encap,omitempty"` // Encapsulation
Gateway string `json:"gateway,omitempty"` // Gateway
Ipv6Gateway string `json:"ipv6Gateway,omitempty"` // IPv6Gateway
Ipv6Subnet string `json:"ipv6Subnet,omitempty"` // IPv6Subnet
NetworkName string `json:"networkName,omitempty"` // Network name
NwType string `json:"nwType,omitempty"` // Network Type
PktTag int `json:"pktTag,omitempty"` // Vlan/Vxlan Tag
Subnet string `json:"subnet,omitempty"` // Subnet
TenantName string `json:"tenantName,omitempty"` // Tenant Name
// add link-sets and links
LinkSets NetworkLinkSets `json:"link-sets,omitempty"`
Links NetworkLinks `json:"links,omitempty"`
}
type NetworkLinkSets struct {
EndpointGroups map[string]modeldb.Link `json:"EndpointGroups,omitempty"`
Servicelbs map[string]modeldb.Link `json:"Servicelbs,omitempty"`
Services map[string]modeldb.Link `json:"Services,omitempty"`
}
type NetworkLinks struct {
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type NetworkOper struct {
AllocatedAddressesCount int `json:"allocatedAddressesCount,omitempty"` // Vlan/Vxlan Tag
AllocatedIPAddresses string `json:"allocatedIPAddresses,omitempty"` // allocated IP addresses
AvailableIPAddresses string `json:"availableIPAddresses,omitempty"` // Available IP addresses
Endpoints []EndpointOper `json:"endpoints,omitempty"`
ExternalPktTag int `json:"externalPktTag,omitempty"` // external packet tag
NumEndpoints int `json:"numEndpoints,omitempty"` // external packet tag
PktTag int `json:"pktTag,omitempty"` // internal packet tag
}
type NetworkInspect struct {
Config Network
Oper NetworkOper
}
type Policy struct {
// every object has a key
Key string `json:"key,omitempty"`
PolicyName string `json:"policyName,omitempty"` // Policy Name
TenantName string `json:"tenantName,omitempty"` // Tenant Name
// add link-sets and links
LinkSets PolicyLinkSets `json:"link-sets,omitempty"`
Links PolicyLinks `json:"links,omitempty"`
}
type PolicyLinkSets struct {
EndpointGroups map[string]modeldb.Link `json:"EndpointGroups,omitempty"`
Rules map[string]modeldb.Link `json:"Rules,omitempty"`
}
type PolicyLinks struct {
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type PolicyOper struct {
Endpoints []EndpointOper `json:"endpoints,omitempty"`
NumEndpoints int `json:"numEndpoints,omitempty"` // number of endpoints
PolicyViolations int `json:"policyViolations,omitempty"` // number of policyViolations
}
type PolicyInspect struct {
Config Policy
Oper PolicyOper
}
type Rule struct {
// every object has a key
Key string `json:"key,omitempty"`
Action string `json:"action,omitempty"` // Action
Direction string `json:"direction,omitempty"` // Direction
FromEndpointGroup string `json:"fromEndpointGroup,omitempty"` // From Endpoint Group
FromIpAddress string `json:"fromIpAddress,omitempty"` // IP Address
FromNetwork string `json:"fromNetwork,omitempty"` // From Network
PolicyName string `json:"policyName,omitempty"` // Policy Name
Port int `json:"port,omitempty"` // Port No
Priority int `json:"priority,omitempty"` // Priority
Protocol string `json:"protocol,omitempty"` // Protocol
RuleID string `json:"ruleId,omitempty"` // Rule Id
TenantName string `json:"tenantName,omitempty"` // Tenant Name
ToEndpointGroup string `json:"toEndpointGroup,omitempty"` // To Endpoint Group
ToIpAddress string `json:"toIpAddress,omitempty"` // IP Address
ToNetwork string `json:"toNetwork,omitempty"` // To Network
// add link-sets and links
LinkSets RuleLinkSets `json:"link-sets,omitempty"`
Links RuleLinks `json:"links,omitempty"`
}
type RuleLinkSets struct {
Policies map[string]modeldb.Link `json:"Policies,omitempty"`
}
type RuleLinks struct {
MatchEndpointGroup modeldb.Link `json:"MatchEndpointGroup,omitempty"`
}
type RuleInspect struct {
Config Rule
}
type ServiceLB struct {
// every object has a key
Key string `json:"key,omitempty"`
IpAddress string `json:"ipAddress,omitempty"` // Service ip
NetworkName string `json:"networkName,omitempty"` // Service network name
Ports []string `json:"ports,omitempty"`
Selectors []string `json:"selectors,omitempty"`
ServiceName string `json:"serviceName,omitempty"` // service name
TenantName string `json:"tenantName,omitempty"` // Tenant Name
Links ServiceLBLinks `json:"links,omitempty"`
}
type ServiceLBLinks struct {
Network modeldb.Link `json:"Network,omitempty"`
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type ServiceLBOper struct {
NumProviders int `json:"numProviders,omitempty"` // number of provider endpoints for the service
Providers []EndpointOper `json:"providers,omitempty"`
ServiceVip string `json:"serviceVip,omitempty"` // allocated IP addresses
}
type ServiceLBInspect struct {
Config ServiceLB
Oper ServiceLBOper
}
type Tenant struct {
// every object has a key
Key string `json:"key,omitempty"`
DefaultNetwork string `json:"defaultNetwork,omitempty"` // Network name
TenantName string `json:"tenantName,omitempty"` // Tenant Name
// add link-sets and links
LinkSets TenantLinkSets `json:"link-sets,omitempty"`
}
type TenantLinkSets struct {
AppProfiles map[string]modeldb.Link `json:"AppProfiles,omitempty"`
EndpointGroups map[string]modeldb.Link `json:"EndpointGroups,omitempty"`
NetProfiles map[string]modeldb.Link `json:"NetProfiles,omitempty"`
Networks map[string]modeldb.Link `json:"Networks,omitempty"`
Policies map[string]modeldb.Link `json:"Policies,omitempty"`
Servicelbs map[string]modeldb.Link `json:"Servicelbs,omitempty"`
VolumeProfiles map[string]modeldb.Link `json:"VolumeProfiles,omitempty"`
Volumes map[string]modeldb.Link `json:"Volumes,omitempty"`
}
type TenantOper struct {
EndpointGroups []EndpointGroupOper `json:"endpointGroups,omitempty"`
Endpoints []EndpointOper `json:"endpoints,omitempty"`
Networks []NetworkOper `json:"networks,omitempty"`
Policies []PolicyOper `json:"policies,omitempty"`
Servicelbs []ServiceLBOper `json:"servicelbs,omitempty"`
TotalAppProfiles int `json:"totalAppProfiles,omitempty"` // total number of App-Profiles
TotalEPGs int `json:"totalEPGs,omitempty"` // total number of EPGs
TotalEndpoints int `json:"totalEndpoints,omitempty"` // total number of endpoints in the tenant
TotalNetprofiles int `json:"totalNetprofiles,omitempty"` // total number of Netprofiles
TotalNetworks int `json:"totalNetworks,omitempty"` // total number of networks
TotalPolicies int `json:"totalPolicies,omitempty"` // total number of totalPolicies
TotalServicelbs int `json:"totalServicelbs,omitempty"` // total number of Servicelbs
}
type TenantInspect struct {
Config Tenant
Oper TenantOper
}
type Volume struct {
// every object has a key
Key string `json:"key,omitempty"`
DatastoreType string `json:"datastoreType,omitempty"` //
MountPoint string `json:"mountPoint,omitempty"` //
PoolName string `json:"poolName,omitempty"` //
Size string `json:"size,omitempty"` //
TenantName string `json:"tenantName,omitempty"` // Tenant Name
VolumeName string `json:"volumeName,omitempty"` // Volume Name
// add link-sets and links
LinkSets VolumeLinkSets `json:"link-sets,omitempty"`
Links VolumeLinks `json:"links,omitempty"`
}
type VolumeLinkSets struct {
ServiceInstances map[string]modeldb.Link `json:"ServiceInstances,omitempty"`
}
type VolumeLinks struct {
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type VolumeInspect struct {
Config Volume
}
type VolumeProfile struct {
// every object has a key
Key string `json:"key,omitempty"`
DatastoreType string `json:"datastoreType,omitempty"` //
MountPoint string `json:"mountPoint,omitempty"` //
PoolName string `json:"poolName,omitempty"` //
Size string `json:"size,omitempty"` //
TenantName string `json:"tenantName,omitempty"` // Tenant Name
VolumeProfileName string `json:"volumeProfileName,omitempty"` // Volume profile Name
// add link-sets and links
LinkSets VolumeProfileLinkSets `json:"link-sets,omitempty"`
Links VolumeProfileLinks `json:"links,omitempty"`
}
type VolumeProfileLinkSets struct {
Services map[string]modeldb.Link `json:"Services,omitempty"`
}
type VolumeProfileLinks struct {
Tenant modeldb.Link `json:"Tenant,omitempty"`
}
type VolumeProfileInspect struct {
Config VolumeProfile
}
type Collections struct {
aciGwMutex sync.Mutex
aciGws map[string]*AciGw
appProfileMutex sync.Mutex
appProfiles map[string]*AppProfile
BgpMutex sync.Mutex
Bgps map[string]*Bgp
endpointGroupMutex sync.Mutex
endpointGroups map[string]*EndpointGroup
extContractsGroupMutex sync.Mutex
extContractsGroups map[string]*ExtContractsGroup
globalMutex sync.Mutex
globals map[string]*Global
netprofileMutex sync.Mutex
netprofiles map[string]*Netprofile
networkMutex sync.Mutex
networks map[string]*Network
policyMutex sync.Mutex
policys map[string]*Policy
ruleMutex sync.Mutex
rules map[string]*Rule
serviceLBMutex sync.Mutex
serviceLBs map[string]*ServiceLB
tenantMutex sync.Mutex
tenants map[string]*Tenant
volumeMutex sync.Mutex
volumes map[string]*Volume
volumeProfileMutex sync.Mutex
volumeProfiles map[string]*VolumeProfile
}
var collections Collections
type AciGwCallbacks interface {
AciGwGetOper(aciGw *AciGwInspect) error
AciGwCreate(aciGw *AciGw) error
AciGwUpdate(aciGw, params *AciGw) error
AciGwDelete(aciGw *AciGw) error
}
type AppProfileCallbacks interface {
AppProfileCreate(appProfile *AppProfile) error
AppProfileUpdate(appProfile, params *AppProfile) error
AppProfileDelete(appProfile *AppProfile) error
}
type BgpCallbacks interface {
BgpGetOper(Bgp *BgpInspect) error
BgpCreate(Bgp *Bgp) error
BgpUpdate(Bgp, params *Bgp) error
BgpDelete(Bgp *Bgp) error
}
type EndpointCallbacks interface {
EndpointGetOper(endpoint *EndpointInspect) error
}
type EndpointGroupCallbacks interface {
EndpointGroupGetOper(endpointGroup *EndpointGroupInspect) error
EndpointGroupCreate(endpointGroup *EndpointGroup) error
EndpointGroupUpdate(endpointGroup, params *EndpointGroup) error
EndpointGroupDelete(endpointGroup *EndpointGroup) error
}
type ExtContractsGroupCallbacks interface {
ExtContractsGroupCreate(extContractsGroup *ExtContractsGroup) error
ExtContractsGroupUpdate(extContractsGroup, params *ExtContractsGroup) error
ExtContractsGroupDelete(extContractsGroup *ExtContractsGroup) error
}
type GlobalCallbacks interface {
GlobalGetOper(global *GlobalInspect) error
GlobalCreate(global *Global) error
GlobalUpdate(global, params *Global) error
GlobalDelete(global *Global) error
}
type NetprofileCallbacks interface {
NetprofileCreate(netprofile *Netprofile) error
NetprofileUpdate(netprofile, params *Netprofile) error
NetprofileDelete(netprofile *Netprofile) error
}
type NetworkCallbacks interface {
NetworkGetOper(network *NetworkInspect) error
NetworkCreate(network *Network) error
NetworkUpdate(network, params *Network) error
NetworkDelete(network *Network) error
}
type PolicyCallbacks interface {
PolicyGetOper(policy *PolicyInspect) error
PolicyCreate(policy *Policy) error
PolicyUpdate(policy, params *Policy) error
PolicyDelete(policy *Policy) error
}
type RuleCallbacks interface {
RuleCreate(rule *Rule) error
RuleUpdate(rule, params *Rule) error
RuleDelete(rule *Rule) error
}
type ServiceLBCallbacks interface {
ServiceLBGetOper(serviceLB *ServiceLBInspect) error
ServiceLBCreate(serviceLB *ServiceLB) error
ServiceLBUpdate(serviceLB, params *ServiceLB) error
ServiceLBDelete(serviceLB *ServiceLB) error
}
type TenantCallbacks interface {
TenantGetOper(tenant *TenantInspect) error
TenantCreate(tenant *Tenant) error
TenantUpdate(tenant, params *Tenant) error
TenantDelete(tenant *Tenant) error
}
type VolumeCallbacks interface {
VolumeCreate(volume *Volume) error
VolumeUpdate(volume, params *Volume) error
VolumeDelete(volume *Volume) error
}
type VolumeProfileCallbacks interface {
VolumeProfileCreate(volumeProfile *VolumeProfile) error
VolumeProfileUpdate(volumeProfile, params *VolumeProfile) error
VolumeProfileDelete(volumeProfile *VolumeProfile) error
}
type CallbackHandlers struct {
AciGwCb AciGwCallbacks
AppProfileCb AppProfileCallbacks
BgpCb BgpCallbacks
EndpointCb EndpointCallbacks
EndpointGroupCb EndpointGroupCallbacks
ExtContractsGroupCb ExtContractsGroupCallbacks
GlobalCb GlobalCallbacks
NetprofileCb NetprofileCallbacks
NetworkCb NetworkCallbacks
PolicyCb PolicyCallbacks
RuleCb RuleCallbacks
ServiceLBCb ServiceLBCallbacks
TenantCb TenantCallbacks
VolumeCb VolumeCallbacks
VolumeProfileCb VolumeProfileCallbacks
}
var objCallbackHandler CallbackHandlers
func Init() {
collections.aciGws = make(map[string]*AciGw)
collections.appProfiles = make(map[string]*AppProfile)
collections.Bgps = make(map[string]*Bgp)
collections.endpointGroups = make(map[string]*EndpointGroup)
collections.extContractsGroups = make(map[string]*ExtContractsGroup)
collections.globals = make(map[string]*Global)
collections.netprofiles = make(map[string]*Netprofile)
collections.networks = make(map[string]*Network)
collections.policys = make(map[string]*Policy)
collections.rules = make(map[string]*Rule)
collections.serviceLBs = make(map[string]*ServiceLB)
collections.tenants = make(map[string]*Tenant)
collections.volumes = make(map[string]*Volume)
collections.volumeProfiles = make(map[string]*VolumeProfile)
restoreAciGw()
restoreAppProfile()
restoreBgp()
restoreEndpointGroup()
restoreExtContractsGroup()
restoreGlobal()
restoreNetprofile()
restoreNetwork()
restorePolicy()
restoreRule()
restoreServiceLB()
restoreTenant()
restoreVolume()
restoreVolumeProfile()
}
func GetAciGwCount() int {
return len(collections.aciGws)
}
func GetAppProfileCount() int {
return len(collections.appProfiles)
}
func GetBgpCount() int {
return len(collections.Bgps)
}
func GetEndpointGroupCount() int {
return len(collections.endpointGroups)
}
func GetExtContractsGroupCount() int {
return len(collections.extContractsGroups)
}
func GetGlobalCount() int {
return len(collections.globals)
}
func GetNetprofileCount() int {
return len(collections.netprofiles)
}
func GetNetworkCount() int {
return len(collections.networks)
}
func GetPolicyCount() int {
return len(collections.policys)
}
func GetRuleCount() int {
return len(collections.rules)
}
func GetServiceLBCount() int {
return len(collections.serviceLBs)
}
func GetTenantCount() int {
return len(collections.tenants)
}
func GetVolumeCount() int {
return len(collections.volumes)
}
func GetVolumeProfileCount() int {
return len(collections.volumeProfiles)
}
func RegisterAciGwCallbacks(handler AciGwCallbacks) {
objCallbackHandler.AciGwCb = handler
}
func RegisterAppProfileCallbacks(handler AppProfileCallbacks) {
objCallbackHandler.AppProfileCb = handler
}
func RegisterBgpCallbacks(handler BgpCallbacks) {
objCallbackHandler.BgpCb = handler
}
func RegisterEndpointCallbacks(handler EndpointCallbacks) {
objCallbackHandler.EndpointCb = handler
}
func RegisterEndpointGroupCallbacks(handler EndpointGroupCallbacks) {
objCallbackHandler.EndpointGroupCb = handler
}
func RegisterExtContractsGroupCallbacks(handler ExtContractsGroupCallbacks) {
objCallbackHandler.ExtContractsGroupCb = handler
}
func RegisterGlobalCallbacks(handler GlobalCallbacks) {
objCallbackHandler.GlobalCb = handler
}
func RegisterNetprofileCallbacks(handler NetprofileCallbacks) {
objCallbackHandler.NetprofileCb = handler
}
func RegisterNetworkCallbacks(handler NetworkCallbacks) {
objCallbackHandler.NetworkCb = handler
}
func RegisterPolicyCallbacks(handler PolicyCallbacks) {
objCallbackHandler.PolicyCb = handler
}
func RegisterRuleCallbacks(handler RuleCallbacks) {
objCallbackHandler.RuleCb = handler
}
func RegisterServiceLBCallbacks(handler ServiceLBCallbacks) {
objCallbackHandler.ServiceLBCb = handler
}
func RegisterTenantCallbacks(handler TenantCallbacks) {
objCallbackHandler.TenantCb = handler
}
func RegisterVolumeCallbacks(handler VolumeCallbacks) {
objCallbackHandler.VolumeCb = handler
}
func RegisterVolumeProfileCallbacks(handler VolumeProfileCallbacks) {
objCallbackHandler.VolumeProfileCb = handler
}
// Simple Wrapper for http handlers
func makeHttpHandler(handlerFunc HttpApiFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(w, r, mux.Vars(r))
if err != nil {
// Log error
log.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL, err)
// Send HTTP response
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
// Send HTTP response as Json
err = writeJSON(w, http.StatusOK, resp)
if err != nil {
log.Errorf("Error generating json. Err: %v", err)
}
}
}
}
// writeJSON: writes the value v to the http response stream as json with standard
// json encoding.
func writeJSON(w http.ResponseWriter, code int, v interface{}) error {
// Set content type as json
w.Header().Set("Content-Type", "application/json")
// write the HTTP status code
w.WriteHeader(code)
// Write the Json output
return json.NewEncoder(w).Encode(v)
}
// Add all routes for REST handlers
func AddRoutes(router *mux.Router) {
var route, listRoute, inspectRoute string
// Register aciGw
route = "/api/v1/aciGws/{key}/"
listRoute = "/api/v1/aciGws/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListAciGws))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetAciGw))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateAciGw))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateAciGw))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteAciGw))
inspectRoute = "/api/v1/inspect/aciGws/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectAciGw))
// Register appProfile
route = "/api/v1/appProfiles/{key}/"
listRoute = "/api/v1/appProfiles/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListAppProfiles))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetAppProfile))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateAppProfile))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateAppProfile))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteAppProfile))
inspectRoute = "/api/v1/inspect/appProfiles/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectAppProfile))
// Register Bgp
route = "/api/v1/Bgps/{key}/"
listRoute = "/api/v1/Bgps/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListBgps))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetBgp))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateBgp))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateBgp))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteBgp))
inspectRoute = "/api/v1/inspect/Bgps/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectBgp))
inspectRoute = "/api/v1/inspect/endpoints/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectEndpoint))
// Register endpointGroup
route = "/api/v1/endpointGroups/{key}/"
listRoute = "/api/v1/endpointGroups/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListEndpointGroups))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetEndpointGroup))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateEndpointGroup))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateEndpointGroup))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteEndpointGroup))
inspectRoute = "/api/v1/inspect/endpointGroups/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectEndpointGroup))
// Register extContractsGroup
route = "/api/v1/extContractsGroups/{key}/"
listRoute = "/api/v1/extContractsGroups/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListExtContractsGroups))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetExtContractsGroup))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateExtContractsGroup))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateExtContractsGroup))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteExtContractsGroup))
inspectRoute = "/api/v1/inspect/extContractsGroups/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectExtContractsGroup))
// Register global
route = "/api/v1/globals/{key}/"
listRoute = "/api/v1/globals/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListGlobals))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetGlobal))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateGlobal))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateGlobal))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteGlobal))
inspectRoute = "/api/v1/inspect/globals/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectGlobal))
// Register netprofile
route = "/api/v1/netprofiles/{key}/"
listRoute = "/api/v1/netprofiles/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListNetprofiles))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetNetprofile))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateNetprofile))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateNetprofile))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteNetprofile))
inspectRoute = "/api/v1/inspect/netprofiles/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectNetprofile))
// Register network
route = "/api/v1/networks/{key}/"
listRoute = "/api/v1/networks/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListNetworks))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetNetwork))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreateNetwork))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreateNetwork))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeleteNetwork))
inspectRoute = "/api/v1/inspect/networks/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectNetwork))
// Register policy
route = "/api/v1/policys/{key}/"
listRoute = "/api/v1/policys/"
log.Infof("Registering %s", route)
router.Path(listRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpListPolicys))
router.Path(route).Methods("GET").HandlerFunc(makeHttpHandler(httpGetPolicy))
router.Path(route).Methods("POST").HandlerFunc(makeHttpHandler(httpCreatePolicy))
router.Path(route).Methods("PUT").HandlerFunc(makeHttpHandler(httpCreatePolicy))
router.Path(route).Methods("DELETE").HandlerFunc(makeHttpHandler(httpDeletePolicy))
inspectRoute = "/api/v1/inspect/policys/{key}/"
router.Path(inspectRoute).Methods("GET").HandlerFunc(makeHttpHandler(httpInspectPolicy))
// Register rule
route = "/api/v1/rules/{key}/"