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

implement image_delete #106

Merged
merged 1 commit into from
Feb 15, 2023
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
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