Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-1588 : Allow extra driver config args as a passthrough for qemu… #1596

Merged
merged 2 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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