-
Notifications
You must be signed in to change notification settings - Fork 30
/
fabric_node_p_ep.go
100 lines (70 loc) · 2.58 KB
/
fabric_node_p_ep.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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const FabricnodepepClassName = "fabricNodePEp"
type NodePolicyEndPoint struct {
BaseAttributes
NodePolicyEndPointAttributes
}
type NodePolicyEndPointAttributes struct {
Node_policy_end_point_id string `json:",omitempty"`
Annotation string `json:",omitempty"`
NameAlias string `json:",omitempty"`
PodId string `json:",omitempty"`
}
func NewNodePolicyEndPoint(fabricNodePEpRn, parentDn, description string, fabricNodePEpattr NodePolicyEndPointAttributes) *NodePolicyEndPoint {
dn := fmt.Sprintf("%s/%s", parentDn, fabricNodePEpRn)
return &NodePolicyEndPoint{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: FabricnodepepClassName,
Rn: fabricNodePEpRn,
},
NodePolicyEndPointAttributes: fabricNodePEpattr,
}
}
func (fabricNodePEp *NodePolicyEndPoint) ToMap() (map[string]string, error) {
fabricNodePEpMap, err := fabricNodePEp.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
A(fabricNodePEpMap, "id", fabricNodePEp.Node_policy_end_point_id)
A(fabricNodePEpMap, "annotation", fabricNodePEp.Annotation)
A(fabricNodePEpMap, "nameAlias", fabricNodePEp.NameAlias)
A(fabricNodePEpMap, "podId", fabricNodePEp.PodId)
return fabricNodePEpMap, err
}
func NodePolicyEndPointFromContainerList(cont *container.Container, index int) *NodePolicyEndPoint {
NodePolicyEndPointCont := cont.S("imdata").Index(index).S(FabricnodepepClassName, "attributes")
return &NodePolicyEndPoint{
BaseAttributes{
DistinguishedName: G(NodePolicyEndPointCont, "dn"),
Description: G(NodePolicyEndPointCont, "descr"),
Status: G(NodePolicyEndPointCont, "status"),
ClassName: FabricnodepepClassName,
Rn: G(NodePolicyEndPointCont, "rn"),
},
NodePolicyEndPointAttributes{
Node_policy_end_point_id: G(NodePolicyEndPointCont, "id"),
Annotation: G(NodePolicyEndPointCont, "annotation"),
NameAlias: G(NodePolicyEndPointCont, "nameAlias"),
PodId: G(NodePolicyEndPointCont, "podId"),
},
}
}
func NodePolicyEndPointFromContainer(cont *container.Container) *NodePolicyEndPoint {
return NodePolicyEndPointFromContainerList(cont, 0)
}
func NodePolicyEndPointListFromContainer(cont *container.Container) []*NodePolicyEndPoint {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*NodePolicyEndPoint, length)
for i := 0; i < length; i++ {
arr[i] = NodePolicyEndPointFromContainerList(cont, i)
}
return arr
}