Skip to content

Commit

Permalink
Merge pull request #1596 from ramukima/qemu-extra-args-issue-1588
Browse files Browse the repository at this point in the history
issue-1588 : Allow extra driver config args as a passthrough for qemu…
  • Loading branch information
diptanu committed Aug 16, 2016
2 parents 7dc175a + 8d72b8e commit 20cce5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/driver/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
},
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions client/driver/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestQemuDriver_StartOpen_Wait(t *testing.T) {
"main": 22,
"web": 8080,
}},
"args": []string{"-nodefconfig", "-nodefaults"},
},
LogConfig: &structs.LogConfig{
MaxFiles: 10,
Expand Down Expand Up @@ -105,6 +106,7 @@ func TestQemuDriverUser(t *testing.T) {
"main": 22,
"web": 8080,
}},
"args": []string{"-nodefconfig", "-nodefaults"},
},
LogConfig: &structs.LogConfig{
MaxFiles: 10,
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/drivers/qemu.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down

0 comments on commit 20cce5e

Please sign in to comment.