-
Notifications
You must be signed in to change notification settings - Fork 29
/
infraPortBlk_service.go
104 lines (80 loc) · 3.99 KB
/
infraPortBlk_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
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateAccessPortBlock(name string, access_port_selector_type string, access_port_selector string, leaf_interface_profile string, description string, infraPortBlkattr models.AccessPortBlockAttributes) (*models.AccessPortBlock, error) {
rn := fmt.Sprintf("portblk-%s", name)
parentDn := fmt.Sprintf("uni/infra/accportprof-%s/hports-%s-typ-%s", leaf_interface_profile, access_port_selector, access_port_selector_type)
infraPortBlk := models.NewAccessPortBlock(rn, parentDn, description, infraPortBlkattr)
err := sm.Save(infraPortBlk)
return infraPortBlk, err
}
func (sm *ServiceManager) ReadAccessPortBlock(name string, access_port_selector_type string, access_port_selector string, leaf_interface_profile string) (*models.AccessPortBlock, error) {
dn := fmt.Sprintf("uni/infra/accportprof-%s/hports-%s-typ-%s/portblk-%s", leaf_interface_profile, access_port_selector, access_port_selector_type, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
infraPortBlk := models.AccessPortBlockFromContainer(cont)
return infraPortBlk, nil
}
func (sm *ServiceManager) DeleteAccessPortBlock(name string, access_port_selector_type string, access_port_selector string, leaf_interface_profile string) error {
dn := fmt.Sprintf("uni/infra/accportprof-%s/hports-%s-typ-%s/portblk-%s", leaf_interface_profile, access_port_selector, access_port_selector_type, name)
return sm.DeleteByDn(dn, models.InfraportblkClassName)
}
func (sm *ServiceManager) UpdateAccessPortBlock(name string, access_port_selector_type string, access_port_selector string, leaf_interface_profile string, description string, infraPortBlkattr models.AccessPortBlockAttributes) (*models.AccessPortBlock, error) {
rn := fmt.Sprintf("portblk-%s", name)
parentDn := fmt.Sprintf("uni/infra/accportprof-%s/hports-%s-typ-%s", leaf_interface_profile, access_port_selector, access_port_selector_type)
infraPortBlk := models.NewAccessPortBlock(rn, parentDn, description, infraPortBlkattr)
infraPortBlk.Status = "modified"
err := sm.Save(infraPortBlk)
return infraPortBlk, err
}
func (sm *ServiceManager) ListAccessPortBlock(access_port_selector_type string, access_port_selector string, leaf_interface_profile string) ([]*models.AccessPortBlock, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/infra/accportprof-%s/hports-%s-typ-%s/infraPortBlk.json", baseurlStr, leaf_interface_profile, access_port_selector, access_port_selector_type)
cont, err := sm.GetViaURL(dnUrl)
list := models.AccessPortBlockListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationinfraRsAccBndlSubgrpFromAccessPortBlock(parentDn, tnInfraAccBndlSubgrpName string) error {
dn := fmt.Sprintf("%s/rsaccBndlSubgrp", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tDn": "%s","annotation":"orchestrator:terraform"
}
}
}`, "infraRsAccBndlSubgrp", dn, tnInfraAccBndlSubgrpName))
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) DeleteRelationinfraRsAccBndlSubgrpFromAccessPortBlock(parentDn string) error {
dn := fmt.Sprintf("%s/rsaccBndlSubgrp", parentDn)
return sm.DeleteByDn(dn, "infraRsAccBndlSubgrp")
}
func (sm *ServiceManager) ReadRelationinfraRsAccBndlSubgrpFromAccessPortBlock(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "infraRsAccBndlSubgrp")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "infraRsAccBndlSubgrp")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}