Add `guest_agent` config option for QEMU driver (#12800)
Add boolean 'guest_agent' config option for QEMU driver, which will create the socket file for the QEMU Guest Agent in the task dir when enabled.
This commit is contained in:
parent
34dea90d7a
commit
94a78597d2
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
qemu: add support for guest agent socket
|
||||||
|
```
|
|
@ -41,6 +41,9 @@ const (
|
||||||
qemuGracefulShutdownMsg = "system_powerdown\n"
|
qemuGracefulShutdownMsg = "system_powerdown\n"
|
||||||
qemuMonitorSocketName = "qemu-monitor.sock"
|
qemuMonitorSocketName = "qemu-monitor.sock"
|
||||||
|
|
||||||
|
// Socket file enabling communication with the Qemu Guest Agent (if enabled and running)
|
||||||
|
qemuGuestAgentSocketName = "qemu-guest-agent.sock"
|
||||||
|
|
||||||
// Maximum socket path length prior to qemu 2.10.1
|
// Maximum socket path length prior to qemu 2.10.1
|
||||||
qemuLegacyMaxMonitorPathLen = 108
|
qemuLegacyMaxMonitorPathLen = 108
|
||||||
|
|
||||||
|
@ -94,6 +97,7 @@ var (
|
||||||
"image_path": hclspec.NewAttr("image_path", "string", true),
|
"image_path": hclspec.NewAttr("image_path", "string", true),
|
||||||
"accelerator": hclspec.NewAttr("accelerator", "string", false),
|
"accelerator": hclspec.NewAttr("accelerator", "string", false),
|
||||||
"graceful_shutdown": hclspec.NewAttr("graceful_shutdown", "bool", false),
|
"graceful_shutdown": hclspec.NewAttr("graceful_shutdown", "bool", false),
|
||||||
|
"guest_agent": hclspec.NewAttr("guest_agent", "bool", false),
|
||||||
"args": hclspec.NewAttr("args", "list(string)", false),
|
"args": hclspec.NewAttr("args", "list(string)", false),
|
||||||
"port_map": hclspec.NewAttr("port_map", "list(map(number))", false),
|
"port_map": hclspec.NewAttr("port_map", "list(map(number))", false),
|
||||||
})
|
})
|
||||||
|
@ -121,6 +125,7 @@ type TaskConfig struct {
|
||||||
Args []string `codec:"args"` // extra arguments to qemu executable
|
Args []string `codec:"args"` // extra arguments to qemu executable
|
||||||
PortMap hclutils.MapStrInt `codec:"port_map"` // A map of host port and the port name defined in the image manifest file
|
PortMap hclutils.MapStrInt `codec:"port_map"` // A map of host port and the port name defined in the image manifest file
|
||||||
GracefulShutdown bool `codec:"graceful_shutdown"`
|
GracefulShutdown bool `codec:"graceful_shutdown"`
|
||||||
|
GuestAgent bool `codec:"guest_agent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskState is the state which is encoded in the handle returned in StartTask.
|
// TaskState is the state which is encoded in the handle returned in StartTask.
|
||||||
|
@ -450,6 +455,17 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
|
||||||
args = append(args, "-monitor", fmt.Sprintf("unix:%s,server,nowait", monitorPath))
|
args = append(args, "-monitor", fmt.Sprintf("unix:%s,server,nowait", monitorPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if driverConfig.GuestAgent {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return nil, nil, errors.New("QEMU Guest Agent socket is unsupported on the Windows platform")
|
||||||
|
}
|
||||||
|
// This socket will be used to communicate with the Guest Agent (if it's running)
|
||||||
|
taskDir := filepath.Join(cfg.AllocDir, cfg.Name)
|
||||||
|
args = append(args, "-chardev", fmt.Sprintf("socket,path=%s/%s,server,nowait,id=qga0", taskDir, qemuGuestAgentSocketName))
|
||||||
|
args = append(args, "-device", "virtio-serial")
|
||||||
|
args = append(args, "-device", "virtserialport,chardev=qga0,name=org.qemu.guest_agent.0")
|
||||||
|
}
|
||||||
|
|
||||||
// Add pass through arguments to qemu executable. A user can specify
|
// Add pass through arguments to qemu executable. A user can specify
|
||||||
// these arguments in driver task configuration. These arguments are
|
// these arguments in driver task configuration. These arguments are
|
||||||
// passed directly to the qemu driver as command line options.
|
// passed directly to the qemu driver as command line options.
|
||||||
|
|
|
@ -61,6 +61,13 @@ The `qemu` driver supports the following configuration in the job spec:
|
||||||
[alloc_dir](/docs/configuration/client#alloc_dir)
|
[alloc_dir](/docs/configuration/client#alloc_dir)
|
||||||
paths.) This feature is currently not supported on Windows.
|
paths.) This feature is currently not supported on Windows.
|
||||||
|
|
||||||
|
- `guest_agent` `(bool: false)` - Enable support for the [QEMU Guest
|
||||||
|
Agent](https://wiki.qemu.org/Features/GuestAgent) for this virtual machine. This
|
||||||
|
will add the necessary virtual hardware and create a `qemu-guest-agent.sock`
|
||||||
|
file in the task's working directory for interacting with the agent. The QEMU Guest
|
||||||
|
Agent must be running in the guest VM. This feature is currently not supported
|
||||||
|
on Windows.
|
||||||
|
|
||||||
- `port_map` - (Optional) A key-value map of port labels.
|
- `port_map` - (Optional) A key-value map of port labels.
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
|
|
Loading…
Reference in New Issue