-
Notifications
You must be signed in to change notification settings - Fork 29
/
vnsLDevVip_service.go
172 lines (150 loc) · 5 KB
/
vnsLDevVip_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
package client
import (
"encoding/json"
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateL4ToL7Devices(name string, tenant string, nameAlias string, vnsLDevVipAttr models.L4ToL7DevicesAttributes) (*models.L4ToL7Devices, error) {
rn := fmt.Sprintf(models.RnvnsLDevVip, name)
parentDn := fmt.Sprintf(models.ParentDnvnsLDevVip, tenant)
vnsLDevVip := models.NewL4ToL7Devices(rn, parentDn, nameAlias, vnsLDevVipAttr)
err := sm.Save(vnsLDevVip)
return vnsLDevVip, err
}
func (sm *ServiceManager) ReadL4ToL7Devices(name string, tenant string) (*models.L4ToL7Devices, error) {
dn := fmt.Sprintf(models.DnvnsLDevVip, tenant, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
vnsLDevVip := models.L4ToL7DevicesFromContainer(cont)
return vnsLDevVip, nil
}
func (sm *ServiceManager) DeleteL4ToL7Devices(name string, tenant string) error {
dn := fmt.Sprintf(models.DnvnsLDevVip, tenant, name)
return sm.DeleteByDn(dn, models.VnsldevvipClassName)
}
func (sm *ServiceManager) UpdateL4ToL7Devices(name string, tenant string, nameAlias string, vnsLDevVipAttr models.L4ToL7DevicesAttributes) (*models.L4ToL7Devices, error) {
rn := fmt.Sprintf(models.RnvnsLDevVip, name)
parentDn := fmt.Sprintf(models.ParentDnvnsLDevVip, tenant)
vnsLDevVip := models.NewL4ToL7Devices(rn, parentDn, nameAlias, vnsLDevVipAttr)
vnsLDevVip.Status = "modified"
err := sm.Save(vnsLDevVip)
return vnsLDevVip, err
}
func (sm *ServiceManager) ListL4ToL7Devices(tenant string) ([]*models.L4ToL7Devices, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/vnsLDevVip.json", models.BaseurlStr, tenant)
cont, err := sm.GetViaURL(dnUrl)
list := models.L4ToL7DevicesListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationvnsRsALDevToDomP(parentDn, annotation, switchingMode string, tDn string) error {
dn := fmt.Sprintf("%s/rsALDevToDomP", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tDn": "%s"
}
}
}`, "vnsRsALDevToDomP", dn, annotation, tDn))
attributes := map[string]interface{}{
"switchingMode": switchingMode,
}
var output map[string]interface{}
err_output := json.Unmarshal([]byte(containerJSON), &output)
if err_output != nil {
return err_output
}
for _, mo := range output {
if mo_map, ok := mo.(map[string]interface{}); ok {
for _, mo_attributes := range mo_map {
if mo_attributes_map, ok := mo_attributes.(map[string]interface{}); ok {
for key, value := range attributes {
if value != "" {
mo_attributes_map[key] = value
}
}
}
}
}
}
input, out_err := json.Marshal(output)
if out_err != nil {
return out_err
}
jsonPayload, err := container.ParseJSON(input)
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
}
fmt.Printf("%+v", cont)
return nil
}
func (sm *ServiceManager) DeleteRelationvnsRsALDevToDomP(parentDn string) error {
dn := fmt.Sprintf("%s/rsALDevToDomP", parentDn)
return sm.DeleteByDn(dn, "vnsRsALDevToDomP")
}
func (sm *ServiceManager) ReadRelationvnsRsALDevToDomP(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsALDevToDomP")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "vnsRsALDevToDomP")
st := make([]map[string]string, 0, 1)
for _, contItem := range contList {
paramMap := make(map[string]string)
paramMap["switchingMode"] = models.G(contItem, "switchingMode")
paramMap["tDn"] = models.G(contItem, "tDn")
st = append(st, paramMap)
}
return st, err
}
func (sm *ServiceManager) CreateRelationvnsRsALDevToPhysDomP(parentDn, annotation, tDn string) error {
dn := fmt.Sprintf("%s/rsALDevToPhysDomP", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tDn": "%s"
}
}
}`, "vnsRsALDevToPhysDomP", dn, annotation, tDn))
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
}
fmt.Printf("%+v", cont)
return nil
}
func (sm *ServiceManager) DeleteRelationvnsRsALDevToPhysDomP(parentDn string) error {
dn := fmt.Sprintf("%s/rsALDevToPhysDomP", parentDn)
return sm.DeleteByDn(dn, "vnsRsALDevToPhysDomP")
}
func (sm *ServiceManager) ReadRelationvnsRsALDevToPhysDomP(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsALDevToPhysDomP")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "vnsRsALDevToPhysDomP")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}