-
Notifications
You must be signed in to change notification settings - Fork 30
/
rtctrl_set_pref.go
104 lines (89 loc) · 2.86 KB
/
rtctrl_set_pref.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 (
DnrtctrlSetPref = "uni/tn-%s/attr-%s/spref"
RnrtctrlSetPref = "spref"
ParentDnrtctrlSetPref = "uni/tn-%s/attr-%s"
RtctrlsetprefClassName = "rtctrlSetPref"
)
type RtctrlSetPref struct {
BaseAttributes
NameAliasAttribute
RtctrlSetPrefAttributes
}
type RtctrlSetPrefAttributes struct {
Annotation string `json:",omitempty"`
LocalPref string `json:",omitempty"`
Name string `json:",omitempty"`
Type string `json:",omitempty"`
}
func NewRtctrlSetPref(rtctrlSetPrefRn, parentDn, description, nameAlias string, rtctrlSetPrefAttr RtctrlSetPrefAttributes) *RtctrlSetPref {
dn := fmt.Sprintf("%s/%s", parentDn, rtctrlSetPrefRn)
return &RtctrlSetPref{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: RtctrlsetprefClassName,
Rn: rtctrlSetPrefRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
RtctrlSetPrefAttributes: rtctrlSetPrefAttr,
}
}
func (rtctrlSetPref *RtctrlSetPref) ToMap() (map[string]string, error) {
rtctrlSetPrefMap, err := rtctrlSetPref.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := rtctrlSetPref.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(rtctrlSetPrefMap, key, value)
}
A(rtctrlSetPrefMap, "annotation", rtctrlSetPref.Annotation)
A(rtctrlSetPrefMap, "localPref", rtctrlSetPref.LocalPref)
A(rtctrlSetPrefMap, "name", rtctrlSetPref.Name)
A(rtctrlSetPrefMap, "type", rtctrlSetPref.Type)
return rtctrlSetPrefMap, err
}
func RtctrlSetPrefFromContainerList(cont *container.Container, index int) *RtctrlSetPref {
RtctrlSetPrefCont := cont.S("imdata").Index(index).S(RtctrlsetprefClassName, "attributes")
return &RtctrlSetPref{
BaseAttributes{
DistinguishedName: G(RtctrlSetPrefCont, "dn"),
Description: G(RtctrlSetPrefCont, "descr"),
Status: G(RtctrlSetPrefCont, "status"),
ClassName: RtctrlsetprefClassName,
Rn: G(RtctrlSetPrefCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(RtctrlSetPrefCont, "nameAlias"),
},
RtctrlSetPrefAttributes{
Annotation: G(RtctrlSetPrefCont, "annotation"),
LocalPref: G(RtctrlSetPrefCont, "localPref"),
Name: G(RtctrlSetPrefCont, "name"),
Type: G(RtctrlSetPrefCont, "type"),
},
}
}
func RtctrlSetPrefFromContainer(cont *container.Container) *RtctrlSetPref {
return RtctrlSetPrefFromContainerList(cont, 0)
}
func RtctrlSetPrefListFromContainer(cont *container.Container) []*RtctrlSetPref {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*RtctrlSetPref, length)
for i := 0; i < length; i++ {
arr[i] = RtctrlSetPrefFromContainerList(cont, i)
}
return arr
}