-
Notifications
You must be signed in to change notification settings - Fork 29
/
l3extSubnet_service.go
158 lines (121 loc) · 5.25 KB
/
l3extSubnet_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
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateL3ExtSubnet(ip string, external_network_instance_profile string, l3_outside string, tenant string, description string, l3extSubnetattr models.L3ExtSubnetAttributes) (*models.L3ExtSubnet, error) {
rn := fmt.Sprintf("extsubnet-[%s]", ip)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/instP-%s", tenant, l3_outside, external_network_instance_profile)
l3extSubnet := models.NewL3ExtSubnet(rn, parentDn, description, l3extSubnetattr)
err := sm.Save(l3extSubnet)
return l3extSubnet, err
}
func (sm *ServiceManager) ReadL3ExtSubnet(ip string, external_network_instance_profile string, l3_outside string, tenant string) (*models.L3ExtSubnet, error) {
dn := fmt.Sprintf("uni/tn-%s/out-%s/instP-%s/extsubnet-[%s]", tenant, l3_outside, external_network_instance_profile, ip)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
l3extSubnet := models.L3ExtSubnetFromContainer(cont)
return l3extSubnet, nil
}
func (sm *ServiceManager) DeleteL3ExtSubnet(ip string, external_network_instance_profile string, l3_outside string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/out-%s/instP-%s/extsubnet-[%s]", tenant, l3_outside, external_network_instance_profile, ip)
return sm.DeleteByDn(dn, models.L3extsubnetClassName)
}
func (sm *ServiceManager) UpdateL3ExtSubnet(ip string, external_network_instance_profile string, l3_outside string, tenant string, description string, l3extSubnetattr models.L3ExtSubnetAttributes) (*models.L3ExtSubnet, error) {
rn := fmt.Sprintf("extsubnet-[%s]", ip)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/instP-%s", tenant, l3_outside, external_network_instance_profile)
l3extSubnet := models.NewL3ExtSubnet(rn, parentDn, description, l3extSubnetattr)
l3extSubnet.Status = "modified"
err := sm.Save(l3extSubnet)
return l3extSubnet, err
}
func (sm *ServiceManager) ListL3L3ExtSubnet(external_network_instance_profile string, l3_outside string, tenant string) ([]*models.L3ExtSubnet, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/out-%s/instP-%s/l3extSubnet.json", baseurlStr, tenant, l3_outside, external_network_instance_profile)
cont, err := sm.GetViaURL(dnUrl)
list := models.L3ExtSubnetListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationl3extRsSubnetToProfileFromL3ExtSubnet(parentDn, tnRtctrlProfileName, direction string) error {
dn := fmt.Sprintf("%s/rssubnetToProfile-[%s]-%s", parentDn, tnRtctrlProfileName, direction)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","annotation":"orchestrator:terraform"
}
}
}`, "l3extRsSubnetToProfile", dn))
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
}
_, _, err = sm.client.Do(req)
if err != nil {
return err
}
return nil
}
func (sm *ServiceManager) DeleteRelationl3extRsSubnetToProfileFromL3ExtSubnet(parentDn, tnRtctrlProfileName, direction string) error {
dn := fmt.Sprintf("%s/rssubnetToProfile-[%s]-%s", parentDn, tnRtctrlProfileName, direction)
return sm.DeleteByDn(dn, "l3extRsSubnetToProfile")
}
func (sm *ServiceManager) ReadRelationl3extRsSubnetToProfileFromL3ExtSubnet(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "l3extRsSubnetToProfile")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "l3extRsSubnetToProfile")
st := make([]map[string]string, 0)
for _, contItem := range contList {
paramMap := make(map[string]string)
paramMap["tnRtctrlProfileName"] = models.G(contItem, "tnRtctrlProfileName")
paramMap["direction"] = models.G(contItem, "direction")
st = append(st, paramMap)
}
return st, err
}
func (sm *ServiceManager) CreateRelationl3extRsSubnetToRtSummFromL3ExtSubnet(parentDn, tnRtsumARtSummPolName string) error {
dn := fmt.Sprintf("%s/rsSubnetToRtSumm", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tDn": "%s","annotation":"orchestrator:terraform"
}
}
}`, "l3extRsSubnetToRtSumm", dn, tnRtsumARtSummPolName))
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
}
_, _, err = sm.client.Do(req)
if err != nil {
return err
}
return nil
}
func (sm *ServiceManager) DeleteRelationl3extRsSubnetToRtSummFromL3ExtSubnet(parentDn string) error {
dn := fmt.Sprintf("%s/rsSubnetToRtSumm", parentDn)
return sm.DeleteByDn(dn, "l3extRsSubnetToRtSumm")
}
func (sm *ServiceManager) ReadRelationl3extRsSubnetToRtSummFromL3ExtSubnet(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "l3extRsSubnetToRtSumm")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "l3extRsSubnetToRtSumm")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}