diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 7f577dfbfae..d109f391234 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -46,6 +46,7 @@ type QemuDriverConfig struct { ImagePath string `mapstructure:"image_path"` Accelerator string `mapstructure:"accelerator"` PortMap []map[string]int `mapstructure:"port_map"` // A map of host port labels and to guest ports. + Args []string `mapstructure:"args"` // extra arguments to qemu executable } // qemuHandle is returned from Start/Open as a handle to the PID @@ -82,6 +83,9 @@ func (d *QemuDriver) Validate(config map[string]interface{}) error { "port_map": &fields.FieldSchema{ Type: fields.TypeArray, }, + "args": &fields.FieldSchema{ + Type: fields.TypeArray, + }, }, } @@ -169,11 +173,16 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, "-name", vmID, "-m", mem, "-drive", "file=" + vmPath, - "-nodefconfig", - "-nodefaults", "-nographic", } + // Add pass through arguments to qemu executable. A user can specify + // these arguments in driver task configuration. These arguments are + // passed directly to the qemu driver as command line options. + // For example, args = [ "-nodefconfig", "-nodefaults" ] + // This will allow a VM with embedded configuration to boot successfully. + args = append(args, driverConfig.Args...) + // Check the Resources required Networks to add port mappings. If no resources // are required, we assume the VM is a purely compute job and does not require // the outside world to be able to reach it. VMs ran without port mappings can diff --git a/client/driver/qemu_test.go b/client/driver/qemu_test.go index 50def9a4b9d..32a2e30c1dc 100644 --- a/client/driver/qemu_test.go +++ b/client/driver/qemu_test.go @@ -46,6 +46,7 @@ func TestQemuDriver_StartOpen_Wait(t *testing.T) { "main": 22, "web": 8080, }}, + "args": []string{"-nodefconfig", "-nodefaults"}, }, LogConfig: &structs.LogConfig{ MaxFiles: 10, @@ -105,6 +106,7 @@ func TestQemuDriverUser(t *testing.T) { "main": 22, "web": 8080, }}, + "args": []string{"-nodefconfig", "-nodefaults"}, }, LogConfig: &structs.LogConfig{ MaxFiles: 10, diff --git a/website/source/docs/drivers/qemu.html.md b/website/source/docs/drivers/qemu.html.md index c905178204b..5a1f44918b8 100644 --- a/website/source/docs/drivers/qemu.html.md +++ b/website/source/docs/drivers/qemu.html.md @@ -40,6 +40,9 @@ The `Qemu` driver supports the following configuration in the job spec: `port_map { db = 6539 }` would forward the host port with label `db` to the guest VM's port 6539. +* `args` - (Optional) A `[]string` that is passed to qemu as command line options. + For example, `args = [ "-nodefconfig", "-nodefaults" ] + ## Examples A simple config block to run a `Qemu` image: @@ -51,6 +54,7 @@ task "virtual" { config { image_path = "local/linux.img" accelerator = "kvm" + args = [ "-nodefaults", "-nodefconfig" ] } # Specifying an artifact is required with the "qemu"