Skip to content

Commit

Permalink
feat: add support for dynamic directpath i/o
Browse files Browse the repository at this point in the history
Adding support for vSphere Dynamic DirectPath I/O.
  • Loading branch information
kshivakumar-nvidia authored and tenthirtyam committed Mar 2, 2024
1 parent 30d53c6 commit deb3a59
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .web-docs/components/builder/vsphere-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,10 @@ wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/foo/bar/preseed.cfg
- `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)
- `pci_passthrough_allowed_device` ([]PCIPassthroughAllowedDevice) - Configure Dynamic DirectPath I/O PCI Passthrough for virtual machine. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-5B3CAB26-5D06-4A99-92A0-3A04C69CE64B.html)

- `vgpu_profile` (string) - vGPU profile for accelerated graphics.
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.

- `NestedHV` (bool) - Enable nested hardware virtualization for VM. Defaults to `false`.
Expand Down
5 changes: 4 additions & 1 deletion .web-docs/components/builder/vsphere-iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/foo/bar/preseed.cfg
- `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)
- `pci_passthrough_allowed_device` ([]PCIPassthroughAllowedDevice) - Configure Dynamic DirectPath I/O PCI Passthrough for virtual machine. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-5B3CAB26-5D06-4A99-92A0-3A04C69CE64B.html)

- `vgpu_profile` (string) - vGPU profile for accelerated graphics.
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.

- `NestedHV` (bool) - Enable nested hardware virtualization for VM. Defaults to `false`.
Expand Down
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.

21 changes: 19 additions & 2 deletions builder/vsphere/common/step_hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type HardwareConfig
//go:generate packer-sdc mapstructure-to-hcl2 -type HardwareConfig,PCIPassthroughAllowedDevice

package common

import (
"context"
"fmt"
"reflect"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver"
)

type PCIPassthroughAllowedDevice struct {
DeviceId string `mapstructure:"device_id"`
VendorId string `mapstructure:"vendor_id"`
SubVendorId string `mapstructure:"sub_vendor_id"`
SubDeviceId string `mapstructure:"sub_device_id"`
}

type HardwareConfig struct {
// Number of CPU cores.
CPUs int32 `mapstructure:"CPUs"`
Expand All @@ -41,6 +49,9 @@ type HardwareConfig struct {
// 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"`
// Configure Dynamic DirectPath I/O PCI Passthrough for virtual machine. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-5B3CAB26-5D06-4A99-92A0-3A04C69CE64B.html)
AllowedDevices []PCIPassthroughAllowedDevice `mapstructure:"pci_passthrough_allowed_device"`
// vGPU profile for accelerated graphics.
// 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 Down Expand Up @@ -86,9 +97,14 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag)
ui := state.Get("ui").(packersdk.Ui)
vm := state.Get("vm").(driver.VirtualMachine)

if *s.Config != (HardwareConfig{}) {
if !reflect.DeepEqual(*s.Config, HardwareConfig{}) {
ui.Say("Customizing hardware...")

var allowedDevices []driver.PCIPassthroughAllowedDevice
for _, device := range s.Config.AllowedDevices {
allowedDevices = append(allowedDevices, driver.PCIPassthroughAllowedDevice(device))
}

err := vm.Configure(&driver.HardwareConfig{
CPUs: s.Config.CPUs,
CpuCores: s.Config.CpuCores,
Expand All @@ -102,6 +118,7 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag)
MemoryHotAddEnabled: s.Config.MemoryHotAddEnabled,
VideoRAM: s.Config.VideoRAM,
Displays: s.Config.Displays,
AllowedDevices: allowedDevices,
VGPUProfile: s.Config.VGPUProfile,
Firmware: s.Config.Firmware,
ForceBIOSSetup: s.Config.ForceBIOSSetup,
Expand Down
99 changes: 65 additions & 34 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.

7 changes: 7 additions & 0 deletions builder/vsphere/common/step_hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ func basicStepConfigureHardware() *StepConfigureHardware {
}

func driverHardwareConfigFromConfig(config *HardwareConfig) *driver.HardwareConfig {

var allowedDevices []driver.PCIPassthroughAllowedDevice
for _, device := range config.AllowedDevices {
allowedDevices = append(allowedDevices, driver.PCIPassthroughAllowedDevice(device))
}

return &driver.HardwareConfig{
CPUs: config.CPUs,
CpuCores: config.CpuCores,
Expand All @@ -225,6 +231,7 @@ func driverHardwareConfigFromConfig(config *HardwareConfig) *driver.HardwareConf
CpuHotAddEnabled: config.CpuHotAddEnabled,
MemoryHotAddEnabled: config.MemoryHotAddEnabled,
VideoRAM: config.VideoRAM,
AllowedDevices: allowedDevices,
VGPUProfile: config.VGPUProfile,
Firmware: config.Firmware,
ForceBIOSSetup: config.ForceBIOSSetup,
Expand Down
Loading

0 comments on commit deb3a59

Please sign in to comment.