Skip to content

Commit

Permalink
add UEFI boot type (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof authored Jul 29, 2022
1 parent 7b83719 commit 07ece68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions builder/nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ import (
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

const (
// NutanixIdentifierBootTypeLegacy is a resource identifier identifying the legacy boot type for virtual machines.
NutanixIdentifierBootTypeLegacy string = "legacy"

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

type Config struct {
common.PackerConfig `mapstructure:",squash"`
CommConfig communicator.Config `mapstructure:",squash"`
Expand Down Expand Up @@ -52,6 +60,7 @@ type VmNIC struct {
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"`
VmDisks []VmDisk `mapstructure:"vm_disks"`
VmNICs []VmNIC `mapstructure:"vm_nics"`
ImageName string `mapstructure:"image_name" json:"image_name" required:"false"`
Expand Down Expand Up @@ -109,6 +118,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.ClusterConfig.Port = 9440
}

if c.BootType != NutanixIdentifierBootTypeLegacy && c.BootType != NutanixIdentifierBootTypeUEFI {
log.Println("No correct VM Boot Type configured, defaulting to 'legacy'")
c.BootType = string(NutanixIdentifierBootTypeLegacy)
}

// Validate Cluster Username
if c.ClusterConfig.Username == "" {
log.Println("Nutanix Username 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.

9 changes: 9 additions & 0 deletions builder/nutanix/driver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nutanix

import (
"strings"
"time"

"fmt"
Expand Down Expand Up @@ -343,6 +344,14 @@ func (d *NutanixDriver) CreateRequest(vm VmConfig) (*v3.VMIntentInput, error) {
},
}

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

req.Spec.Resources.BootConfig = &v3.VMBootConfig{
BootType: &bootType,
}
}

return req, nil

}
Expand Down

0 comments on commit 07ece68

Please sign in to comment.