Skip to content

Commit

Permalink
add uefi support / fix delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof committed Sep 25, 2023
1 parent 40a52c9 commit 0bf0f27
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ If you want to use Nutanix Node Driver, you need add it in order to start using
| `nutanix-password` | The password of the nutanix management account | yes | |
| `nutanix-insecure` | Set to true to force SSL insecure connection | no | false |
| `nutanix-cluster` | The name of the cluster where deploy the VM (case sensitive) | yes | |
| `nutanix-boot-type` | The boot type of the VM (legacy or uefi) | no | legacy |
| `nutanix-vm-mem` | The amount of RAM of the newly created VM (MB) | no | 2 GB |
| `nutanix-vm-cpus` | The number of cpus in the newly created VM (core) | no | 2 |
| `nutanix-vm-cores` | The number of cores per vCPU | no | 1 |
Expand Down
61 changes: 51 additions & 10 deletions machine/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
)

const (
defaultVMMem = 2048
defaultVCPUs = 2
defaultCores = 1
defaultVMMem = 2048
defaultVCPUs = 2
defaultCores = 1
defaultBootType = "legacy"
)

// NutanixDriver driver structure
Expand Down Expand Up @@ -55,6 +56,7 @@ type NutanixDriver struct {
CloudInit string
SerialPort bool
Project string
BootType string
}

// NewDriver create new instance
Expand Down Expand Up @@ -99,6 +101,14 @@ func (d *NutanixDriver) Create() error {
res.NumSockets = utils.Int64Ptr(int64(d.VMVCPUs))
res.NumVcpusPerSocket = utils.Int64Ptr(int64(d.VMCores))

// Configure BootType
log.Infof("Set BootType to %s", d.BootType)
res.BootConfig = &v3.VMBootConfig{}
res.BootConfig.BootType = utils.StringPtr(strings.ToUpper(d.BootType))
if d.BootType == "legacy" {
res.BootConfig.BootDeviceOrderList = append(res.BootConfig.BootDeviceOrderList, utils.StringPtr("DISK"))
}

// Configure CPU Passthrough
if d.VMCPUPassthrough {
res.EnableCPUPassthrough = utils.BoolPtr(d.VMCPUPassthrough)
Expand Down Expand Up @@ -621,6 +631,12 @@ func (d *NutanixDriver) GetCreateFlags() []mcnflag.Flag {
Usage: "The name of the project to assign the VM",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "NUTANIX_BOOT_TYPE",
Name: "nutanix-boot-type",
Usage: "The boot type of the VM (legacy or uefi)",
Value: defaultBootType,
},
}
}

Expand Down Expand Up @@ -705,17 +721,36 @@ func (d *NutanixDriver) Remove() error {

taskUUID := resp.Status.ExecutionContext.TaskUUID.(string)

// Wait for the VM to be deleted
for i := 0; i < 1200; i++ {
log.Infof("waiting to delete vm %s (%s): task %s", name, d.VMId, taskUUID)

// Wait end of the task
waitTask:
for i := 0; i < 60; i++ {
resp, err := conn.V3.GetTask(taskUUID)
if err != nil || *resp.Status != "SUCCEEDED" {
<-time.After(1 * time.Second)
continue
if err != nil {
log.Errorf("Error getting task: [%v]", err)
return err
}
return err

switch *resp.Status {
case "SUCCEEDED":
log.Infof("VM %s deletion task succeeded", name)
break waitTask
case "FAILED":
errMsg := strings.ReplaceAll(*resp.ErrorDetail, "\n", " ")
log.Errorf("Error deleting vm: [%v]", errMsg)
return errors.New(errMsg)
}
if i == 59 {
log.Errorf("Timeout waiting to delete vm %s", name)
return errors.New("timeout waiting to delete vm")
}
log.Infof("VM %s deletion is in %s state", name, *resp.Status)
<-time.After(5 * time.Second)

}
return fmt.Errorf("unable to delete VM %s", name)

return nil
}

// Restart a host. This may just call Stop(); Start() if the provider does not
Expand Down Expand Up @@ -775,6 +810,12 @@ func (d *NutanixDriver) SetConfigFromFlags(opts drivers.DriverOptions) error {
d.CloudInit = opts.String("nutanix-cloud-init")
d.SerialPort = opts.Bool("nutanix-vm-serial-port")
d.Project = opts.String("nutanix-project")

d.BootType = opts.String("nutanix-boot-type")
if d.BootType != "uefi" && d.BootType != "legacy" {
return fmt.Errorf("nutanix-boot-type %s is invalid", d.BootType)
}

return nil
}

Expand Down

0 comments on commit 0bf0f27

Please sign in to comment.