Skip to content

Commit

Permalink
Add support for number of displays in the vsphere builders (#201)
Browse files Browse the repository at this point in the history
* feat: add support for number of `displays` in the `vsphere` builders

Adds add support for number of `displays` in the `vsphere` builders.

Closes #80 

Added a link to the [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html) for maximums.

Signed-off-by: Ryan Johnson <[email protected]

Co-authored-by: Wilken Rivera <[email protected]>
  • Loading branch information
Ryan Johnson and nywilken authored Jun 29, 2022
1 parent ed96cf2 commit 25e41ad
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions builder/vsphere/clone/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion builder/vsphere/common/step_hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ type HardwareConfig struct {
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
// Enable RAM hot plug setting for virtual machine. Defaults to `false`.
MemoryHotAddEnabled bool `mapstructure:"RAM_hot_plug"`
// Amount of video memory in KB.
// Amount of video memory in KB. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html)
// for supported maximums. Defaults to 4096 KB.
VideoRAM int64 `mapstructure:"video_ram"`
// Number of video displays. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html)
// for supported maximums. Defaults to 1.
Displays int32 `mapstructure:"displays"`
// vGPU profile for accelerated graphics. See [NVIDIA GRID vGPU documentation](https://docs.nvidia.com/grid/latest/grid-vgpu-user-guide/index.html#configure-vmware-vsphere-vm-with-vgpu)
// for examples of profile names. Defaults to none.
VGPUProfile string `mapstructure:"vgpu_profile"`
Expand All @@ -57,6 +61,7 @@ func (c *HardwareConfig) Prepare() []error {
if c.Firmware != "" && c.Firmware != "bios" && c.Firmware != "efi" && c.Firmware != "efi-secure" {
errs = append(errs, fmt.Errorf("'firmware' must be '', 'bios', 'efi' or 'efi-secure'"))
}

if c.VTPMEnabled && c.Firmware != "efi" && c.Firmware != "efi-secure" {
errs = append(errs, fmt.Errorf("'vTPM' could be enabled only when 'firmware' set to 'efi' or 'efi-secure'"))
}
Expand Down Expand Up @@ -87,6 +92,7 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag)
CpuHotAddEnabled: s.Config.CpuHotAddEnabled,
MemoryHotAddEnabled: s.Config.MemoryHotAddEnabled,
VideoRAM: s.Config.VideoRAM,
Displays: s.Config.Displays,
VGPUProfile: s.Config.VGPUProfile,
Firmware: s.Config.Firmware,
ForceBIOSSetup: s.Config.ForceBIOSSetup,
Expand Down
2 changes: 2 additions & 0 deletions builder/vsphere/common/step_hardware.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions builder/vsphere/driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type HardwareConfig struct {
CpuHotAddEnabled bool
MemoryHotAddEnabled bool
VideoRAM int64
Displays int32
VGPUProfile string
Firmware string
ForceBIOSSetup bool
Expand Down Expand Up @@ -561,7 +562,11 @@ func (vm *VirtualMachineDriver) Configure(config *HardwareConfig) error {
confSpec.CpuHotAddEnabled = &config.CpuHotAddEnabled
confSpec.MemoryHotAddEnabled = &config.MemoryHotAddEnabled

if config.VideoRAM != 0 {
if config.Displays == 0 {
config.Displays = 1
}

if config.VideoRAM != 0 || config.Displays != 0 {
devices, err := vm.vm.Device(vm.driver.ctx)
if err != nil {
return err
Expand All @@ -571,15 +576,15 @@ func (vm *VirtualMachineDriver) Configure(config *HardwareConfig) error {
return err
}
card := l[0].(*types.VirtualMachineVideoCard)

card.VideoRamSizeInKB = config.VideoRAM

card.NumDisplays = config.Displays
spec := &types.VirtualDeviceConfigSpec{
Device: card,
Operation: types.VirtualDeviceConfigSpecOperationEdit,
}
confSpec.DeviceChange = append(confSpec.DeviceChange, spec)
}

if config.VGPUProfile != "" {
devices, err := vm.vm.Device(vm.driver.ctx)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions builder/vsphere/iso/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

- `RAM_hot_plug` (bool) - Enable RAM hot plug setting for virtual machine. Defaults to `false`.

- `video_ram` (int64) - Amount of video memory in KB.
- `video_ram` (int64) - Amount of video memory in KB. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html)
for supported maximums. Defaults to 4096 KB.

- `displays` (int32) - Number of video displays. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html)
for supported maximums. Defaults to 1.

- `vgpu_profile` (string) - vGPU profile for accelerated graphics. See [NVIDIA GRID vGPU documentation](https://docs.nvidia.com/grid/latest/grid-vgpu-user-guide/index.html#configure-vmware-vsphere-vm-with-vgpu)
for examples of profile names. Defaults to none.
Expand Down

0 comments on commit 25e41ad

Please sign in to comment.