-
Notifications
You must be signed in to change notification settings - Fork 29
/
hsrpGroupP_service.go
99 lines (77 loc) · 3.78 KB
/
hsrpGroupP_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
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateHSRPGroupProfile(name string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string, description string, hsrpGroupPattr models.HSRPGroupProfileAttributes) (*models.HSRPGroupProfile, error) {
rn := fmt.Sprintf("hsrpIfP/hsrpGroupP-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", tenant, l3_outside, logical_node_profile, logical_interface_profile)
hsrpGroupP := models.NewHSRPGroupProfile(rn, parentDn, description, hsrpGroupPattr)
err := sm.Save(hsrpGroupP)
return hsrpGroupP, err
}
func (sm *ServiceManager) ReadHSRPGroupProfile(name string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) (*models.HSRPGroupProfile, error) {
dn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP/hsrpGroupP-%s", tenant, l3_outside, logical_node_profile, logical_interface_profile, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
hsrpGroupP := models.HSRPGroupProfileFromContainer(cont)
return hsrpGroupP, nil
}
func (sm *ServiceManager) DeleteHSRPGroupProfile(name string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP/hsrpGroupP-%s", tenant, l3_outside, logical_node_profile, logical_interface_profile, name)
return sm.DeleteByDn(dn, models.HsrpgrouppClassName)
}
func (sm *ServiceManager) UpdateHSRPGroupProfile(name string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string, description string, hsrpGroupPattr models.HSRPGroupProfileAttributes) (*models.HSRPGroupProfile, error) {
rn := fmt.Sprintf("hsrpIfP/hsrpGroupP-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", tenant, l3_outside, logical_node_profile, logical_interface_profile)
hsrpGroupP := models.NewHSRPGroupProfile(rn, parentDn, description, hsrpGroupPattr)
hsrpGroupP.Status = "modified"
err := sm.Save(hsrpGroupP)
return hsrpGroupP, err
}
func (sm *ServiceManager) ListHSRPGroupProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) ([]*models.HSRPGroupProfile, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpGroupP.json", baseurlStr, tenant, l3_outside, logical_node_profile, logical_interface_profile)
cont, err := sm.GetViaURL(dnUrl)
list := models.HSRPGroupProfileListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationhsrpRsGroupPolFromHSRPGroupProfile(parentDn, tnHsrpGroupPolName string) error {
dn := fmt.Sprintf("%s/rsGroupPol", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tnHsrpGroupPolName": "%s","annotation":"orchestrator:terraform"
}
}
}`, "hsrpRsGroupPol", dn, tnHsrpGroupPolName))
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) ReadRelationhsrpRsGroupPolFromHSRPGroupProfile(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "hsrpRsGroupPol")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "hsrpRsGroupPol")
if len(contList) > 0 {
dat := models.G(contList[0], "tnHsrpGroupPolName")
return dat, err
} else {
return nil, err
}
}