-
Notifications
You must be signed in to change notification settings - Fork 29
/
bgpPeerP_service.go
152 lines (123 loc) · 5.04 KB
/
bgpPeerP_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package client
import (
"fmt"
"log"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateBgpPeerConnectivityProfile(addr string, logical_node_profile string, l3_outside string, tenant string, description string, bgpPeerPattr models.BgpPeerConnectivityProfileAttributes) (*models.BgpPeerConnectivityProfile, error) {
rn := fmt.Sprintf("peerP-[%s]", addr)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s", tenant, l3_outside, logical_node_profile)
bgpPeerP := models.NewBgpPeerConnectivityProfile(rn, parentDn, description, bgpPeerPattr)
err := sm.Save(bgpPeerP)
return bgpPeerP, err
}
func (sm *ServiceManager) ReadBgpPeerConnectivityProfile(addr string, logical_node_profile string, l3_outside string, tenant string) (*models.BgpPeerConnectivityProfile, error) {
dn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/peerP-[%s]", tenant, l3_outside, logical_node_profile, addr)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
bgpPeerP := models.BgpPeerConnectivityProfileFromContainer(cont)
return bgpPeerP, nil
}
func (sm *ServiceManager) DeleteBgpPeerConnectivityProfile(addr string, logical_node_profile string, l3_outside string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/peerP-[%s]", tenant, l3_outside, logical_node_profile, addr)
return sm.DeleteByDn(dn, models.BgppeerpClassName)
}
func (sm *ServiceManager) UpdateBgpPeerConnectivityProfile(addr string, logical_node_profile string, l3_outside string, tenant string, description string, bgpPeerPattr models.BgpPeerConnectivityProfileAttributes) (*models.BgpPeerConnectivityProfile, error) {
rn := fmt.Sprintf("peerP-[%s]", addr)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s", tenant, l3_outside, logical_node_profile)
bgpPeerP := models.NewBgpPeerConnectivityProfile(rn, parentDn, description, bgpPeerPattr)
bgpPeerP.Status = "modified"
err := sm.Save(bgpPeerP)
return bgpPeerP, err
}
func (sm *ServiceManager) ListBgpPeerConnectivityProfile(logical_node_profile string, l3_outside string, tenant string) ([]*models.BgpPeerConnectivityProfile, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/out-%s/lnodep-%s/bgpPeerP.json", baseurlStr, tenant, l3_outside, logical_node_profile)
cont, err := sm.GetViaURL(dnUrl)
list := models.BgpPeerConnectivityProfileListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationbgpRsPeerPfxPolFromBgpPeerConnectivityProfile(parentDn, tnBgpPeerPfxPolName string) error {
dn := fmt.Sprintf("%s/rspeerPfxPol", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"tnBgpPeerPfxPolName": "%s",
"annotation":"orchestrator:terraform"}
}
}`, "bgpRsPeerPfxPol", dn, tnBgpPeerPfxPolName))
jsonPayload, err := container.ParseJSON(containerJSON)
if err != nil {
return err
}
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true)
if err != nil {
return err
}
cont, _, err := sm.client.Do(req)
if err != nil {
return err
}
log.Printf("%+v", cont)
return nil
}
func (sm *ServiceManager) ReadRelationbgpRsPeerPfxPolFromBgpPeerConnectivityProfile(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "bgpRsPeerPfxPol")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "bgpRsPeerPfxPol")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}
func (sm *ServiceManager) CreateRelationbgpRsPeerToProfile(parentDn, annotation, direction string, tDn string) error {
dn := fmt.Sprintf("%s/rspeerToProfile-[%s]-%s", parentDn, tDn, direction)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tDn": "%s",
"direction": "%s"
}
}
}`, "bgpRsPeerToProfile", dn, annotation, tDn, direction))
jsonPayload, err := container.ParseJSON(containerJSON)
if err != nil {
return err
}
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true)
if err != nil {
return err
}
cont, _, err := sm.client.Do(req)
if err != nil {
return err
}
log.Printf("%+v", cont)
return nil
}
func (sm *ServiceManager) DeleteRelationbgpRsPeerToProfile(parentDn, tDn, direction string) error {
dn := fmt.Sprintf("%s/rspeerToProfile-[%s]-%s", parentDn, tDn, direction)
return sm.DeleteByDn(dn, "bgpRsPeerToProfile")
}
func (sm *ServiceManager) ReadRelationbgpRsPeerToProfile(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "bgpRsPeerToProfile")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "bgpRsPeerToProfile")
st := make([]map[string]string, 0)
for _, contItem := range contList {
paramMap := make(map[string]string)
paramMap["target_dn"] = models.G(contItem, "tDn")
paramMap["direction"] = models.G(contItem, "direction")
st = append(st, paramMap)
}
return st, err
}