-
Notifications
You must be signed in to change notification settings - Fork 30
/
infra_sh_port_s.go
96 lines (86 loc) · 3.13 KB
/
infra_sh_port_s.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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DninfraSHPortS = "uni/infra/spaccportprof-%s/shports-%s-typ-%s"
RninfraSHPortS = "shports-%s-typ-%s"
ParentDninfraSHPortS = "uni/infra/spaccportprof-%s"
InfrashportsClassName = "infraSHPortS"
)
type SpineAccessPortSelector struct {
BaseAttributes
NameAliasAttribute
SpineAccessPortSelectorAttributes
}
type SpineAccessPortSelectorAttributes struct {
Annotation string `json:",omitempty"`
Name string `json:",omitempty"`
SpineAccessPortSelector_type string `json:",omitempty"`
}
func NewSpineAccessPortSelector(infraSHPortSRn, parentDn, description, nameAlias string, infraSHPortSAttr SpineAccessPortSelectorAttributes) *SpineAccessPortSelector {
dn := fmt.Sprintf("%s/%s", parentDn, infraSHPortSRn)
return &SpineAccessPortSelector{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: InfrashportsClassName,
Rn: infraSHPortSRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
SpineAccessPortSelectorAttributes: infraSHPortSAttr,
}
}
func (infraSHPortS *SpineAccessPortSelector) ToMap() (map[string]string, error) {
infraSHPortSMap, err := infraSHPortS.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := infraSHPortS.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(infraSHPortSMap, key, value)
}
A(infraSHPortSMap, "annotation", infraSHPortS.Annotation)
A(infraSHPortSMap, "name", infraSHPortS.Name)
A(infraSHPortSMap, "type", infraSHPortS.SpineAccessPortSelector_type)
return infraSHPortSMap, err
}
func SpineAccessPortSelectorFromContainerList(cont *container.Container, index int) *SpineAccessPortSelector {
SpineAccessPortSelectorCont := cont.S("imdata").Index(index).S(InfrashportsClassName, "attributes")
return &SpineAccessPortSelector{
BaseAttributes{
DistinguishedName: G(SpineAccessPortSelectorCont, "dn"),
Description: G(SpineAccessPortSelectorCont, "descr"),
Status: G(SpineAccessPortSelectorCont, "status"),
ClassName: InfrashportsClassName,
Rn: G(SpineAccessPortSelectorCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(SpineAccessPortSelectorCont, "nameAlias"),
},
SpineAccessPortSelectorAttributes{
Annotation: G(SpineAccessPortSelectorCont, "annotation"),
Name: G(SpineAccessPortSelectorCont, "name"),
SpineAccessPortSelector_type: G(SpineAccessPortSelectorCont, "type"),
},
}
}
func SpineAccessPortSelectorFromContainer(cont *container.Container) *SpineAccessPortSelector {
return SpineAccessPortSelectorFromContainerList(cont, 0)
}
func SpineAccessPortSelectorListFromContainer(cont *container.Container) []*SpineAccessPortSelector {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*SpineAccessPortSelector, length)
for i := 0; i < length; i++ {
arr[i] = SpineAccessPortSelectorFromContainerList(cont, i)
}
return arr
}