-
Notifications
You must be signed in to change notification settings - Fork 29
/
cloudRouterP_service.go
191 lines (150 loc) · 5.63 KB
/
cloudRouterP_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package client
import (
"fmt"
"log"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateCloudVpnGateway(name string, cloudContextProfile string, tenant string, description string, cloudRouterPattr models.CloudVpnGatewayAttributes) (*models.CloudVpnGateway, error) {
rn := fmt.Sprintf("routerp-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s/ctxprofile-%s", tenant, cloudContextProfile)
cloudRouterP := models.NewCloudVpnGateway(rn, parentDn, description, cloudRouterPattr)
err := sm.Save(cloudRouterP)
return cloudRouterP, err
}
func (sm *ServiceManager) ReadCloudVpnGateway(name string, cloudContextProfile string, tenant string) (*models.CloudVpnGateway, error) {
dn := fmt.Sprintf("uni/tn-%s/ctxprofile-%s/routerp-%s", tenant, cloudContextProfile, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
cloudRouterP := models.CloudVpnGatewayFromContainer(cont)
return cloudRouterP, nil
}
func (sm *ServiceManager) DeleteCloudVpnGateway(name string, cloudContextProfile string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/ctxprofile-%s/routerp-%s", tenant, cloudContextProfile, name)
return sm.DeleteByDn(dn, models.CloudrouterpClassName)
}
func (sm *ServiceManager) UpdateCloudVpnGateway(name string, cloudContextProfile string, tenant string, description string, cloudRouterPattr models.CloudVpnGatewayAttributes) (*models.CloudVpnGateway, error) {
rn := fmt.Sprintf("routerp-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s/ctxprofile-%s", tenant, cloudContextProfile)
cloudRouterP := models.NewCloudVpnGateway(rn, parentDn, description, cloudRouterPattr)
cloudRouterP.Status = "modified"
err := sm.Save(cloudRouterP)
return cloudRouterP, err
}
func (sm *ServiceManager) ListCloudVpnGateway(cloudContextProfile string, tenant string) ([]*models.CloudVpnGateway, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/ctxprofile-%s/cloudRouterP.json", baseurlStr, tenant, cloudContextProfile)
cont, err := sm.GetViaURL(dnUrl)
list := models.CloudVpnGatewayListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationcloudRsToVpnGwPolFromCloudVpnGateway(parentDn, tnCloudVpnGwPolName string) error {
dn := fmt.Sprintf("%s/rstoVpnGwPol", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tnCloudVpnGwPolName": "%s","annotation": "orchestrator:terraform"
}
}
}`, "cloudRsToVpnGwPol", dn, tnCloudVpnGwPolName))
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) ReadRelationcloudRsToVpnGwPolFromCloudVpnGateway(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "cloudRsToVpnGwPol")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "cloudRsToVpnGwPol")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}
func (sm *ServiceManager) CreateRelationcloudRsToDirectConnPolFromCloudVpnGateway(parentDn, tnCloudDirectConnPolName string) error {
dn := fmt.Sprintf("%s/rstoDirectConnPol", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tnCloudDirectConnPolName": "%s","annotation": "orchestrator:terraform"
}
}
}`, "cloudRsToDirectConnPol", dn, tnCloudDirectConnPolName))
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) ReadRelationcloudRsToDirectConnPolFromCloudVpnGateway(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "cloudRsToDirectConnPol")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "cloudRsToDirectConnPol")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}
func (sm *ServiceManager) CreateRelationcloudRsToHostRouterPolFromCloudVpnGateway(parentDn, tnCloudHostRouterPolName string) error {
dn := fmt.Sprintf("%s/rstoHostRouterPol", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tnCloudHostRouterPolName": "%s","annotation": "orchestrator:terraform"
}
}
}`, "cloudRsToHostRouterPol", dn, tnCloudHostRouterPolName))
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) ReadRelationcloudRsToHostRouterPolFromCloudVpnGateway(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "cloudRsToHostRouterPol")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "cloudRsToHostRouterPol")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}