Skip to content

Commit

Permalink
implement image_delete (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof authored Feb 15, 2023
1 parent 22648cd commit ed683a3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions builder/nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
ImageDescription string `mapstructure:"image_description" json:"image_description" required:"false"`
ImageCategoryKey string `mapstructure:"image_category_key" json:"image_category_key" required:"false"`
ImageCategoryValue string `mapstructure:"image_category_value" json:"image_category_value" required:"false"`
ImageDelete bool `mapstructure:"image_delete" json:"image_delete" required:"false"`
WaitTimeout time.Duration `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" 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.

18 changes: 18 additions & 0 deletions builder/nutanix/step_copy_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ func (s *stepCopyImage) Run(ctx context.Context, state multistep.StateBag) multi
}

func (s *stepCopyImage) Cleanup(state multistep.StateBag) {
ui := state.Get("ui").(packer.Ui)
d := state.Get("driver").(Driver)

if !s.Config.ImageDelete {
return
}

if imgUUID, ok := state.GetOk("image_uuid"); ok {
ui.Say(fmt.Sprintf("Deleting image %s...", s.Config.ImageName))

err := d.DeleteImage(imgUUID.(string))
if err != nil {
ui.Error("An error occurred while deleting image")
return
} else {
ui.Message("Image successfully deleted")
}
}
}
1 change: 1 addition & 0 deletions docs/builders/nutanix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ These parameters allow to configure everything around image creation, from the t
- `image_category_key` (string) - Name of the category to assign to the image.
- `image_category_value` (string) - Value of the category to assign to the image.
- `force_deregister` (bool) - Allow output image override if already exists.
- `image_delete` (bool) - Delete image once build process is completed.
- `shutdown_command` (string) - Command line to shutdown your temporary VM.
- `shutdown_timeout` (string) - Timeout for VM shutdown (format : 2m).
- `communicator` (string) - Protocol used for Packer connection (ex "winrm" or "ssh"). Default is : "ssh".
Expand Down

0 comments on commit ed683a3

Please sign in to comment.