Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add UEFI boot type #32

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -104,6 +113,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 @@ -342,6 +343,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