-
Notifications
You must be signed in to change notification settings - Fork 30
/
fv_tag_selector.go
102 lines (92 loc) · 3.68 KB
/
fv_tag_selector.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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DnfvTagSelector = "uni/tn-%s/ap-%s/esg-%s/tagselectorkey-[%s]-value-[%s]"
RnfvTagSelector = "tagselectorkey-[%s]-value-[%s]"
ParentDnfvTagSelector = "uni/tn-%s/ap-%s/esg-%s"
FvtagselectorClassName = "fvTagSelector"
)
type EndpointSecurityGroupTagSelector struct {
BaseAttributes
NameAliasAttribute
EndpointSecurityGroupTagSelectorAttributes
}
type EndpointSecurityGroupTagSelectorAttributes struct {
Annotation string `json:",omitempty"`
MatchKey string `json:",omitempty"`
MatchValue string `json:",omitempty"`
Name string `json:",omitempty"`
ValueOperator string `json:",omitempty"`
}
func NewEndpointSecurityGroupTagSelector(fvTagSelectorRn, parentDn, description, nameAlias string, fvTagSelectorAttr EndpointSecurityGroupTagSelectorAttributes) *EndpointSecurityGroupTagSelector {
dn := fmt.Sprintf("%s/%s", parentDn, fvTagSelectorRn)
return &EndpointSecurityGroupTagSelector{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: FvtagselectorClassName,
Rn: fvTagSelectorRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
EndpointSecurityGroupTagSelectorAttributes: fvTagSelectorAttr,
}
}
func (fvTagSelector *EndpointSecurityGroupTagSelector) ToMap() (map[string]string, error) {
fvTagSelectorMap, err := fvTagSelector.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := fvTagSelector.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(fvTagSelectorMap, key, value)
}
A(fvTagSelectorMap, "annotation", fvTagSelector.Annotation)
A(fvTagSelectorMap, "matchKey", fvTagSelector.MatchKey)
A(fvTagSelectorMap, "matchValue", fvTagSelector.MatchValue)
A(fvTagSelectorMap, "name", fvTagSelector.Name)
A(fvTagSelectorMap, "valueOperator", fvTagSelector.ValueOperator)
return fvTagSelectorMap, err
}
func EndpointSecurityGroupTagSelectorFromContainerList(cont *container.Container, index int) *EndpointSecurityGroupTagSelector {
EndpointSecurityGroupTagSelectorCont := cont.S("imdata").Index(index).S(FvtagselectorClassName, "attributes")
return &EndpointSecurityGroupTagSelector{
BaseAttributes{
DistinguishedName: G(EndpointSecurityGroupTagSelectorCont, "dn"),
Description: G(EndpointSecurityGroupTagSelectorCont, "descr"),
Status: G(EndpointSecurityGroupTagSelectorCont, "status"),
ClassName: FvtagselectorClassName,
Rn: G(EndpointSecurityGroupTagSelectorCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(EndpointSecurityGroupTagSelectorCont, "nameAlias"),
},
EndpointSecurityGroupTagSelectorAttributes{
Annotation: G(EndpointSecurityGroupTagSelectorCont, "annotation"),
MatchKey: G(EndpointSecurityGroupTagSelectorCont, "matchKey"),
MatchValue: G(EndpointSecurityGroupTagSelectorCont, "matchValue"),
Name: G(EndpointSecurityGroupTagSelectorCont, "name"),
ValueOperator: G(EndpointSecurityGroupTagSelectorCont, "valueOperator"),
},
}
}
func EndpointSecurityGroupTagSelectorFromContainer(cont *container.Container) *EndpointSecurityGroupTagSelector {
return EndpointSecurityGroupTagSelectorFromContainerList(cont, 0)
}
func EndpointSecurityGroupTagSelectorListFromContainer(cont *container.Container) []*EndpointSecurityGroupTagSelector {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*EndpointSecurityGroupTagSelector, length)
for i := 0; i < length; i++ {
arr[i] = EndpointSecurityGroupTagSelectorFromContainerList(cont, i)
}
return arr
}