Add qemu USB devices

Signed-off-by: Omar Ramadan <omar.ramadan93@gmail.com>
This commit is contained in:
Omar Ramadan 2018-11-27 09:24:11 -08:00
parent 36aa581400
commit 71808a004d

View File

@ -47,6 +47,8 @@ type QemuConfig struct {
PublishedPorts []string
NetdevConfig string
UUID uuid.UUID
USB bool
Devices []string
}
const (
@ -180,6 +182,11 @@ func runQemu(args []string) {
publishFlags := multipleFlag{}
flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])")
// USB devices
usbEnabled := flags.Bool("usb", false, "Enable USB controller")
deviceFlags := multipleFlag{}
flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like -device on the qemu command line.")
if err := flags.Parse(args); err != nil {
log.Fatal("Unable to parse args")
}
@ -332,6 +339,8 @@ func runQemu(args []string) {
PublishedPorts: publishFlags,
NetdevConfig: netdevConfig,
UUID: vmUUID,
USB: *usbEnabled,
Devices: deviceFlags,
}
config = discoverBackend(config)
@ -663,6 +672,13 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
qemuArgs = append(qemuArgs, "-nographic")
}
if config.USB == true {
qemuArgs = append(qemuArgs, "-usb")
}
for _, d := range config.Devices {
qemuArgs = append(qemuArgs, "-device", d)
}
return config, qemuArgs
}