forked from contiv-experimental/contivmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontivModelClient.go
1278 lines (1035 loc) · 33.6 KB
/
contivModelClient.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
// contivModelClient.go
// This file is auto generated by modelgen tool
// Do not edit this file manually
package client
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
log "github.com/Sirupsen/logrus"
)
// Link is a one way relattion between two objects
type Link struct {
ObjType string `json:"type,omitempty"`
ObjKey string `json:"key,omitempty"`
}
func httpGet(url string, jdata interface{}) error {
r, err := http.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
switch {
case r.StatusCode == int(404):
return errors.New("Page not found!")
case r.StatusCode == int(403):
return errors.New("Access denied!")
case r.StatusCode == int(500):
response, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
return errors.New(string(response))
case r.StatusCode != int(200):
log.Debugf("GET Status '%s' status code %d \n", r.Status, r.StatusCode)
return errors.New(r.Status)
}
response, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
if err := json.Unmarshal(response, jdata); err != nil {
return err
}
return nil
}
func httpDelete(url string) error {
req, err := http.NewRequest("DELETE", url, nil)
r, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer r.Body.Close()
// body, _ := ioutil.ReadAll(r.Body)
switch {
case r.StatusCode == int(404):
// return errors.New("Page not found!")
return nil
case r.StatusCode == int(403):
return errors.New("Access denied!")
case r.StatusCode == int(500):
response, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
return errors.New(string(response))
case r.StatusCode != int(200):
log.Debugf("DELETE Status '%s' status code %d \n", r.Status, r.StatusCode)
return errors.New(r.Status)
}
return nil
}
func httpPost(url string, jdata interface{}) error {
buf, err := json.Marshal(jdata)
if err != nil {
return err
}
body := bytes.NewBuffer(buf)
r, err := http.Post(url, "application/json", body)
if err != nil {
return err
}
defer r.Body.Close()
switch {
case r.StatusCode == int(404):
return errors.New("Page not found!")
case r.StatusCode == int(403):
return errors.New("Access denied!")
case r.StatusCode == int(500):
response, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
return errors.New(string(response))
case r.StatusCode != int(200):
log.Debugf("POST Status '%s' status code %d \n", r.Status, r.StatusCode)
return errors.New(r.Status)
}
response, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
log.Debugf(string(response))
return nil
}
// ContivClient has the contiv model client instance
type ContivClient struct {
baseURL string
}
// NewContivClient returns a new client instance
func NewContivClient(baseURL string) (*ContivClient, error) {
client := ContivClient{
baseURL: baseURL,
}
return &client, nil
}
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"`
NetworkName string `json:"networkName,omitempty"` // Network of App Prof
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]Link `json:"EndpointGroups,omitempty"`
}
type AppProfileLinks struct {
Network Link `json:"Network,omitempty"`
Tenant Link `json:"Tenant,omitempty"`
}
type EndpointGroup struct {
// every object has a key
Key string `json:"key,omitempty"`
EndpointGroupID int `json:"endpointGroupId,omitempty"` // Group Identifier
GroupName string `json:"groupName,omitempty"` // Group 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 {
Policies map[string]Link `json:"Policies,omitempty"`
Services map[string]Link `json:"Services,omitempty"`
}
type EndpointGroupLinks struct {
AppProfile Link `json:"AppProfile,omitempty"`
Network Link `json:"Network,omitempty"`
Tenant Link `json:"Tenant,omitempty"`
}
type Global struct {
// every object has a key
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"` // name of this block
NetworkInfraType string `json:"network-infra-type,omitempty"` // Network infrastructure type
Vlans string `json:"vlans,omitempty"` // Allowed vlan range
Vxlans string `json:"vxlans,omitempty"` // Allwed vxlan range
}
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 Network struct {
// every object has a key
Key string `json:"key,omitempty"`
Encap string `json:"encap,omitempty"` // Encapsulation
Gateway string `json:"gateway,omitempty"` // Gateway
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 {
AppProfiles map[string]Link `json:"AppProfiles,omitempty"`
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
Servicelbs map[string]Link `json:"Servicelbs,omitempty"`
Services map[string]Link `json:"Services,omitempty"`
}
type NetworkLinks struct {
Tenant Link `json:"Tenant,omitempty"`
}
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]Link `json:"EndpointGroups,omitempty"`
Rules map[string]Link `json:"Rules,omitempty"`
}
type PolicyLinks struct {
Tenant Link `json:"Tenant,omitempty"`
}
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"`
}
type RuleLinkSets struct {
Policies map[string]Link `json:"Policies,omitempty"`
}
type Service struct {
// every object has a key
Key string `json:"key,omitempty"`
AppName string `json:"appName,omitempty"` // Application Name
Command string `json:"command,omitempty"` //
Cpu string `json:"cpu,omitempty"` //
EndpointGroups []string `json:"endpointGroups,omitempty"`
Environment []string `json:"environment,omitempty"`
ImageName string `json:"imageName,omitempty"` //
Memory string `json:"memory,omitempty"` //
Networks []string `json:"networks,omitempty"`
Scale int `json:"scale,omitempty"` //
ServiceName string `json:"serviceName,omitempty"` // Service Name
TenantName string `json:"tenantName,omitempty"` // Tenant Name
VolumeProfile string `json:"volumeProfile,omitempty"` //
// add link-sets and links
LinkSets ServiceLinkSets `json:"link-sets,omitempty"`
Links ServiceLinks `json:"links,omitempty"`
}
type ServiceLinkSets struct {
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
Instances map[string]Link `json:"Instances,omitempty"`
Networks map[string]Link `json:"Networks,omitempty"`
}
type ServiceLinks struct {
App Link `json:"App,omitempty"`
VolumeProfile Link `json:"VolumeProfile,omitempty"`
}
type ServiceInstance struct {
// every object has a key
Key string `json:"key,omitempty"`
AppName string `json:"appName,omitempty"` //
InstanceID string `json:"instanceId,omitempty"` // Service instance id
ServiceName string `json:"serviceName,omitempty"` //
TenantName string `json:"tenantName,omitempty"` // Tenant Name
Volumes []string `json:"volumes,omitempty"`
// add link-sets and links
LinkSets ServiceInstanceLinkSets `json:"link-sets,omitempty"`
Links ServiceInstanceLinks `json:"links,omitempty"`
}
type ServiceInstanceLinkSets struct {
Volumes map[string]Link `json:"Volumes,omitempty"`
}
type ServiceInstanceLinks struct {
Service Link `json:"Service,omitempty"`
}
type ServiceLB struct {
// every object has a key
Key string `json:"key,omitempty"`
IpAddress string `json:"ipAddress,omitempty"` // Service ip
Network string `json:"network,omitempty"` // Service subnet
Ports []string `json:"ports,omitempty"`
Selectors []string `json:"selectors,omitempty"`
ServiceName string `json:"serviceName,omitempty"` // service name
TenantName string `json:"tenantName,omitempty"` // Tenant Name
}
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]Link `json:"AppProfiles,omitempty"`
EndpointGroups map[string]Link `json:"EndpointGroups,omitempty"`
Networks map[string]Link `json:"Networks,omitempty"`
Policies map[string]Link `json:"Policies,omitempty"`
Servicelbs map[string]Link `json:"Servicelbs,omitempty"`
VolumeProfiles map[string]Link `json:"VolumeProfiles,omitempty"`
Volumes map[string]Link `json:"Volumes,omitempty"`
}
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]Link `json:"ServiceInstances,omitempty"`
}
type VolumeLinks struct {
Tenant Link `json:"Tenant,omitempty"`
}
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]Link `json:"Services,omitempty"`
}
type VolumeProfileLinks struct {
Tenant Link `json:"Tenant,omitempty"`
}
// AppProfilePost posts the appProfile object
func (c *ContivClient) AppProfilePost(obj *AppProfile) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.NetworkName + ":" + obj.AppProfileName
url := c.baseURL + "/api/appProfiles/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating appProfile %+v. Err: %v", obj, err)
return err
}
return nil
}
// AppProfileList lists all appProfile objects
func (c *ContivClient) AppProfileList() (*[]*AppProfile, error) {
// build key and URL
url := c.baseURL + "/api/appProfiles/"
// http get the object
var objList []*AppProfile
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting appProfiles. Err: %v", err)
return nil, err
}
return &objList, nil
}
// AppProfileGet gets the appProfile object
func (c *ContivClient) AppProfileGet(tenantName string, networkName string, appProfileName string) (*AppProfile, error) {
// build key and URL
keyStr := tenantName + ":" + networkName + ":" + appProfileName
url := c.baseURL + "/api/appProfiles/" + keyStr + "/"
// http get the object
var obj AppProfile
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting appProfile %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// AppProfileDelete deletes the appProfile object
func (c *ContivClient) AppProfileDelete(tenantName string, networkName string, appProfileName string) error {
// build key and URL
keyStr := tenantName + ":" + networkName + ":" + appProfileName
url := c.baseURL + "/api/appProfiles/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting appProfile %s. Err: %v", keyStr, err)
return err
}
return nil
}
// EndpointGroupPost posts the endpointGroup object
func (c *ContivClient) EndpointGroupPost(obj *EndpointGroup) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.NetworkName + ":" + obj.GroupName
url := c.baseURL + "/api/endpointGroups/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating endpointGroup %+v. Err: %v", obj, err)
return err
}
return nil
}
// EndpointGroupList lists all endpointGroup objects
func (c *ContivClient) EndpointGroupList() (*[]*EndpointGroup, error) {
// build key and URL
url := c.baseURL + "/api/endpointGroups/"
// http get the object
var objList []*EndpointGroup
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting endpointGroups. Err: %v", err)
return nil, err
}
return &objList, nil
}
// EndpointGroupGet gets the endpointGroup object
func (c *ContivClient) EndpointGroupGet(tenantName string, networkName string, groupName string) (*EndpointGroup, error) {
// build key and URL
keyStr := tenantName + ":" + networkName + ":" + groupName
url := c.baseURL + "/api/endpointGroups/" + keyStr + "/"
// http get the object
var obj EndpointGroup
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting endpointGroup %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// EndpointGroupDelete deletes the endpointGroup object
func (c *ContivClient) EndpointGroupDelete(tenantName string, networkName string, groupName string) error {
// build key and URL
keyStr := tenantName + ":" + networkName + ":" + groupName
url := c.baseURL + "/api/endpointGroups/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting endpointGroup %s. Err: %v", keyStr, err)
return err
}
return nil
}
// GlobalPost posts the global object
func (c *ContivClient) GlobalPost(obj *Global) error {
// build key and URL
keyStr := obj.Name
url := c.baseURL + "/api/globals/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating global %+v. Err: %v", obj, err)
return err
}
return nil
}
// GlobalList lists all global objects
func (c *ContivClient) GlobalList() (*[]*Global, error) {
// build key and URL
url := c.baseURL + "/api/globals/"
// http get the object
var objList []*Global
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting globals. Err: %v", err)
return nil, err
}
return &objList, nil
}
// GlobalGet gets the global object
func (c *ContivClient) GlobalGet(name string) (*Global, error) {
// build key and URL
keyStr := name
url := c.baseURL + "/api/globals/" + keyStr + "/"
// http get the object
var obj Global
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting global %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// GlobalDelete deletes the global object
func (c *ContivClient) GlobalDelete(name string) error {
// build key and URL
keyStr := name
url := c.baseURL + "/api/globals/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting global %s. Err: %v", keyStr, err)
return err
}
return nil
}
// BgpPost posts the Bgp object
func (c *ContivClient) BgpPost(obj *Bgp) error {
// build key and URL
keyStr := obj.Hostname
url := c.baseURL + "/api/Bgps/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating Bgp %+v. Err: %v", obj, err)
return err
}
return nil
}
// BgpList lists all Bgp objects
func (c *ContivClient) BgpList() (*[]*Bgp, error) {
// build key and URL
url := c.baseURL + "/api/Bgps/"
// http get the object
var objList []*Bgp
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting Bgps. Err: %v", err)
return nil, err
}
return &objList, nil
}
// BgpGet gets the Bgp object
func (c *ContivClient) BgpGet(hostname string) (*Bgp, error) {
// build key and URL
keyStr := hostname
url := c.baseURL + "/api/Bgps/" + keyStr + "/"
// http get the object
var obj Bgp
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting Bgp %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// BgpDelete deletes the Bgp object
func (c *ContivClient) BgpDelete(hostname string) error {
// build key and URL
keyStr := hostname
url := c.baseURL + "/api/Bgps/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting Bgp %s. Err: %v", keyStr, err)
return err
}
return nil
}
// NetworkPost posts the network object
func (c *ContivClient) NetworkPost(obj *Network) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.NetworkName
url := c.baseURL + "/api/networks/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating network %+v. Err: %v", obj, err)
return err
}
return nil
}
// NetworkList lists all network objects
func (c *ContivClient) NetworkList() (*[]*Network, error) {
// build key and URL
url := c.baseURL + "/api/networks/"
// http get the object
var objList []*Network
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting networks. Err: %v", err)
return nil, err
}
return &objList, nil
}
// NetworkGet gets the network object
func (c *ContivClient) NetworkGet(tenantName string, networkName string) (*Network, error) {
// build key and URL
keyStr := tenantName + ":" + networkName
url := c.baseURL + "/api/networks/" + keyStr + "/"
// http get the object
var obj Network
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting network %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// NetworkDelete deletes the network object
func (c *ContivClient) NetworkDelete(tenantName string, networkName string) error {
// build key and URL
keyStr := tenantName + ":" + networkName
url := c.baseURL + "/api/networks/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting network %s. Err: %v", keyStr, err)
return err
}
return nil
}
// PolicyPost posts the policy object
func (c *ContivClient) PolicyPost(obj *Policy) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.PolicyName
url := c.baseURL + "/api/policys/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating policy %+v. Err: %v", obj, err)
return err
}
return nil
}
// PolicyList lists all policy objects
func (c *ContivClient) PolicyList() (*[]*Policy, error) {
// build key and URL
url := c.baseURL + "/api/policys/"
// http get the object
var objList []*Policy
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting policys. Err: %v", err)
return nil, err
}
return &objList, nil
}
// PolicyGet gets the policy object
func (c *ContivClient) PolicyGet(tenantName string, policyName string) (*Policy, error) {
// build key and URL
keyStr := tenantName + ":" + policyName
url := c.baseURL + "/api/policys/" + keyStr + "/"
// http get the object
var obj Policy
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting policy %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// PolicyDelete deletes the policy object
func (c *ContivClient) PolicyDelete(tenantName string, policyName string) error {
// build key and URL
keyStr := tenantName + ":" + policyName
url := c.baseURL + "/api/policys/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting policy %s. Err: %v", keyStr, err)
return err
}
return nil
}
// RulePost posts the rule object
func (c *ContivClient) RulePost(obj *Rule) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.PolicyName + ":" + obj.RuleID
url := c.baseURL + "/api/rules/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating rule %+v. Err: %v", obj, err)
return err
}
return nil
}
// RuleList lists all rule objects
func (c *ContivClient) RuleList() (*[]*Rule, error) {
// build key and URL
url := c.baseURL + "/api/rules/"
// http get the object
var objList []*Rule
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting rules. Err: %v", err)
return nil, err
}
return &objList, nil
}
// RuleGet gets the rule object
func (c *ContivClient) RuleGet(tenantName string, policyName string, ruleId string) (*Rule, error) {
// build key and URL
keyStr := tenantName + ":" + policyName + ":" + ruleId
url := c.baseURL + "/api/rules/" + keyStr + "/"
// http get the object
var obj Rule
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting rule %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// RuleDelete deletes the rule object
func (c *ContivClient) RuleDelete(tenantName string, policyName string, ruleId string) error {
// build key and URL
keyStr := tenantName + ":" + policyName + ":" + ruleId
url := c.baseURL + "/api/rules/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting rule %s. Err: %v", keyStr, err)
return err
}
return nil
}
// ServicePost posts the service object
func (c *ContivClient) ServicePost(obj *Service) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.AppName + ":" + obj.ServiceName
url := c.baseURL + "/api/services/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating service %+v. Err: %v", obj, err)
return err
}
return nil
}
// ServiceList lists all service objects
func (c *ContivClient) ServiceList() (*[]*Service, error) {
// build key and URL
url := c.baseURL + "/api/services/"
// http get the object
var objList []*Service
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting services. Err: %v", err)
return nil, err
}
return &objList, nil
}
// ServiceGet gets the service object
func (c *ContivClient) ServiceGet(tenantName string, appName string, serviceName string) (*Service, error) {
// build key and URL
keyStr := tenantName + ":" + appName + ":" + serviceName
url := c.baseURL + "/api/services/" + keyStr + "/"
// http get the object
var obj Service
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting service %+v. Err: %v", keyStr, err)
return nil, err
}
return &obj, nil
}
// ServiceDelete deletes the service object
func (c *ContivClient) ServiceDelete(tenantName string, appName string, serviceName string) error {
// build key and URL
keyStr := tenantName + ":" + appName + ":" + serviceName
url := c.baseURL + "/api/services/" + keyStr + "/"
// http get the object
err := httpDelete(url)
if err != nil {
log.Debugf("Error deleting service %s. Err: %v", keyStr, err)
return err
}
return nil
}
// ServiceInstancePost posts the serviceInstance object
func (c *ContivClient) ServiceInstancePost(obj *ServiceInstance) error {
// build key and URL
keyStr := obj.TenantName + ":" + obj.AppName + ":" + obj.ServiceName + ":" + obj.InstanceID
url := c.baseURL + "/api/serviceInstances/" + keyStr + "/"
// http post the object
err := httpPost(url, obj)
if err != nil {
log.Debugf("Error creating serviceInstance %+v. Err: %v", obj, err)
return err
}
return nil
}
// ServiceInstanceList lists all serviceInstance objects
func (c *ContivClient) ServiceInstanceList() (*[]*ServiceInstance, error) {
// build key and URL
url := c.baseURL + "/api/serviceInstances/"
// http get the object
var objList []*ServiceInstance
err := httpGet(url, &objList)
if err != nil {
log.Debugf("Error getting serviceInstances. Err: %v", err)
return nil, err
}
return &objList, nil
}
// ServiceInstanceGet gets the serviceInstance object
func (c *ContivClient) ServiceInstanceGet(tenantName string, appName string, serviceName string, instanceId string) (*ServiceInstance, error) {
// build key and URL
keyStr := tenantName + ":" + appName + ":" + serviceName + ":" + instanceId
url := c.baseURL + "/api/serviceInstances/" + keyStr + "/"
// http get the object
var obj ServiceInstance
err := httpGet(url, &obj)
if err != nil {
log.Debugf("Error getting serviceInstance %+v. Err: %v", keyStr, err)
return nil, err
}