-
Notifications
You must be signed in to change notification settings - Fork 30
/
infra_rs_dom_p.go
82 lines (67 loc) · 2.05 KB
/
infra_rs_dom_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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DninfraRsDomP = "%s/%s"
RninfraRsDomP = "rsdomP-[%s]"
ParentDninfraRsDomP = "uni/infra/attentp-%s"
InfrarsdompClassName = "infraRsDomP"
)
type InfraRsDomP struct {
BaseAttributes
InfraRsDomPAttributes
}
type InfraRsDomPAttributes struct {
Annotation string `json:",omitempty"`
TDn string `json:",omitempty"`
}
func NewInfraRsDomP(infraRsDomPRn string, parentDn string, infraRsDomPAttr InfraRsDomPAttributes) *InfraRsDomP {
dn := fmt.Sprintf("%s/%s", parentDn, infraRsDomPRn)
return &InfraRsDomP{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Status: "created, modified",
ClassName: InfrarsdompClassName,
Rn: infraRsDomPRn,
},
InfraRsDomPAttributes: infraRsDomPAttr,
}
}
func (infraRsDomP *InfraRsDomP) ToMap() (map[string]string, error) {
infraRsDomPMap, err := infraRsDomP.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
A(infraRsDomPMap, "annotation", infraRsDomP.Annotation)
A(infraRsDomPMap, "tDn", infraRsDomP.TDn)
return infraRsDomPMap, err
}
func InfraRsDomPFromContainerList(cont *container.Container, index int) *InfraRsDomP {
InfraRsDomPCont := cont.S("imdata").Index(index).S(InfrarsdompClassName, "attributes")
return &InfraRsDomP{
BaseAttributes{
DistinguishedName: G(InfraRsDomPCont, "dn"),
Status: G(InfraRsDomPCont, "status"),
ClassName: InfrarsdompClassName,
Rn: G(InfraRsDomPCont, "rn"),
},
InfraRsDomPAttributes{
Annotation: G(InfraRsDomPCont, "annotation"),
TDn: G(InfraRsDomPCont, "tDn"),
},
}
}
func InfraRsDomPFromContainer(cont *container.Container) *InfraRsDomP {
return InfraRsDomPFromContainerList(cont, 0)
}
func InfraRsDomPListFromContainer(cont *container.Container) []*InfraRsDomP {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*InfraRsDomP, length)
for i := 0; i < length; i++ {
arr[i] = InfraRsDomPFromContainerList(cont, i)
}
return arr
}