add option to destroy vm after deploy to content library (#9569)

This commit is contained in:
Sylvia Moss 2020-07-14 10:07:20 +02:00 committed by GitHub
parent 1400662db7
commit 3a0dfa1259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View File

@ -44,6 +44,8 @@ type ContentLibraryDestinationConfig struct {
// The datastore for the virtual machine template's configuration and log files.
// Defaults to the storage backing associated with the library specified by library.
Datastore string `mapstructure:"datastore"`
// If set to true, the VM will be destroyed after deploying the template to the Content Library. Defaults to `false`.
Destroy bool `mapstructure:"destroy"`
}
func (c *ContentLibraryDestinationConfig) Prepare(lc *LocationConfig) []error {
@ -120,6 +122,10 @@ func (s *StepImportToContentLibrary) Run(_ context.Context, state multistep.Stat
return multistep.ActionHalt
}
if s.ContentLibConfig.Destroy {
state.Put("destroy_vm", s.ContentLibConfig.Destroy)
}
return multistep.ActionContinue
}

View File

@ -17,6 +17,7 @@ type FlatContentLibraryDestinationConfig struct {
Host *string `mapstructure:"host" cty:"host" hcl:"host"`
ResourcePool *string `mapstructure:"resource_pool" cty:"resource_pool" hcl:"resource_pool"`
Datastore *string `mapstructure:"datastore" cty:"datastore" hcl:"datastore"`
Destroy *bool `mapstructure:"destroy" cty:"destroy" hcl:"destroy"`
}
// FlatMapstructure returns a new FlatContentLibraryDestinationConfig.
@ -39,6 +40,7 @@ func (*FlatContentLibraryDestinationConfig) HCL2Spec() map[string]hcldec.Spec {
"host": &hcldec.AttrSpec{Name: "host", Type: cty.String, Required: false},
"resource_pool": &hcldec.AttrSpec{Name: "resource_pool", Type: cty.String, Required: false},
"datastore": &hcldec.AttrSpec{Name: "datastore", Type: cty.String, Required: false},
"destroy": &hcldec.AttrSpec{Name: "destroy", Type: cty.Bool, Required: false},
}
return s
}

View File

@ -207,7 +207,8 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
func (s *StepCreateVM) Cleanup(state multistep.StateBag) {
_, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted)
if !cancelled && !halted {
_, destroy := state.GetOk("destroy_vm")
if !cancelled && !halted && !destroy {
return
}

View File

@ -27,3 +27,5 @@
- `datastore` (string) - The datastore for the virtual machine template's configuration and log files.
Defaults to the storage backing associated with the library specified by library.
- `destroy` (bool) - If set to true, the VM will be destroyed after deploying the template to the Content Library. Defaults to `false`.