Skip to content

Commit

Permalink
implement boot_priority option
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof committed Jan 3, 2025
1 parent 6447f21 commit 9b99696
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .web-docs/components/builder/nutanix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ These parameters allow to define information about platform and temporary VM use
- `memory_mb` (number) - Size of vRAM for temporary VM (in megabytes).
- `cd_files` (array of strings) - A list of files to place onto a CD that is attached when the VM is booted. This can include either files or directories; any directories will be copied onto the CD recursively, preserving directory structure hierarchy.
- `cd_label` (string) - Label of this CD Drive.
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi").
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi", default is "legacy").
- `boot_priority` (string) - Priority of boot device ("cdrom" or "disk", default is "cdrom").
- `ip_wait_timeout` (duration string | ex: "0h42m0s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'. Defaults to 15m (15 minutes). See the Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration) documentation for full details.
- `vm_categories` ([]Category) - Assign Categories to the vm.
- `project` (string) - Assign Project to the vm.
Expand Down
17 changes: 17 additions & 0 deletions builder/nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const (

// NutanixIdentifierBootTypeUEFI is a resource identifier identifying the UEFI boot type for virtual machines.
NutanixIdentifierBootTypeUEFI string = "uefi"

// NutanixIdentifierBootPriorityDisk is a resource identifier identifying the boot priority as disk for virtual machines.
NutanixIdentifierBootPriorityDisk string = "disk"

// NutanixIdentifierBootPriorityCDROM is a resource identifier identifying the boot priority as cdrom for virtual machines.
NutanixIdentifierBootPriorityCDROM string = "cdrom"
)

type Config struct {
Expand Down Expand Up @@ -79,6 +85,7 @@ type VmConfig struct {
VMName string `mapstructure:"vm_name" json:"vm_name" required:"false"`
OSType string `mapstructure:"os_type" json:"os_type" required:"true"`
BootType string `mapstructure:"boot_type" json:"boot_type" required:"false"`
BootPriority string `mapstructure:"boot_priority" json:"boot_priority" required:"false"`
VmDisks []VmDisk `mapstructure:"vm_disks"`
VmNICs []VmNIC `mapstructure:"vm_nics"`
ImageName string `mapstructure:"image_name" json:"image_name" required:"false"`
Expand Down Expand Up @@ -135,6 +142,16 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.BootType = string(NutanixIdentifierBootTypeLegacy)
}

if c.BootType == NutanixIdentifierBootTypeUEFI && c.BootPriority != "" {
log.Println("Boot Priority is not supported for UEFI boot type")
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("UEFI does not support boot priority"))
}

if c.BootPriority != NutanixIdentifierBootPriorityDisk && c.BootPriority != NutanixIdentifierBootPriorityCDROM {
log.Println("No correct VM Boot Priority configured, defaulting to 'cdrom'")
c.BootPriority = string(NutanixIdentifierBootPriorityCDROM)
}

// Validate Cluster Endpoint
if c.ClusterConfig.Endpoint == "" {
log.Println("Nutanix Endpoint missing from configuration")
Expand Down
4 changes: 4 additions & 0 deletions builder/nutanix/config.hcl2spec.go

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

25 changes: 24 additions & 1 deletion builder/nutanix/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,34 @@ func (d *NutanixDriver) CreateRequest(ctx context.Context, vm VmConfig, state mu
}

if vm.BootType == NutanixIdentifierBootTypeUEFI {
bootType := strings.ToUpper(vm.BootType)
bootType := strings.ToUpper(NutanixIdentifierBootTypeUEFI)

req.Spec.Resources.BootConfig = &v3.VMBootConfig{
BootType: &bootType,
}
} else {
bootType := strings.ToUpper(NutanixIdentifierBootTypeLegacy)

var bootDeviceOrderList []*string

if vm.BootPriority == "cdrom" {
bootDeviceOrderList = []*string{
StringPtr("CDROM"),
StringPtr("DISK"),
StringPtr("NETWORK"),
}
} else {
bootDeviceOrderList = []*string{
StringPtr("DISK"),
StringPtr("CDROM"),
StringPtr("NETWORK"),
}
}
req.Spec.Resources.BootConfig = &v3.VMBootConfig{
BootType: &bootType,
BootDeviceOrderList: bootDeviceOrderList,
}

}

if len(vm.VMCategories) != 0 {
Expand Down
3 changes: 2 additions & 1 deletion docs/builders/nutanix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ These parameters allow to define information about platform and temporary VM use
- `memory_mb` (number) - Size of vRAM for temporary VM (in megabytes).
- `cd_files` (array of strings) - A list of files to place onto a CD that is attached when the VM is booted. This can include either files or directories; any directories will be copied onto the CD recursively, preserving directory structure hierarchy.
- `cd_label` (string) - Label of this CD Drive.
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi").
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi", default is "legacy").
- `boot_priority` (string) - Priority of boot device ("cdrom" or "disk", default is "cdrom").
- `ip_wait_timeout` (duration string | ex: "0h42m0s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'. Defaults to 15m (15 minutes). See the Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration) documentation for full details.
- `vm_categories` ([]Category) - Assign Categories to the vm.
- `project` (string) - Assign Project to the vm.
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Creating Ubuntu from Upstream Image and running Provisioner:
packer build -only nutanix.ubuntu .

Creating from ISO with Kickstart-File:
packer build -only nutanix.centos-kickerstart .
packer build -only nutanix.centos-kickstart .

Windows Image (ISO Boot, VirtIO Drivers, cd_files)
packer build -only nutanix.windows .
Expand Down
4 changes: 4 additions & 0 deletions example/source.nutanix.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ source "nutanix" "centos-kickstart" {
cd_files = ["scripts/ks.cfg"]
cd_label = "OEMDRV"

boot_priority = "disk"

image_name ="centos8-{{isotime `Jan-_2-15:04:05`}}"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
shutdown_timeout = "2m"
Expand Down Expand Up @@ -131,6 +133,8 @@ source "nutanix" "windows" {

cd_files = ["scripts/gui/autounattend.xml","scripts/win-update.ps1"]

boot_priority = "disk"

image_name ="win-{{isotime `Jan-_2-15:04:05`}}"
shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\""
shutdown_timeout = "3m"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/centos-iso/source.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ source "nutanix" "centos" {
image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
image_delete = true

boot_priority = "disk"

force_deregister = true

Expand Down

0 comments on commit 9b99696

Please sign in to comment.