Skip to content
Draft
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
7 changes: 7 additions & 0 deletions lib/hypervisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type VMConfig struct {

// Console
SerialLogPath string
Display *DisplayConfig

// Vsock
VsockCID int64
Expand All @@ -41,6 +42,12 @@ type VMConfig struct {
EnableRosetta bool
}

// DisplayConfig describes an optional virtual display adapter.
type DisplayConfig struct {
Device string
SocketPath string
}

// GuestMemoryConfig contains hypervisor-agnostic guest memory feature toggles.
type GuestMemoryConfig struct {
EnableBalloon bool
Expand Down
10 changes: 8 additions & 2 deletions lib/hypervisor/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ func buildArgs(cfg hypervisor.VMConfig, machine MachineType) []string {
args = append(args, "-serial", "stdio")
}

// No graphics
args = append(args, "-nographic")
if cfg.Display != nil {
args = append(args, "-device", cfg.Display.Device, "-display", "none")
if cfg.Display.SocketPath != "" {
args = append(args, "-vnc", "unix:"+cfg.Display.SocketPath)
}
} else {
args = append(args, "-nographic")
}

// Disable default devices we don't need
args = append(args, "-nodefaults")
Expand Down
19 changes: 19 additions & 0 deletions lib/hypervisor/qemu/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ func TestBuildArgs_Basic(t *testing.T) {
assert.Contains(t, args, "-nographic")
}

func TestBuildArgs_Display(t *testing.T) {
cfg := hypervisor.VMConfig{
VCPUs: 2,
MemoryBytes: 1024 * 1024 * 1024,
Display: &hypervisor.DisplayConfig{
Device: "VGA",
SocketPath: "/instance/display.sock",
},
}

args := BuildArgs(cfg)
assert.Contains(t, args, "VGA")
assert.Contains(t, args, "-display")
assert.Contains(t, args, "none")
assert.Contains(t, args, "-vnc")
assert.Contains(t, args, "unix:/instance/display.sock")
assert.NotContains(t, args, "-nographic")
}

func TestBuildArgs_Disks(t *testing.T) {
cfg := hypervisor.VMConfig{
VCPUs: 1,
Expand Down
10 changes: 7 additions & 3 deletions lib/instances/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ func (m *manager) buildWindowsHypervisorConfig(inst *Instance, image *images.Ima
Disks: []hypervisor.DiskConfig{{Path: m.paths.InstanceWindowsDisk(inst.Id), Format: hypervisor.DiskFormatQCOW2, IOBps: ioBps, IOBurstBps: burstBps}},
Networks: networks,
SerialLogPath: m.paths.InstanceAppLog(inst.Id),
VsockCID: inst.VsockCID,
VsockSocket: inst.VsockSocket,
BootMode: hypervisor.BootModeUEFI,
Display: &hypervisor.DisplayConfig{
Device: "VGA",
SocketPath: m.paths.InstanceSocket(inst.Id, "display.sock"),
},
VsockCID: inst.VsockCID,
VsockSocket: inst.VsockSocket,
BootMode: hypervisor.BootModeUEFI,
Firmware: &hypervisor.FirmwareConfig{
CodePath: m.paths.InstanceOVMFCode(inst.Id),
VarsPath: m.paths.InstanceOVMFVars(inst.Id),
Expand Down
3 changes: 3 additions & 0 deletions lib/instances/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ func TestBuildWindowsHypervisorConfig(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, hypervisor.BootModeUEFI, config.BootMode)
assert.True(t, config.Firmware.SecureBoot)
require.NotNil(t, config.Display)
assert.Equal(t, "VGA", config.Display.Device)
assert.Equal(t, p.InstanceSocket(stored.Id, "display.sock"), config.Display.SocketPath)
assert.Equal(t, p.InstanceTPMDir(stored.Id), config.TPM.StateDir)
require.Len(t, config.Disks, 1)
assert.Equal(t, hypervisor.DiskFormatQCOW2, config.Disks[0].Format)
Expand Down
Loading