Skip to content

Commit

Permalink
implement force_delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof committed Aug 7, 2023
1 parent 694c5b5 commit d0fd2b4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions builder/nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
ImageDelete bool `mapstructure:"image_delete" json:"image_delete" required:"false"`
ImageExport bool `mapstructure:"image_export" json:"image_export" required:"false"`
WaitTimeout time.Duration `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" required:"false"`
ForceDelete bool `mapstructure:"force_delete" json:"force_delete" required:"false"`

ctx interpolate.Context
}
Expand Down
2 changes: 2 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.

15 changes: 9 additions & 6 deletions builder/nutanix/step_build_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ func (s *stepBuildVM) Cleanup(state multistep.StateBag) {
return
}

ui := state.Get("ui").(packer.Ui)
d := state.Get("driver").(Driver)
config := state.Get("config").(*Config)

_, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted)

d := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)

if cancelled || halted {
if cancelled || halted && !config.ForceDelete {
ui.Say("Task cancelled, virtual machine is not deleted")
return
} else if config.ForceDelete && cancelled || halted {
ui.Say("Force Deleting virtual machine...")
} else {
ui.Say("Deleting virtual machine...")
}

ui.Say("Deleting virtual machine...")

if cdUUID, ok := state.GetOk("cd_uuid"); ok {
err := d.DeleteImage(cdUUID.(string))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions docs/builders/nutanix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ These parameters allow to define information about platform and temporary VM use
- `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.
- `force_delete` (bool) - Delete vm even if build is not succesful (default is false).


## Output configuration
Expand Down

0 comments on commit d0fd2b4

Please sign in to comment.