-
Notifications
You must be signed in to change notification settings - Fork 29
/
vns_c_dev.go
116 lines (101 loc) · 3.38 KB
/
vns_c_dev.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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DnvnsCDev = "%s/cDev-%s"
RnvnsCDev = "cDev-%s"
VnscdevClassName = "vnsCDev"
)
type ConcreteDevice struct {
BaseAttributes
NameAliasAttribute
ConcreteDeviceAttributes
}
type ConcreteDeviceAttributes struct {
CloneCount string `json:",omitempty"`
DevCtxLbl string `json:",omitempty"`
Host string `json:",omitempty"`
IsCloneOperation string `json:",omitempty"`
IsTemplate string `json:",omitempty"`
Name string `json:",omitempty"`
VcenterName string `json:",omitempty"`
VmName string `json:",omitempty"`
Annotation string `json:",omitempty"`
}
func NewConcreteDevice(vnsCDevRn, parentDn, nameAlias string, vnsCDevAttr ConcreteDeviceAttributes) *ConcreteDevice {
dn := fmt.Sprintf("%s/%s", parentDn, vnsCDevRn)
return &ConcreteDevice{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Status: "created, modified",
ClassName: VnscdevClassName,
Rn: vnsCDevRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
ConcreteDeviceAttributes: vnsCDevAttr,
}
}
func (vnsCDev *ConcreteDevice) ToMap() (map[string]string, error) {
vnsCDevMap, err := vnsCDev.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := vnsCDev.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(vnsCDevMap, key, value)
}
A(vnsCDevMap, "cloneCount", vnsCDev.CloneCount)
A(vnsCDevMap, "annotation", vnsCDev.Annotation)
A(vnsCDevMap, "devCtxLbl", vnsCDev.DevCtxLbl)
A(vnsCDevMap, "host", vnsCDev.Host)
A(vnsCDevMap, "isCloneOperation", vnsCDev.IsCloneOperation)
A(vnsCDevMap, "isTemplate", vnsCDev.IsTemplate)
A(vnsCDevMap, "name", vnsCDev.Name)
A(vnsCDevMap, "vcenterName", vnsCDev.VcenterName)
A(vnsCDevMap, "vmName", vnsCDev.VmName)
return vnsCDevMap, err
}
func ConcreteDeviceFromContainerList(cont *container.Container, index int) *ConcreteDevice {
ConcreteDeviceCont := cont.S("imdata").Index(index).S(VnscdevClassName, "attributes")
return &ConcreteDevice{
BaseAttributes{
DistinguishedName: G(ConcreteDeviceCont, "dn"),
Status: G(ConcreteDeviceCont, "status"),
ClassName: VnscdevClassName,
Rn: G(ConcreteDeviceCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(ConcreteDeviceCont, "nameAlias"),
},
ConcreteDeviceAttributes{
CloneCount: G(ConcreteDeviceCont, "cloneCount"),
Annotation: G(ConcreteDeviceCont, "annotation"),
DevCtxLbl: G(ConcreteDeviceCont, "devCtxLbl"),
Host: G(ConcreteDeviceCont, "host"),
IsCloneOperation: G(ConcreteDeviceCont, "isCloneOperation"),
IsTemplate: G(ConcreteDeviceCont, "isTemplate"),
Name: G(ConcreteDeviceCont, "name"),
VcenterName: G(ConcreteDeviceCont, "vcenterName"),
VmName: G(ConcreteDeviceCont, "vmName"),
},
}
}
func ConcreteDeviceFromContainer(cont *container.Container) *ConcreteDevice {
return ConcreteDeviceFromContainerList(cont, 0)
}
func ConcreteDeviceListFromContainer(cont *container.Container) []*ConcreteDevice {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*ConcreteDevice, length)
for i := 0; i < length; i++ {
arr[i] = ConcreteDeviceFromContainerList(cont, i)
}
return arr
}