Merge pull request #1596 from ramukima/qemu-extra-args-issue-1588

issue-1588 : Allow extra driver config args as a passthrough for qemu…
This commit is contained in:
Diptanu Choudhury
2016-08-16 11:17:12 -07:00
committed by GitHub
3 changed files with 17 additions and 2 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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"