-
Notifications
You must be signed in to change notification settings - Fork 29
/
l3extVirtualLIfP_service.go
130 lines (101 loc) · 5.2 KB
/
l3extVirtualLIfP_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package client
import (
"fmt"
"log"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateVirtualLogicalInterfaceProfile(encap string, nodeDn string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string, description string, l3extVirtualLIfPattr models.VirtualLogicalInterfaceProfileAttributes) (*models.VirtualLogicalInterfaceProfile, error) {
rn := fmt.Sprintf("vlifp-[%s]-[%s]", nodeDn, encap)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", tenant, l3_outside, logical_node_profile, logical_interface_profile)
l3extVirtualLIfP := models.NewVirtualLogicalInterfaceProfile(rn, parentDn, description, l3extVirtualLIfPattr)
err := sm.Save(l3extVirtualLIfP)
return l3extVirtualLIfP, err
}
func (sm *ServiceManager) ReadVirtualLogicalInterfaceProfile(encap string, nodeDn string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) (*models.VirtualLogicalInterfaceProfile, error) {
dn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/vlifp-[%s]-[%s]", tenant, l3_outside, logical_node_profile, logical_interface_profile, nodeDn, encap)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
l3extVirtualLIfP := models.VirtualLogicalInterfaceProfileFromContainer(cont)
return l3extVirtualLIfP, nil
}
func (sm *ServiceManager) DeleteVirtualLogicalInterfaceProfile(encap string, nodeDn 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/vlifp-[%s]-[%s]", tenant, l3_outside, logical_node_profile, logical_interface_profile, nodeDn, encap)
return sm.DeleteByDn(dn, models.L3extvirtuallifpClassName)
}
func (sm *ServiceManager) UpdateVirtualLogicalInterfaceProfile(encap string, nodeDn string, logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string, description string, l3extVirtualLIfPattr models.VirtualLogicalInterfaceProfileAttributes) (*models.VirtualLogicalInterfaceProfile, error) {
rn := fmt.Sprintf("vlifp-[%s]-[%s]", nodeDn, encap)
parentDn := fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", tenant, l3_outside, logical_node_profile, logical_interface_profile)
l3extVirtualLIfP := models.NewVirtualLogicalInterfaceProfile(rn, parentDn, description, l3extVirtualLIfPattr)
l3extVirtualLIfP.Status = "modified"
err := sm.Save(l3extVirtualLIfP)
return l3extVirtualLIfP, err
}
func (sm *ServiceManager) ListVirtualLogicalInterfaceProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) ([]*models.VirtualLogicalInterfaceProfile, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/out-%s/lnodep-%s/lifp-%s/l3extVirtualLIfP.json", baseurlStr, tenant, l3_outside, logical_node_profile, logical_interface_profile)
cont, err := sm.GetViaURL(dnUrl)
list := models.VirtualLogicalInterfaceProfileListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationl3extRsDynPathAttFromLogicalInterfaceProfile(parentDn, tDn, addr, forgedTransmit, macChange, promMode string) error {
dn := fmt.Sprintf("%s/rsdynPathAtt-[%s]", parentDn, tDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation":"orchestrator:terraform",
"tDn":"%s"
}
}
}`, "l3extRsDynPathAtt", dn, tDn))
jsonPayload, err := container.ParseJSON(containerJSON)
if err != nil {
return err
}
if addr != "" {
jsonPayload.Set(addr, "l3extRsDynPathAtt", "attributes", "floatingAddr")
}
if forgedTransmit != "" {
jsonPayload.Set(forgedTransmit, "l3extRsDynPathAtt", "attributes", "forgedTransmit")
}
if macChange != "" {
jsonPayload.Set(macChange, "l3extRsDynPathAtt", "attributes", "macChange")
}
if promMode != "" {
jsonPayload.Set(promMode, "l3extRsDynPathAtt", "attributes", "promMode")
}
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
}
log.Printf("%+v", cont)
return CheckForErrors(cont, "POST", sm.client.skipLoggingPayload)
}
func (sm *ServiceManager) DeleteRelationl3extRsDynPathAttFromLogicalInterfaceProfile(parentDn, tDn string) error {
dn := fmt.Sprintf("%s/rsdynPathAtt-[%s]", parentDn, tDn)
return sm.DeleteByDn(dn, "l3extRsDynPathAtt")
}
func (sm *ServiceManager) ReadRelationl3extRsDynPathAttFromLogicalInterfaceProfile(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "l3extRsDynPathAtt")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "l3extRsDynPathAtt")
st := make([]map[string]string, 0)
for _, contItem := range contList {
paramMap := make(map[string]string)
paramMap["tDn"] = models.G(contItem, "tDn")
paramMap["floatingAddr"] = models.G(contItem, "floatingAddr")
paramMap["forgedTransmit"] = models.G(contItem, "forgedTransmit")
paramMap["macChange"] = models.G(contItem, "macChange")
paramMap["promMode"] = models.G(contItem, "promMode")
st = append(st, paramMap)
}
return st, err
}