-
Notifications
You must be signed in to change notification settings - Fork 29
/
vzCPIf_service.go
105 lines (82 loc) · 2.9 KB
/
vzCPIf_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
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateImportedContract(name string, tenant string, description string, vzCPIfattr models.ImportedContractAttributes) (*models.ImportedContract, error) {
rn := fmt.Sprintf("cif-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s", tenant)
vzCPIf := models.NewImportedContract(rn, parentDn, description, vzCPIfattr)
err := sm.Save(vzCPIf)
return vzCPIf, err
}
func (sm *ServiceManager) ReadImportedContract(name string, tenant string) (*models.ImportedContract, error) {
dn := fmt.Sprintf("uni/tn-%s/cif-%s", tenant, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
vzCPIf := models.ImportedContractFromContainer(cont)
return vzCPIf, nil
}
func (sm *ServiceManager) DeleteImportedContract(name string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/cif-%s", tenant, name)
return sm.DeleteByDn(dn, models.VzcpifClassName)
}
func (sm *ServiceManager) UpdateImportedContract(name string, tenant string, description string, vzCPIfattr models.ImportedContractAttributes) (*models.ImportedContract, error) {
rn := fmt.Sprintf("cif-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s", tenant)
vzCPIf := models.NewImportedContract(rn, parentDn, description, vzCPIfattr)
vzCPIf.Status = "modified"
err := sm.Save(vzCPIf)
return vzCPIf, err
}
func (sm *ServiceManager) ListImportedContract(tenant string) ([]*models.ImportedContract, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/vzCPIf.json", baseurlStr, tenant)
cont, err := sm.GetViaURL(dnUrl)
list := models.ImportedContractListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationvzRsIfFromImportedContract(parentDn, tnVzACtrctName string) error {
dn := fmt.Sprintf("%s/rsif", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"tDn": "%s"
}
}
}`, "vzRsIf", dn, tnVzACtrctName))
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) DeleteRelationvzRsIfFromImportedContract(parentDn string) error {
dn := fmt.Sprintf("%s/rsif", parentDn)
return sm.DeleteByDn(dn, "vzRsIf")
}
func (sm *ServiceManager) ReadRelationvzRsIfFromImportedContract(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "vzRsIf")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "vzRsIf")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}