Implement a null-object communicator for 'none'

Fixes #2736
This commit is contained in:
Evan Powell 2015-10-20 17:00:48 -05:00
parent a563944b58
commit bb8ced8cc9
2 changed files with 51 additions and 0 deletions

View File

@ -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'")
}

View File

@ -6,6 +6,8 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
gossh "golang.org/x/crypto/ssh" 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 // 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 { 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") log.Printf("[INFO] communicator disabled, will not connect")
return multistep.ActionContinue return multistep.ActionContinue
} }