forked from ciscoecosystem/aci-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabric_node_blk.go
99 lines (73 loc) · 2.6 KB
/
fabric_node_blk.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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const FabricNodeBlkClassName = "fabricNodeBlk"
type NodeBlk struct {
BaseAttributes
NodeBlkAttributes
}
type NodeBlkAttributes struct {
Annotation string `json:",omitempty"`
Name string `json:",omitempty"`
NameAlias string `json:",omitempty"`
From_ string `json:",omitempty"`
To_ string `json:",omitempty"`
}
func NewNodeBlk(fabricNodeBlkRn, parentDn, description string, fabricNodeBlkattr NodeBlkAttributes) *NodeBlk {
dn := fmt.Sprintf("%s/%s", parentDn, fabricNodeBlkRn)
return &NodeBlk{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "",
ClassName: FabricNodeBlkClassName,
Rn: fabricNodeBlkRn,
},
NodeBlkAttributes: fabricNodeBlkattr,
}
}
func (fabricNodeBlk *NodeBlk) ToMap() (map[string]string, error) {
fabricNodeBlkMap, err := fabricNodeBlk.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
A(fabricNodeBlkMap, "annotation",fabricNodeBlk.Annotation)
A(fabricNodeBlkMap, "name",fabricNodeBlk.Name)
A(fabricNodeBlkMap, "nameAlias",fabricNodeBlk.NameAlias)
A(fabricNodeBlkMap, "from_",fabricNodeBlk.From_)
A(fabricNodeBlkMap, "to_",fabricNodeBlk.To_)
return fabricNodeBlkMap, err
}
func NodeBlkFromContainerList(cont *container.Container, index int) *NodeBlk {
NodeBlkCont := cont.S("imdata").Index(index).S(FabricNodeBlkClassName, "attributes")
return &NodeBlk{
BaseAttributes{
DistinguishedName: G(NodeBlkCont, "dn"),
Description: G(NodeBlkCont, "descr"),
Status: G(NodeBlkCont, "status"),
ClassName: FabricNodeBlkClassName,
Rn: G(NodeBlkCont, "rn"),
},
NodeBlkAttributes{
Annotation : G(NodeBlkCont, "annotation"),
Name : G(NodeBlkCont, "name"),
NameAlias : G(NodeBlkCont, "nameAlias"),
From_ : G(NodeBlkCont, "from_"),
To_ : G(NodeBlkCont, "to_"),
},
}
}
func NodeBlkFromContainer(cont *container.Container) *NodeBlk {
return NodeBlkFromContainerList(cont, 0)
}
func NodeBlkListFromContainer(cont *container.Container) []*NodeBlk {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*NodeBlk, length)
for i := 0; i < length; i++ {
arr[i] = NodeBlkFromContainerList(cont, i)
}
return arr
}