-
Notifications
You must be signed in to change notification settings - Fork 30
/
rtctrl_subj_p.go
93 lines (83 loc) · 2.41 KB
/
rtctrl_subj_p.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 models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DnrtctrlSubjP = "uni/tn-%s/subj-%s"
RnrtctrlSubjP = "subj-%s"
ParentDnrtctrlSubjP = "uni/tn-%s"
RtctrlsubjpClassName = "rtctrlSubjP"
)
type MatchRule struct {
BaseAttributes
NameAliasAttribute
MatchRuleAttributes
}
type MatchRuleAttributes struct {
Annotation string `json:",omitempty"`
Name string `json:",omitempty"`
}
func NewMatchRule(rtctrlSubjPRn, parentDn, description, nameAlias string, rtctrlSubjPAttr MatchRuleAttributes) *MatchRule {
dn := fmt.Sprintf("%s/%s", parentDn, rtctrlSubjPRn)
return &MatchRule{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: RtctrlsubjpClassName,
Rn: rtctrlSubjPRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
MatchRuleAttributes: rtctrlSubjPAttr,
}
}
func (rtctrlSubjP *MatchRule) ToMap() (map[string]string, error) {
rtctrlSubjPMap, err := rtctrlSubjP.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := rtctrlSubjP.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(rtctrlSubjPMap, key, value)
}
A(rtctrlSubjPMap, "annotation", rtctrlSubjP.Annotation)
A(rtctrlSubjPMap, "name", rtctrlSubjP.Name)
return rtctrlSubjPMap, err
}
func MatchRuleFromContainerList(cont *container.Container, index int) *MatchRule {
MatchRuleCont := cont.S("imdata").Index(index).S(RtctrlsubjpClassName, "attributes")
return &MatchRule{
BaseAttributes{
DistinguishedName: G(MatchRuleCont, "dn"),
Description: G(MatchRuleCont, "descr"),
Status: G(MatchRuleCont, "status"),
ClassName: RtctrlsubjpClassName,
Rn: G(MatchRuleCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(MatchRuleCont, "nameAlias"),
},
MatchRuleAttributes{
Annotation: G(MatchRuleCont, "annotation"),
Name: G(MatchRuleCont, "name"),
},
}
}
func MatchRuleFromContainer(cont *container.Container) *MatchRule {
return MatchRuleFromContainerList(cont, 0)
}
func MatchRuleListFromContainer(cont *container.Container) []*MatchRule {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*MatchRule, length)
for i := 0; i < length; i++ {
arr[i] = MatchRuleFromContainerList(cont, i)
}
return arr
}