ssh

package
v0.1.1-0...-e7e60cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2014 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultUser is used if there is no default user given
	DefaultUser = "root"

	// DefaultPort is used if there is no port given
	DefaultPort = 22

	// DefaultScriptPath is used as the path to copy the file to
	// for remote execution if not provided otherwise.
	DefaultScriptPath = "/tmp/script.sh"

	// DefaultTimeout is used if there is no timeout given
	DefaultTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func ConnectFunc

func ConnectFunc(network, addr string) func() (net.Conn, error)

ConnectFunc is a convenience method for returning a function that just uses net.Dial to communicate with the remote end that is suitable for use with the SSH communicator configuration.

func PasswordKeyboardInteractive

func PasswordKeyboardInteractive(password string) ssh.KeyboardInteractiveChallenge

An implementation of ssh.KeyboardInteractiveChallenge that simply sends back the password for all questions. The questions are logged.

func VerifySSH

func VerifySSH(s *terraform.ResourceState) error

VerifySSH is used to verify the ConnInfo is usable by remote-exec

Types

type Config

type Config struct {
	// The configuration of the Go SSH connection
	SSHConfig *ssh.ClientConfig

	// Connection returns a new connection. The current connection
	// in use will be closed as part of the Close method, or in the
	// case an error occurs.
	Connection func() (net.Conn, error)

	// NoPty, if true, will not request a pty from the remote end.
	NoPty bool
}

Config is the structure used to configure the SSH communicator.

func PrepareConfig

func PrepareConfig(conf *SSHConfig) (*Config, error)

PrepareConfig is used to turn the *SSHConfig provided into a usable *Config for client initialization.

type RemoteCmd

type RemoteCmd struct {
	// Command is the command to run remotely. This is executed as if
	// it were a shell command, so you are expected to do any shell escaping
	// necessary.
	Command string

	// Stdin specifies the process's standard input. If Stdin is
	// nil, the process reads from an empty bytes.Buffer.
	Stdin io.Reader

	// Stdout and Stderr represent the process's standard output and
	// error.
	//
	// If either is nil, it will be set to ioutil.Discard.
	Stdout io.Writer
	Stderr io.Writer

	// This will be set to true when the remote command has exited. It
	// shouldn't be set manually by the user, but there is no harm in
	// doing so.
	Exited bool

	// Once Exited is true, this will contain the exit code of the process.
	ExitStatus int

	// This thing is a mutex, lock when making modifications concurrently
	sync.Mutex
	// contains filtered or unexported fields
}

RemoteCmd represents a remote command being prepared or run.

func (*RemoteCmd) SetExited

func (r *RemoteCmd) SetExited(status int)

SetExited is a helper for setting that this process is exited. This should be called by communicators who are running a remote command in order to set that the command is done.

func (*RemoteCmd) Wait

func (r *RemoteCmd) Wait()

Wait waits for the remote command to complete.

type SSHCommunicator

type SSHCommunicator struct {
	// contains filtered or unexported fields
}

func New

func New(address string, config *Config) (result *SSHCommunicator, err error)

New creates a new packer.Communicator implementation over SSH. This takes an already existing TCP connection and SSH configuration.

func (*SSHCommunicator) Download

func (c *SSHCommunicator) Download(string, io.Writer) error

func (*SSHCommunicator) Start

func (c *SSHCommunicator) Start(cmd *RemoteCmd) (err error)

func (*SSHCommunicator) Upload

func (c *SSHCommunicator) Upload(path string, input io.Reader) error

func (*SSHCommunicator) UploadDir

func (c *SSHCommunicator) UploadDir(dst string, src string, excl []string) error

type SSHConfig

type SSHConfig struct {
	User       string
	Password   string
	KeyFile    string `mapstructure:"key_file"`
	Host       string
	Port       int
	Timeout    string
	ScriptPath string        `mapstructure:"script_path"`
	TimeoutVal time.Duration `mapstructure:"-"`
}

SSHConfig is decoded from the ConnInfo of the resource. These are the only keys we look at. If a KeyFile is given, that is used instead of a password.

func ParseSSHConfig

func ParseSSHConfig(s *terraform.ResourceState) (*SSHConfig, error)

ParseSSHConfig is used to convert the ConnInfo of the ResourceState into a SSHConfig struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL