Add 'video_ram' parameter (#197)
This commit is contained in:
parent
b107245aed
commit
70b6d6a8b3
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
21
driver/vm.go
21
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue