diff --git a/clone/builder_acc_test.go b/clone/builder_acc_test.go index 63610233c..9f37fc4e3 100644 --- a/clone/builder_acc_test.go +++ b/clone/builder_acc_test.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/packer/packer" "github.com/jetbrains-infra/packer-builder-vsphere/common" commonT "github.com/jetbrains-infra/packer-builder-vsphere/common/testing" + "github.com/vmware/govmomi/vim25/types" "os" "testing" ) @@ -338,6 +339,7 @@ func hardwareConfig() string { config["RAM_reservation"] = 1024 config["CPU_hot_plug"] = true config["RAM_hot_plug"] = true + config["video_ram"] = 8192 return commonT.RenderConfig(config) } @@ -387,6 +389,18 @@ func checkHardware(t *testing.T) builderT.TestCheckFunc { t.Errorf("VM should have Memory hot add enabled, got %v", memoryHotAdd) } + l, err := vm.Devices() + if err != nil { + t.Fatalf("Cannot read VM devices: %v", err) + } + v := l.SelectByType((*types.VirtualMachineVideoCard)(nil)) + if len(v) != 1 { + t.Errorf("VM should have one video card") + } + if v[0].(*types.VirtualMachineVideoCard).VideoRamSizeInKB != 8192 { + t.Errorf("Video RAM should be equal 8192") + } + return nil } } diff --git a/common/step_hardware.go b/common/step_hardware.go index ea301127a..e9225a6f6 100644 --- a/common/step_hardware.go +++ b/common/step_hardware.go @@ -19,7 +19,8 @@ type HardwareConfig struct { RAMReserveAll bool `mapstructure:"RAM_reserve_all"` MemoryHotAddEnabled bool `mapstructure:"RAM_hot_plug"` - NestedHV bool `mapstructure:"NestedHV"` + VideoRAM int64 `mapstructure:"video_ram"` + NestedHV bool `mapstructure:"NestedHV"` } func (c *HardwareConfig) Prepare() []error { @@ -53,6 +54,7 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag) NestedHV: s.Config.NestedHV, CpuHotAddEnabled: s.Config.CpuHotAddEnabled, MemoryHotAddEnabled: s.Config.MemoryHotAddEnabled, + VideoRAM: s.Config.VideoRAM, }) if err != nil { state.Put("error", err) diff --git a/driver/vm.go b/driver/vm.go index 286b9518d..f5af74d20 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -37,6 +37,7 @@ type HardwareConfig struct { NestedHV bool CpuHotAddEnabled bool MemoryHotAddEnabled bool + VideoRAM int64 } type CreateConfig struct { @@ -277,6 +278,26 @@ func (vm *VirtualMachine) Configure(config *HardwareConfig) error { confSpec.CpuHotAddEnabled = &config.CpuHotAddEnabled confSpec.MemoryHotAddEnabled = &config.MemoryHotAddEnabled + if config.VideoRAM != 0 { + devices, err := vm.vm.Device(vm.driver.ctx) + if err != nil { + return err + } + l := devices.SelectByType((*types.VirtualMachineVideoCard)(nil)) + if len(l) != 1 { + return err + } + card := l[0].(*types.VirtualMachineVideoCard) + + card.VideoRamSizeInKB = config.VideoRAM + + spec := &types.VirtualDeviceConfigSpec{ + Device: card, + Operation: types.VirtualDeviceConfigSpecOperationEdit, + } + confSpec.DeviceChange = append(confSpec.DeviceChange, spec) + } + task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec) if err != nil { return err diff --git a/iso/builder_acc_test.go b/iso/builder_acc_test.go index 026ec0e3b..40a1a8e0f 100644 --- a/iso/builder_acc_test.go +++ b/iso/builder_acc_test.go @@ -161,6 +161,7 @@ func hardwareConfig() string { config["RAM_reservation"] = 1024 config["NestedHV"] = true config["firmware"] = "efi" + config["video_ram"] = 8192 return commonT.RenderConfig(config) } @@ -223,6 +224,14 @@ func checkHardware(t *testing.T) builderT.TestCheckFunc { t.Errorf("VM should have no SATA controllers") } + v := l.SelectByType((*types.VirtualMachineVideoCard)(nil)) + if len(v) != 1 { + t.Errorf("VM should have one video card") + } + if v[0].(*types.VirtualMachineVideoCard).VideoRamSizeInKB != 8192 { + t.Errorf("Video RAM should be equal 8192") + } + return nil } }