From bb8ced8cc9efc2c57797a3bcd320b8cb606cf95f Mon Sep 17 00:00:00 2001 From: Evan Powell Date: Tue, 20 Oct 2015 17:00:48 -0500 Subject: [PATCH] Implement a null-object communicator for 'none' Fixes #2736 --- communicator/none/communicator.go | 40 +++++++++++++++++++++++++++++ helper/communicator/step_connect.go | 11 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 communicator/none/communicator.go diff --git a/communicator/none/communicator.go b/communicator/none/communicator.go new file mode 100644 index 000000000..8b0603f01 --- /dev/null +++ b/communicator/none/communicator.go @@ -0,0 +1,40 @@ +package none + +import ( + "errors" + "io" + "os" + "github.com/mitchellh/packer/packer" +) + +type comm struct { + config string +} + +// Creates a null packer.Communicator implementation. This takes +// an already existing configuration. +func New(config string) (result *comm, err error) { + // Establish an initial connection and connect + result = &comm{ + config: config, + } + + return +} + +func (c *comm) Start(cmd *packer.RemoteCmd) (err error) { + cmd.SetExited(0) + return +} + +func (c *comm) Upload(path string, input io.Reader, fi *os.FileInfo) error { + return errors.New("Upload is not implemented when communicator = 'none'") +} + +func (c *comm) UploadDir(dst string, src string, excl []string) error { + return errors.New("UploadDir is not implemented when communicator = 'none'") +} + +func (c *comm) Download(path string, output io.Writer) error { + return errors.New("Download is not implemented when communicator = 'none'") +} diff --git a/helper/communicator/step_connect.go b/helper/communicator/step_connect.go index e72be3ba8..41729efec 100644 --- a/helper/communicator/step_connect.go +++ b/helper/communicator/step_connect.go @@ -6,6 +6,8 @@ import ( "github.com/mitchellh/multistep" gossh "golang.org/x/crypto/ssh" + "github.com/mitchellh/packer/packer" + "github.com/mitchellh/packer/communicator/none" ) // StepConnect is a multistep Step implementation that connects to @@ -67,6 +69,15 @@ func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction { } if step == nil { + comm, err := none.New("none") + if err != nil { + err := fmt.Errorf("Failed to set communicator 'none': %s", err) + state.Put("error", err) + ui := state.Get("ui").(packer.Ui) + ui.Error(err.Error()) + return multistep.ActionHalt + } + state.Put("communicator", comm) log.Printf("[INFO] communicator disabled, will not connect") return multistep.ActionContinue }