forked from luthermonson/go-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtual_machine_config.go
116 lines (100 loc) · 2.57 KB
/
virtual_machine_config.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 proxmox
import (
"reflect"
"strconv"
"strings"
)
func (vmc *VirtualMachineConfig) mergeIndexedDevices(prefix string) map[string]string {
deviceMap := make(map[string]string)
t := reflect.TypeOf(*vmc)
v := reflect.ValueOf(*vmc)
count := v.NumField()
for i := 0; i < count; i++ {
fn := t.Field(i).Name
fv := v.Field(i).String()
if "" == fv {
continue
}
if strings.HasPrefix(fn, prefix) {
// Ignore non-numeric suffixes like SCSIHW
suffix := strings.TrimPrefix(fn, prefix)
if _, err := strconv.Atoi(suffix); err != nil {
continue
}
deviceMap[strings.ToLower(fn)] = fv
}
}
return deviceMap
}
func (vmc *VirtualMachineConfig) MergeIDEs() map[string]string {
if nil == vmc.IDEs {
vmc.IDEs = vmc.mergeIndexedDevices("IDE")
}
return vmc.IDEs
}
func (vmc *VirtualMachineConfig) MergeSCSIs() map[string]string {
if nil == vmc.SCSIs {
vmc.SCSIs = vmc.mergeIndexedDevices("SCSI")
}
return vmc.SCSIs
}
func (vmc *VirtualMachineConfig) MergeSATAs() map[string]string {
if nil == vmc.SATAs {
vmc.SATAs = vmc.mergeIndexedDevices("SATA")
}
return vmc.SATAs
}
func (vmc *VirtualMachineConfig) MergeNets() map[string]string {
if nil == vmc.Nets {
vmc.Nets = vmc.mergeIndexedDevices("Net")
}
return vmc.Nets
}
func (vmc *VirtualMachineConfig) MergeVirtIOs() map[string]string {
if nil == vmc.VirtIOs {
vmc.VirtIOs = vmc.mergeIndexedDevices("VirtIO")
}
return vmc.VirtIOs
}
func (vmc *VirtualMachineConfig) MergeUnuseds() map[string]string {
if nil == vmc.Unuseds {
vmc.Unuseds = vmc.mergeIndexedDevices("Unused")
}
return vmc.Unuseds
}
func (vmc *VirtualMachineConfig) MergeSerials() map[string]string {
if nil == vmc.Serials {
vmc.Serials = vmc.mergeIndexedDevices("Serial")
}
return vmc.Serials
}
func (vmc *VirtualMachineConfig) MergeUSBs() map[string]string {
if nil == vmc.USBs {
vmc.HostPCIs = vmc.mergeIndexedDevices("USB")
}
return vmc.USBs
}
func (vmc *VirtualMachineConfig) MergeHostPCIs() map[string]string {
if nil == vmc.HostPCIs {
vmc.HostPCIs = vmc.mergeIndexedDevices("HostPCI")
}
return vmc.HostPCIs
}
func (vmc *VirtualMachineConfig) MergeNumas() map[string]string {
if nil == vmc.Numas {
vmc.HostPCIs = vmc.mergeIndexedDevices("Numa")
}
return vmc.Numas
}
func (vmc *VirtualMachineConfig) MergeParallels() map[string]string {
if nil == vmc.Parallels {
vmc.Parallels = vmc.mergeIndexedDevices("Parallel")
}
return vmc.Parallels
}
func (vmc *VirtualMachineConfig) MergeIPConfigs() map[string]string {
if nil == vmc.IPConfigs {
vmc.IPConfigs = vmc.mergeIndexedDevices("IPConfig")
}
return vmc.IPConfigs
}