-
Notifications
You must be signed in to change notification settings - Fork 63
/
config.go
306 lines (257 loc) · 7.54 KB
/
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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package qemu
import "kraftkit.sh/internal/run"
type QemuConfig struct {
// Command-line arguments for qemu-system-*
Accel QemuMachineAccelerator `flag:"-accel" json:"accel,omitempty"`
Append string `flag:"-append" json:"append,omitempty"`
CharDevs []QemuCharDev `flag:"-chardev" json:"chardev,omitempty"`
CPU QemuCPU `flag:"-cpu" json:"cpu,omitempty"`
Daemonize bool `flag:"-daemonize" json:"daemonize,omitempty"`
Devices []QemuDevice `flag:"-device" json:"device,omitempty"`
Display QemuDisplay `flag:"-display" json:"display,omitempty"`
EnableKVM bool `flag:"-enable-kvm" json:"enable_kvm,omitempty"`
FsDevs []QemuFsDev `flag:"-fsdev" json:"fsdev,omitempty"`
InitRd string `flag:"-initrd" json:"initrd,omitempty"`
Kernel string `flag:"-kernel" json:"kernel,omitempty"`
Machine QemuMachine `flag:"-machine" json:"machine,omitempty"`
Memory QemuMemory `flag:"-m" json:"memory,omitempty"`
Monitor QemuHostCharDev `flag:"-monitor" json:"monitor,omitempty"`
Name string `flag:"-name" json:"name,omitempty"`
NetDevs []QemuNetDev `flag:"-netdev" json:"netdev,omitempty"`
NoACPI bool `flag:"-no-acpi" json:"no_acpi,omitempty"`
NoDefaults bool `flag:"-nodefaults" json:"no_defaults,omitempty"`
NoGraphic bool `flag:"-nographic" json:"no_graphic,omitempty"`
NoReboot bool `flag:"-no-reboot" json:"no_reboot,omitempty"`
NoShutdown bool `flag:"-no-shutdown" json:"no_shutdown,omitempty"`
NoStart bool `flag:"-S" json:"no_start,omitempty"`
Parallel QemuHostCharDev `flag:"-parallel" json:"parallel,omitempty"`
PidFile string `flag:"-pidfile" json:"pidfile,omitempty"`
QMP []QemuHostCharDev `flag:"-qmp" json:"qmp,omitempty"`
RTC QemuRTC `flag:"-rtc" json:"rtc,omitempty"`
Serial []QemuHostCharDev `flag:"-serial" json:"serial,omitempty"`
SMP QemuSMP `flag:"-smp" json:"smp,omitempty"`
TBSize int `flag:"-tb-size" json:"tb_size,omitempty"`
VGA QemuVGA `flag:"-vga" json:"vga,omitempty"`
Version bool `flag:"-version" json:"-"`
// Command-line arguments for qemu-system-i386 and qemu-system-x86_64 only
NoHPET bool `flag:"-no-hpet" json:"no_hpet,omitempty"`
}
type QemuOption func(*QemuConfig) error
func NewQemuConfig(qopts ...QemuOption) (*QemuConfig, error) {
qcfg := QemuConfig{}
for _, o := range qopts {
if err := o(&qcfg); err != nil {
return nil, err
}
}
return &qcfg, nil
}
func WithAccel(accel QemuMachineAccelerator) QemuOption {
return func(qc *QemuConfig) error {
qc.Accel = accel
return nil
}
}
func WithAppend(append ...string) QemuOption {
return func(qc *QemuConfig) error {
qc.Append = run.BootArgsPrepare(append...)
return nil
}
}
func WithCharDevice(chardev QemuCharDev) QemuOption {
return func(qc *QemuConfig) error {
if qc.CharDevs == nil {
qc.CharDevs = make([]QemuCharDev, 0)
}
qc.CharDevs = append(qc.CharDevs, chardev)
return nil
}
}
func WithCPU(cpu QemuCPU) QemuOption {
return func(qc *QemuConfig) error {
qc.CPU = cpu
return nil
}
}
func WithDaemonize(daemonize bool) QemuOption {
return func(qc *QemuConfig) error {
qc.Daemonize = daemonize
return nil
}
}
func WithDevice(device QemuDevice) QemuOption {
return func(qc *QemuConfig) error {
if qc.Devices == nil {
qc.Devices = make([]QemuDevice, 0)
}
qc.Devices = append(qc.Devices, device)
return nil
}
}
func WithDisplay(display QemuDisplay) QemuOption {
return func(qc *QemuConfig) error {
qc.Display = display
return nil
}
}
func WithEnableKVM(enableKVM bool) QemuOption {
return func(qc *QemuConfig) error {
qc.EnableKVM = enableKVM
return nil
}
}
func WithFsDevice(fsdev QemuFsDev) QemuOption {
return func(qc *QemuConfig) error {
if qc.FsDevs == nil {
qc.FsDevs = make([]QemuFsDev, 0)
}
qc.FsDevs = append(qc.FsDevs, fsdev)
return nil
}
}
func WithInitRd(initrd string) QemuOption {
return func(qc *QemuConfig) error {
qc.InitRd = initrd
return nil
}
}
func WithKernel(kernel string) QemuOption {
return func(qc *QemuConfig) error {
qc.Kernel = kernel
return nil
}
}
func WithMachine(machine QemuMachine) QemuOption {
return func(qc *QemuConfig) error {
qc.Machine = machine
return nil
}
}
func WithMemory(memory QemuMemory) QemuOption {
return func(qc *QemuConfig) error {
qc.Memory = memory
return nil
}
}
func WithMonitor(chardev QemuHostCharDev) QemuOption {
return func(qc *QemuConfig) error {
qc.Monitor = chardev
return nil
}
}
func WithName(name string) QemuOption {
return func(qc *QemuConfig) error {
qc.Name = name
return nil
}
}
func WithNetDevice(netdev QemuNetDev) QemuOption {
return func(qc *QemuConfig) error {
if qc.NetDevs == nil {
qc.NetDevs = make([]QemuNetDev, 0)
}
qc.NetDevs = append(qc.NetDevs, netdev)
return nil
}
}
func WithNoACPI(noACPI bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoACPI = noACPI
return nil
}
}
func WithNoDefaults(noDefaults bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoDefaults = noDefaults
return nil
}
}
func WithNoGraphic(noGraphic bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoGraphic = noGraphic
return nil
}
}
func WithNoReboot(noReboot bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoReboot = noReboot
return nil
}
}
func WithNoShutdown(noShutdown bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoShutdown = noShutdown
return nil
}
}
func WithNoStart(noStart bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoStart = noStart
return nil
}
}
func WithParallel(chardev QemuHostCharDev) QemuOption {
return func(qc *QemuConfig) error {
qc.Parallel = chardev
return nil
}
}
func WithPidFile(pidFile string) QemuOption {
return func(qc *QemuConfig) error {
qc.PidFile = pidFile
return nil
}
}
// WithQMP is similar to WithMonitor but opens in "control" mode.
func WithQMP(qmp QemuHostCharDev) QemuOption {
return func(qc *QemuConfig) error {
if qc.QMP == nil {
qc.QMP = make([]QemuHostCharDev, 0)
}
qc.QMP = append(qc.QMP, qmp)
return nil
}
}
func WithRTC(rtc QemuRTC) QemuOption {
return func(qc *QemuConfig) error {
qc.RTC = rtc
return nil
}
}
func WithSerial(chardev QemuHostCharDev) QemuOption {
return func(qc *QemuConfig) error {
if qc.Serial == nil {
qc.Serial = make([]QemuHostCharDev, 0)
}
qc.Serial = append(qc.Serial, chardev)
return nil
}
}
func WithSMP(smp QemuSMP) QemuOption {
return func(qc *QemuConfig) error {
qc.SMP = smp
return nil
}
}
func WithTBSize(tbSize int) QemuOption {
return func(qc *QemuConfig) error {
qc.TBSize = tbSize
return nil
}
}
func WithVGA(vga QemuVGA) QemuOption {
return func(qc *QemuConfig) error {
qc.VGA = vga
return nil
}
}
func WithNoHPET(noHPET bool) QemuOption {
return func(qc *QemuConfig) error {
qc.NoHPET = noHPET
return nil
}
}