From 09edada93d5979deb761ce059e30946f3d86c81d Mon Sep 17 00:00:00 2001 From: James Griffith Date: Tue, 13 Oct 2020 15:12:28 -0400 Subject: [PATCH] moved the warning into Prepare() and updated the invocation --- builder/vsphere/common/step_shutdown.go | 15 +++++++-------- builder/vsphere/iso/config.go | 6 +++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/builder/vsphere/common/step_shutdown.go b/builder/vsphere/common/step_shutdown.go index 468caf675..4eeb38e9c 100644 --- a/builder/vsphere/common/step_shutdown.go +++ b/builder/vsphere/common/step_shutdown.go @@ -11,6 +11,7 @@ import ( "time" "github.com/hashicorp/packer/builder/vsphere/driver" + "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -33,14 +34,17 @@ type ShutdownConfig struct { DisableShutdown bool `mapstructure:"disable_shutdown"` } -func (c *ShutdownConfig) Prepare() []error { - var errs []error +func (c *ShutdownConfig) Prepare(comm communicator.Config) (warnings []string, errs []error) { if c.Timeout == 0 { c.Timeout = 5 * time.Minute } - return errs + if comm.Type == "none" && c.Command != "" { + warnings = append(warnings, "The parameter `shutdown_command` is ignored as it requires a `communicator`.") + } + + return } type StepShutdown struct { @@ -59,11 +63,6 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis if state.Get("communicator") == nil { - ui.Say("The `communicator` is 'none', automatic shutdown disabled.") - if s.Config.Command != "" { - ui.Message("The parameter `shutdown_command` is ignored as it requires a `communicator`.") - } - msg := fmt.Sprintf("Please shutdown virtual machine within %s.", s.Config.Timeout) ui.Message(msg) diff --git a/builder/vsphere/iso/config.go b/builder/vsphere/iso/config.go index 3d9601524..791f80cc9 100644 --- a/builder/vsphere/iso/config.go +++ b/builder/vsphere/iso/config.go @@ -86,7 +86,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) { errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.WaitIpConfig.Prepare()...) errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...) - errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...) + + shutdownWarnings, shutdownErrs := c.ShutdownConfig.Prepare(c.Comm) + warnings = append(warnings, shutdownWarnings...) + errs = packer.MultiErrorAppend(errs, shutdownErrs...) + if c.Export != nil { errs = packer.MultiErrorAppend(errs, c.Export.Prepare(&c.ctx, &c.LocationConfig, &c.PackerConfig)...) }