-
Notifications
You must be signed in to change notification settings - Fork 30
/
fv_subnet.go
118 lines (79 loc) · 2.42 KB
/
fv_subnet.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const FvsubnetClassName = "fvSubnet"
type Subnet struct {
BaseAttributes
SubnetAttributes
}
type SubnetAttributes struct {
Ip string `json:",omitempty"`
Annotation string `json:",omitempty"`
Ctrl string `json:",omitempty"`
NameAlias string `json:",omitempty"`
Preferred string `json:",omitempty"`
Scope string `json:",omitempty"`
Virtual string `json:",omitempty"`
}
func NewSubnet(fvSubnetRn, parentDn, description string, fvSubnetattr SubnetAttributes) *Subnet {
dn := fmt.Sprintf("%s/%s", parentDn, fvSubnetRn)
return &Subnet{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: FvsubnetClassName,
Rn: fvSubnetRn,
},
SubnetAttributes: fvSubnetattr,
}
}
func (fvSubnet *Subnet) ToMap() (map[string]string, error) {
fvSubnetMap, err := fvSubnet.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
A(fvSubnetMap, "ip", fvSubnet.Ip)
A(fvSubnetMap, "annotation", fvSubnet.Annotation)
A(fvSubnetMap, "ctrl", fvSubnet.Ctrl)
A(fvSubnetMap, "nameAlias", fvSubnet.NameAlias)
A(fvSubnetMap, "preferred", fvSubnet.Preferred)
A(fvSubnetMap, "scope", fvSubnet.Scope)
A(fvSubnetMap, "virtual", fvSubnet.Virtual)
return fvSubnetMap, err
}
func SubnetFromContainerList(cont *container.Container, index int) *Subnet {
SubnetCont := cont.S("imdata").Index(index).S(FvsubnetClassName, "attributes")
return &Subnet{
BaseAttributes{
DistinguishedName: G(SubnetCont, "dn"),
Description: G(SubnetCont, "descr"),
Status: G(SubnetCont, "status"),
ClassName: FvsubnetClassName,
Rn: G(SubnetCont, "rn"),
},
SubnetAttributes{
Ip: G(SubnetCont, "ip"),
Annotation: G(SubnetCont, "annotation"),
Ctrl: G(SubnetCont, "ctrl"),
NameAlias: G(SubnetCont, "nameAlias"),
Preferred: G(SubnetCont, "preferred"),
Scope: G(SubnetCont, "scope"),
Virtual: G(SubnetCont, "virtual"),
},
}
}
func SubnetFromContainer(cont *container.Container) *Subnet {
return SubnetFromContainerList(cont, 0)
}
func SubnetListFromContainer(cont *container.Container) []*Subnet {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*Subnet, length)
for i := 0; i < length; i++ {
arr[i] = SubnetFromContainerList(cont, i)
}
return arr
}