From e1db7009d8285244adccb959d05f5a93c08c8353 Mon Sep 17 00:00:00 2001 From: ramukima Date: Mon, 15 Aug 2016 23:36:13 -0400 Subject: [PATCH 1/2] issue-1588 : Allow extra driver config args as a passthrough for qemu executable from a task specification --- client/driver/qemu.go | 13 +++++++++++-- client/driver/qemu_test.go | 2 ++ website/source/docs/drivers/qemu.html.md | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 7f577dfbfae8..7d8aa6a2984e 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 50def9a4b9d1..32a2e30c1dcb 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 c905178204b8..5a1f44918b87 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" From 8d72b8e23eb783c31c11c6b8f312635b7e5e51fc Mon Sep 17 00:00:00 2001 From: ramukima Date: Tue, 16 Aug 2016 09:20:13 -0400 Subject: [PATCH 2/2] go fmt performed code when copied from another directory got messed up again ? Ok, ran go fmt again --- client/driver/qemu.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 7d8aa6a2984e..d109f3912343 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -46,7 +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 + Args []string `mapstructure:"args"` // extra arguments to qemu executable } // qemuHandle is returned from Start/Open as a handle to the PID