option to keep the VM registered with esxi
This commit is contained in:
parent
b50036c817
commit
84bd2ff754
|
@ -46,6 +46,7 @@ type Config struct {
|
|||
Version string `mapstructure:"version"`
|
||||
VMName string `mapstructure:"vm_name"`
|
||||
BootCommand []string `mapstructure:"boot_command"`
|
||||
KeepRegistered bool `mapstructure:"keep_registered"`
|
||||
SkipCompaction bool `mapstructure:"skip_compaction"`
|
||||
VMXTemplatePath string `mapstructure:"vmx_template_path"`
|
||||
VMXDiskTemplatePath string `mapstructure:"vmx_disk_template_path"`
|
||||
|
@ -147,7 +148,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
if b.config.RemotePort == 0 {
|
||||
b.config.RemotePort = 22
|
||||
}
|
||||
|
||||
if b.config.VMXTemplatePath != "" {
|
||||
if err := b.validateVMXTemplatePath(); err != nil {
|
||||
errs = packer.MultiErrorAppend(
|
||||
|
|
|
@ -41,6 +41,14 @@ func (s *StepRegister) Cleanup(state multistep.StateBag) {
|
|||
|
||||
driver := state.Get("driver").(vmwcommon.Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
config := state.Get("config").(*Config)
|
||||
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
if (config.KeepRegistered == true) && (!cancelled && !halted) {
|
||||
ui.Say("Keeping virtual machine registered with ESX host (keep_registered = true)")
|
||||
return
|
||||
}
|
||||
|
||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||
if s.Format == "" {
|
||||
|
|
|
@ -32,6 +32,10 @@ func TestStepRegister_remoteDriver(t *testing.T) {
|
|||
step := new(StepRegister)
|
||||
|
||||
driver := new(RemoteDriverMock)
|
||||
var config Config
|
||||
config.KeepRegistered = false
|
||||
state.Put("config", &config)
|
||||
|
||||
state.Put("driver", driver)
|
||||
state.Put("vmx_path", "foo")
|
||||
|
||||
|
@ -63,3 +67,29 @@ func TestStepRegister_remoteDriver(t *testing.T) {
|
|||
t.Fatal("should unregister proper path")
|
||||
}
|
||||
}
|
||||
func TestStepRegister_WithoutUnregister_remoteDriver(t *testing.T) {
|
||||
state := testState(t)
|
||||
step := new(StepRegister)
|
||||
|
||||
driver := new(RemoteDriverMock)
|
||||
var config Config
|
||||
config.KeepRegistered = true
|
||||
state.Put("config", &config)
|
||||
|
||||
state.Put("driver", driver)
|
||||
state.Put("vmx_path", "foo")
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(state); action != multistep.ActionContinue {
|
||||
t.Fatalf("bad action: %#v", action)
|
||||
}
|
||||
if _, ok := state.GetOk("error"); ok {
|
||||
t.Fatal("should NOT have error")
|
||||
}
|
||||
|
||||
// cleanup
|
||||
step.Cleanup(state)
|
||||
if driver.UnregisterCalled {
|
||||
t.Fatal("unregister should not be called")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue