-
Notifications
You must be signed in to change notification settings - Fork 30
/
rtctrl_set_as_path_asn.go
104 lines (89 loc) · 2.85 KB
/
rtctrl_set_as_path_asn.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 models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DnrtctrlSetASPathASN = "uni/tn-%s/attr-%s/saspath-%s/asn-%s"
RnrtctrlSetASPathASN = "asn-%s"
ParentDnrtctrlSetASPathASN = "uni/tn-%s/attr-%s/saspath-%s"
RtctrlsetaspathasnClassName = "rtctrlSetASPathASN"
)
type ASNumber struct {
BaseAttributes
NameAliasAttribute
ASNumberAttributes
}
type ASNumberAttributes struct {
Annotation string `json:",omitempty"`
Asn string `json:",omitempty"`
Name string `json:",omitempty"`
Order string `json:",omitempty"`
}
func NewASNumber(rtctrlSetASPathASNRn, parentDn, description, nameAlias string, rtctrlSetASPathASNAttr ASNumberAttributes) *ASNumber {
dn := fmt.Sprintf("%s/%s", parentDn, rtctrlSetASPathASNRn)
return &ASNumber{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: RtctrlsetaspathasnClassName,
Rn: rtctrlSetASPathASNRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
ASNumberAttributes: rtctrlSetASPathASNAttr,
}
}
func (rtctrlSetASPathASN *ASNumber) ToMap() (map[string]string, error) {
rtctrlSetASPathASNMap, err := rtctrlSetASPathASN.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := rtctrlSetASPathASN.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(rtctrlSetASPathASNMap, key, value)
}
A(rtctrlSetASPathASNMap, "annotation", rtctrlSetASPathASN.Annotation)
A(rtctrlSetASPathASNMap, "asn", rtctrlSetASPathASN.Asn)
A(rtctrlSetASPathASNMap, "name", rtctrlSetASPathASN.Name)
A(rtctrlSetASPathASNMap, "order", rtctrlSetASPathASN.Order)
return rtctrlSetASPathASNMap, err
}
func ASNumberFromContainerList(cont *container.Container, index int) *ASNumber {
ASNumberCont := cont.S("imdata").Index(index).S(RtctrlsetaspathasnClassName, "attributes")
return &ASNumber{
BaseAttributes{
DistinguishedName: G(ASNumberCont, "dn"),
Description: G(ASNumberCont, "descr"),
Status: G(ASNumberCont, "status"),
ClassName: RtctrlsetaspathasnClassName,
Rn: G(ASNumberCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(ASNumberCont, "nameAlias"),
},
ASNumberAttributes{
Annotation: G(ASNumberCont, "annotation"),
Asn: G(ASNumberCont, "asn"),
Name: G(ASNumberCont, "name"),
Order: G(ASNumberCont, "order"),
},
}
}
func ASNumberFromContainer(cont *container.Container) *ASNumber {
return ASNumberFromContainerList(cont, 0)
}
func ASNumberListFromContainer(cont *container.Container) []*ASNumber {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*ASNumber, length)
for i := 0; i < length; i++ {
arr[i] = ASNumberFromContainerList(cont, i)
}
return arr
}