-
Notifications
You must be signed in to change notification settings - Fork 29
/
vnsLIf_service.go
96 lines (82 loc) · 2.91 KB
/
vnsLIf_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
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func (sm *ServiceManager) CreateLogicalInterface(name string, parent_dn string, nameAlias string, vnsLIfAttr models.LogicalInterfaceAttributes) (*models.LogicalInterface, error) {
rn := fmt.Sprintf(models.RnvnsLIf, name)
vnsLIf := models.NewLogicalInterface(rn, parent_dn, nameAlias, vnsLIfAttr)
err := sm.Save(vnsLIf)
return vnsLIf, err
}
func (sm *ServiceManager) ReadLogicalInterface(name string, parent_dn string) (*models.LogicalInterface, error) {
dn := fmt.Sprintf(parent_dn+"/"+models.RnvnsLIf, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
vnsLIf := models.LogicalInterfaceFromContainer(cont)
return vnsLIf, nil
}
func (sm *ServiceManager) DeleteLogicalInterface(name string, parent_dn string) error {
dn := fmt.Sprintf(parent_dn+"/"+models.RnvnsLIf, name)
return sm.DeleteByDn(dn, models.VnslifClassName)
}
func (sm *ServiceManager) UpdateLogicalInterface(name string, parent_dn string, nameAlias string, vnsLIfAttr models.LogicalInterfaceAttributes) (*models.LogicalInterface, error) {
rn := fmt.Sprintf(models.RnvnsLIf, name)
vnsLIf := models.NewLogicalInterface(rn, parent_dn, nameAlias, vnsLIfAttr)
vnsLIf.Status = "modified"
err := sm.Save(vnsLIf)
return vnsLIf, err
}
func (sm *ServiceManager) ListLogicalInterface(parent_dn string) ([]*models.LogicalInterface, error) {
dnUrl := fmt.Sprintf(models.BaseurlStr + "/" + parent_dn + "/vnsLIf.json")
cont, err := sm.GetViaURL(dnUrl)
list := models.LogicalInterfaceListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationvnsRsCIfAttN(parentDn, annotation, tDn string) error {
dn := fmt.Sprintf("%s/rscIfAttN-[%s]", parentDn, tDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tDn": "%s"
}
}
}`, "vnsRsCIfAttN", 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) DeleteRelationvnsRsCIfAttN(parentDn, tDn string) error {
dn := fmt.Sprintf("%s/rscIfAttN-[%s]", parentDn, tDn)
return sm.DeleteByDn(dn, "vnsRsCIfAttN")
}
func (sm *ServiceManager) ReadRelationvnsRsCIfAttN(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsCIfAttN")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "vnsRsCIfAttN")
st := &schema.Set{
F: schema.HashString,
}
for _, contItem := range contList {
dat := models.G(contItem, "tDn")
st.Add(dat)
}
return st, err
}