-
Notifications
You must be signed in to change notification settings - Fork 8
/
api.go
291 lines (258 loc) · 9.32 KB
/
api.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package vmx
type Vhardware struct {
Version int `vmx:"version,omitempty"`
Compat string `vmx:"productcompatibility,omitempty"`
}
type Ethernet struct {
VMXID string
Address string `vmx:"address,omitempty"`
GeneratedAddress string `vmx:"generatedaddress,omit"`
StartConnected bool `vmx:"startconnected,omitempty"`
Present bool `vmx:"present"`
ConnectionType string `vmx:"connectiontype,omitempty"`
VirtualDev string `vmx:"virtualdev,omitempty"`
WakeOnPcktRcv bool `vmx:"wakeonpcktrcv,omitempty"`
AddressType EthernetAddressType `vmx:"addresstype,omitempty"`
LinkStatePropagation bool `vmx:"linkstatepropagation.enable,omitempty"`
VNetwork string `vmx:"vnet,omitempty"`
}
type EthernetAddressType string
const (
MAC_TYPE_STATIC = "static"
MAC_TYPE_GENERATED = "generated"
)
type Device struct {
VMXID string
Present bool `vmx:"present"`
Autodetect bool `vmx:"autodetect,omitempty"`
StartConnected bool `vmx:"startconnected,omitempty"`
Type string `vmx:"devicetype,omitempty"`
Filename string `vmxl:"filename,omitempty"`
}
type SATADevice struct {
Device
}
type SCSIDevice struct {
Device
PCISlot int `vmx:"pcislotnumber,omitempty"`
VirtualDev string `vmx:"virtualdev,omitempty"`
}
type IDEDevice struct {
Device
}
type USBDevice struct {
VMXID string
Present bool `vmx:"present"`
Speed uint `vmx:"speed,omitempty"`
Type string `vmx:"devicetype,omitempty"`
Port uint `vmx:"port,omitempty"`
Parent string `vmx:"parent,omitempty"`
}
type PowerType struct {
PowerOff string `vmx:"poweroff,omitempty"`
PowerOn string `vmx:"poweron,omitempty"`
Reset string `vmx:"reset,omitempty"`
Suspend string `vmx:"suspend,omitempty"`
}
type Sound struct {
VMXID string
Present bool `vmx:"present"`
Filename string `vmx:"filename,omitempty"`
Autodetect bool `vmx:"autodetect,omitempty"`
}
type SerialPort struct {
VMXID string
StartConnected bool `vmx:"startconnected,omitempty"`
Present bool `vmx:"present"`
Filetype string `vmx:"filetype,omitempty"`
Filename string `vmx:"filename,omitempty"`
Autodetect bool `vmx:"autodetect,omitempty"`
TryNoRxLoss bool `vmx:"trynorxloss,omitempty"`
PipeEndpoint string `vmx:"pipe.endpoint,omitempty"`
AllowGuestConnCtrl bool `vmx:"allowguestconnectioncontrol,omitempty"`
HardwareFlowCtrl bool `vmx:"hardwareFlowControl,omitempty"`
}
type PCIBridge struct {
VMXID string
Present bool `vmx:"present"`
VirtualDev string `vmx:"virtualdev,omitempty"`
SlotNumber int `vmx:"pcislotnumber,omitempty"`
Functions uint `vmx:"functions,omitempty"`
}
type Tools struct {
SyncTime bool `vmx:"synctime,omitempty"`
UpgradePolicy string `vmx:"upgrade.policy,omitempty"`
RemindInstall bool `vmx:"remindinstall,omitempty"`
}
type UUID struct {
Action string `vmx:"action,omitempty"`
// Autogenerated, do not change
Bios string `vmx:"bios,omitempty"`
// Autogenerated, do not change
Location string `vmx:"location,omitempty"`
}
type RemoteDisplay struct {
VNCEnabled bool `vmx:"vnc.enabled,omitempty"`
VNCPort uint `vmx:"vnc.port,omitempty"`
VNCPassword string `vmx:"vnc.password,omitempty"`
VNCIPAddress string `vmx:"vnc.ip,omitempty"`
VNCKey string `vmx:"vnc.key,omitempty"`
VNCKeyMap string `vmx:"vnc.keymap,omitempty"`
VNCKeyMapFile string `vmx:"vnc.keymapfile,omitempty"`
VNCZlibLevel uint `vmx:"vnc.zliblevel,omitempty"`
VNCWheelStep string `vmx:"vncWheelStep,omitempty"`
Depth uint `vmx:"depth,omitempty"`
MaxConnections uint `vmx:"maxconnections,omitempty"`
MaxHeight uint `vmx:"maxheight,omitempty"`
MaxWidth uint `vmx:"maxwidth,omitempty"`
}
type SharedFolder struct {
VMXID string
Present bool `vmx:"present"`
Enabled bool `vmx:"enabled,omitempty"`
ReadAccess bool `vmx:"readaccess,omitempty"`
WriteAccess bool `vmx:"writeaccess,omitempty"`
HostPath string `vmx:"hostpath,omitempty"`
GuestName string `vmx:"guestname,omitempty"`
Expiration string `vmx:"expiration,omitempty"`
}
type GUI struct {
ExitAtPowerOff bool `vmx:"exitatpoweroff,omitempty"`
FullScreenAtPowerOn bool `vmx:"fullscreenatpoweron,omitempty"`
PowerOnAtStartup bool `vmx:"poweronatstartup,omitempty"`
ExitOnCLIHalt bool `vmx:"exitonclihlt,omitempty"`
}
type Isolation struct {
// Disable shared folders
HgfsDisable bool `vmx:"tools.hgfs.disable,omitempty"`
CopyDisable bool `vmx:"tools.copy.disable,omitempty"`
PasteDisable bool `vmx:"tools.paste.disable,omitempty"`
DragNDropDisable bool `vmx:"tools.dnd.disable,omitempty"`
}
type FloppyDevice struct {
VMXID string
Present bool `vmx:"present"`
StartConnected bool `vmx:"startconnected,omitempty"`
Autodetect bool `vmx:"autodetect,omitempty"`
Filename string `vmx:"filename,omitempty"`
Filetype string `vmx:"filetype,omitempty"`
GuestControl bool `vmx:"allowGuestConnectionControl,omitempty"`
}
type VMCI struct {
VMXID string
ID string `vmx:"id,omitempty"`
// We omit adding vmci.present = "false" since VMWare defaults it to TRUE
// given that it increases IO performance between VMs in the same host
Present bool `vmx:"present,omitempty"`
PCISlot int `vmx:"pcislotnumber,omitempty"`
}
type VMotion struct {
CheckpointSize string `vmx:"checkpointFBSize,omitempty"`
}
type USB struct {
Present bool `vmx:"present"`
GenericAutoconnect bool `vmx:"generic.autoconnect,omitempty"`
}
type RTC struct {
DiffFromUTC int `vmx:"diffFromUTC"`
}
type BIOS struct {
BootOrder string `vmx:"bootorder,omitempty"`
HDDOrder string `vmx:"hddorder,omitempty"`
}
type Config struct {
Version string `vmx:"version,omitempty"`
}
type VirtualMachine struct {
Encoding string `vmx:".encoding,omitempty"`
ExtendedCfgFile string `vmx:"extendedconfigfile,omitempty"`
PowerType PowerType `vmx:"powertype,omitempty"`
Annotation string `vmx:"annotation,omitempty"`
Vhardware Vhardware `vmx:"virtualhw,omitempty"`
Memsize uint `vmx:"memsize,omitempty"`
NumvCPUs uint `vmx:"numvcpus,omitempty"`
MemHotAdd bool `vmx:"mem.hotadd,omitempty"`
VCPUHotAdd bool `vmx:"vcpu.hotadd,omitempty"`
DisplayName string `vmx:"displayname,omitempty"`
GuestOS string `vmx:"guestos,omitempty"`
Autoanswer bool `vmx:"msg.autoanswer,omitempty"`
Sound Sound `vmx:"sound,omitempty"`
Tools Tools `vmx:"tools,omitempty"`
NVRam string `vmx:"nvmram,omitempty"`
UUID UUID `vmx:"uuid,omitempty"`
CleanShutdown bool `vmx:"cleanshutdown,omitempty"`
SoftPowerOff bool `vmx:"softpoweroff,omitempty"`
VMCI VMCI `vmx:"vmci0,omitempty"`
VMotion VMotion `vmx:"vmotion,omitempty"`
USB USB `vmx:"usb,omitempty"`
RTC RTC `vmx:"rtc,omitempty"`
Config Config `vmx:"config"`
// Enable or not nested virtualiation
VHVEnable bool `vmx:"vhv.enable,omitempty"`
RemoteDisplay RemoteDisplay `vmx:"remotedisplay,omitempty"`
Isolation Isolation `vmx:"isolation,omitempty"`
SharedFolders []SharedFolder `vmx:"sharedfolder,omitempty"`
PCIBridges []PCIBridge `vmx:"pcibridge,omitempty"`
SerialPorts []SerialPort `vmx:"serial,omitempty"`
Ethernet []Ethernet `vmx:"ethernet,omitempty"`
IDEDevices []IDEDevice `vmx:"ide,omitempty"`
SCSIDevices []SCSIDevice `vmx:"scsi,omitempty"`
SATADevices []SATADevice `vmx:"sata,omitempty"`
USBDevices []USBDevice `vmx:"usb,omitempty"`
FloppyDevices []FloppyDevice `vmx:"floppy,omitempty"`
}
// Bus type to use when attaching or detaching CD/DVD drives and disks.
type BusType string
// Disk controllers
const (
IDE BusType = "ide"
SCSI BusType = "scsi"
SATA BusType = "sata"
)
// CDROM device types
const (
CDROM_IMAGE string = "cdrom-image"
CDROM_RAW string = "cdrom-raw"
)
// FindDevice executes the given function p on all the devices of one of the
// given types until one of the calls returns true.
// If no bus types are provided all will be used.
// FindDevice returns true only if one of the calls of p returned true.
func (vm VirtualMachine) FindDevice(p func(Device) bool, types ...BusType) bool {
return vm.walkDevices(p, types...)
}
// WalkDevices executes the given function f on all the devices of one of the
// specified types.
// If no bus types are provided all will be used.
func (vm VirtualMachine) WalkDevices(f func(Device), types ...BusType) {
p := func(d Device) bool { f(d); return false }
vm.walkDevices(p, types...)
}
func (vm VirtualMachine) walkDevices(p func(Device) bool, types ...BusType) bool {
if len(types) == 0 {
types = []BusType{SATA, IDE, SCSI}
}
for _, t := range types {
switch t {
case SATA:
for _, d := range vm.SATADevices {
if p(d.Device) {
return true
}
}
case IDE:
for _, d := range vm.IDEDevices {
if p(d.Device) {
return true
}
}
case SCSI:
for _, d := range vm.SCSIDevices {
if p(d.Device) {
return true
}
}
}
}
return false
}