-
Notifications
You must be signed in to change notification settings - Fork 29
/
rtctrlScope_service.go
93 lines (81 loc) · 3.63 KB
/
rtctrlScope_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
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateRouteContextScope(route_control_context string, route_control_profile string, tenant string, description string, nameAlias string, rtctrlScopeAttr models.RouteContextScopeAttributes) (*models.RouteContextScope, error) {
rn := fmt.Sprintf(models.RnrtctrlScope)
parentDn := fmt.Sprintf(models.ParentDnrtctrlScope, tenant, route_control_profile, route_control_context)
rtctrlScope := models.NewRouteContextScope(rn, parentDn, description, nameAlias, rtctrlScopeAttr)
err := sm.Save(rtctrlScope)
return rtctrlScope, err
}
func (sm *ServiceManager) ReadRouteContextScope(route_control_context string, route_control_profile string, tenant string) (*models.RouteContextScope, error) {
dn := fmt.Sprintf(models.DnrtctrlScope, tenant, route_control_profile, route_control_context)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
rtctrlScope := models.RouteContextScopeFromContainer(cont)
return rtctrlScope, nil
}
func (sm *ServiceManager) DeleteRouteContextScope(route_control_context string, route_control_profile string, tenant string) error {
dn := fmt.Sprintf(models.DnrtctrlScope, tenant, route_control_profile, route_control_context)
return sm.DeleteByDn(dn, models.RtctrlscopeClassName)
}
func (sm *ServiceManager) UpdateRouteContextScope(route_control_context string, route_control_profile string, tenant string, description string, nameAlias string, rtctrlScopeAttr models.RouteContextScopeAttributes) (*models.RouteContextScope, error) {
rn := fmt.Sprintf(models.RnrtctrlScope)
parentDn := fmt.Sprintf(models.ParentDnrtctrlScope, tenant, route_control_profile, route_control_context)
rtctrlScope := models.NewRouteContextScope(rn, parentDn, description, nameAlias, rtctrlScopeAttr)
rtctrlScope.Status = "modified"
err := sm.Save(rtctrlScope)
return rtctrlScope, err
}
func (sm *ServiceManager) ListRouteContextScope(route_control_context string, route_control_profile string, tenant string) ([]*models.RouteContextScope, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/prof-%s/ctx-%s/rtctrlScope.json", models.BaseurlStr, tenant, route_control_profile, route_control_context)
cont, err := sm.GetViaURL(dnUrl)
list := models.RouteContextScopeListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationrtctrlRsScopeToAttrP(parentDn, annotation, tnRtctrlAttrPName string) error {
dn := fmt.Sprintf("%s/rsScopeToAttrP", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tnRtctrlAttrPName": "%s"
}
}
}`, "rtctrlRsScopeToAttrP", dn, annotation, tnRtctrlAttrPName))
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) DeleteRelationrtctrlRsScopeToAttrP(parentDn string) error {
dn := fmt.Sprintf("%s/rsScopeToAttrP", parentDn)
return sm.DeleteByDn(dn, "rtctrlRsScopeToAttrP")
}
func (sm *ServiceManager) ReadRelationrtctrlRsScopeToAttrP(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "rtctrlRsScopeToAttrP")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "rtctrlRsScopeToAttrP")
if len(contList) > 0 {
dat := models.G(contList[0], "tnRtctrlAttrPName")
return dat, err
} else {
return nil, err
}
}