Documentation ¶
Overview ¶
Package massh provides tools for running distributed shell commands via SSH
Index ¶
- Variables
- type Config
- func (c *Config) AutoCancelSlowHosts()
- func (c *Config) CheckSanity() error
- func (c *Config) Run() ([]Result, error)
- func (c *Config) SetBastionHost(host string)
- func (c *Config) SetBastionHostConfig(s *ssh.ClientConfig)
- func (c *Config) SetHosts(hosts []string)
- func (c *Config) SetJob(job *Job)
- func (c *Config) SetPasswordAuth(username string, password string)
- func (c *Config) SetPrivateKeyAuth(PrivateKeyFile string, PrivateKeyPassphrase string) error
- func (c *Config) SetSSHAuthSock() error
- func (c *Config) SetSSHConfig(s *ssh.ClientConfig)
- func (c *Config) SetSSHHostKeyCallback(callback ssh.HostKeyCallback)
- func (c *Config) SetSlowTimeout(timeout int)
- func (c *Config) SetWorkerPool(numWorkers int)
- func (c *Config) StopAllSessions()
- func (c *Config) Stream(rs chan *Result) error
- type Job
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( // ErrJobConflict indicates that both Job and Jobstack are assigned in Config. ErrJobConflict = errors.New("only one of job or jobstack must be present in config") // ErrNoJobsSet indicates that no job is set for the config. ErrNoJobsSet = errors.New("no jobs are set in config") )
var ( // NumberOfStreamingHostsCompleted is incremented when a Result's DoneChannel is written to, indicating a host has completed it's work. NumberOfStreamingHostsCompleted int )
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v1.0.0
type Config struct { Hosts map[string]struct{} SSHConfig *ssh.ClientConfig // Jobs to execute, config will error if both are set Job *Job JobStack *[]Job // Number of concurrent workers WorkerPool int BastionHost string // BastionHost's SSH config. If nil, Bastion will use SSHConfig instead. BastionHostSSHConfig *ssh.ClientConfig // Stream-only SlowTimeout int // Timeout for delcaring that a host is slow. CancelSlowHosts bool // Not implemented. Automatically cancel hosts that are flagged as slow. Stop chan struct{} }
Config is a config implementation for distributed SSH commands
func (*Config) AutoCancelSlowHosts ¶ added in v1.14.1
func (c *Config) AutoCancelSlowHosts()
AutoCancelSlowHosts will cancel/terminate slow host sessions.
func (*Config) CheckSanity ¶ added in v1.0.0
CheckSanity ensures config is valid.
func (*Config) Run ¶ added in v1.0.0
Run executes the config, return a slice of Results once the command has exited on all hosts.
This is a rudimentary function, and is not affected by Config.SlowTimeout or Config.CancelSlowHosts. By extension, the Results returned using Run always have an IsSlow value of false.
func (*Config) SetBastionHost ¶ added in v1.1.1
SetBastionHost sets the bastion host to use for a massh config
func (*Config) SetBastionHostConfig ¶ added in v1.1.1
func (c *Config) SetBastionHostConfig(s *ssh.ClientConfig)
SetBastionHostConfig sets the bastion hosts's SSH client config. If value is left nil, SSHConfig will be used instead.
func (*Config) SetHosts ¶ added in v1.0.0
SetHosts adds a slice of strings as hosts to config. Removes duplicates.
func (*Config) SetPasswordAuth ¶ added in v1.0.0
SetPasswordAuth sets ssh password from provided byte slice (read from terminal)
func (*Config) SetPrivateKeyAuth ¶ added in v1.10.1
SetPrivateKeyAuth takes the private key file provided, reads it, and adds the key signature to the config.
func (*Config) SetSSHAuthSock ¶ added in v1.12.0
SetSSHAuthSock uses SSH_AUTH_SOCK environment variable to populate auth method in the SSH config. Useful when using keys, and `AgentForwarding` is enabled in the local SSH config.
func (*Config) SetSSHConfig ¶ added in v1.0.0
func (c *Config) SetSSHConfig(s *ssh.ClientConfig)
SetSSHConfig sets the SSH client config for all hosts.
func (*Config) SetSSHHostKeyCallback ¶ added in v1.10.1
func (c *Config) SetSSHHostKeyCallback(callback ssh.HostKeyCallback)
SetSSHHostKeyCallback sets the HostKeyCallback for the Config's SSHConfig value.
func (*Config) SetSlowTimeout ¶ added in v1.14.1
SetSlowTimeout sets the SlowTimeout value for config.
func (*Config) SetWorkerPool ¶ added in v1.0.0
SetWorkerPool populates specified number of concurrent workers in Config. It is safe for this number to be larger than the number of hosts being processed, but it must not be zero.
func (*Config) StopAllSessions ¶ added in v1.14.1
func (c *Config) StopAllSessions()
func (*Config) Stream ¶ added in v1.1.0
Stream executes the config, and writes to rs as commands are initiated.
One result is added to the channel for each host. Streaming is performed by reading the StdOutStream and StdErrStream parameters in Result.
Example reading each result in the channel: ``` cfg.Stream(resultChan)
for { result := <-resultChan go func() { // do something with the result }() }
```
type Job ¶ added in v1.0.0
type Job struct { Command string Script script }
Job is a single remote task config. For script files, use Job.SetLocalScript().
func (*Job) SetCommand ¶ added in v1.0.0
SetCommand sets the Command value in Job. This is the Command executed over SSH to all hosts.
type Result ¶ added in v1.0.0
type Result struct { Host string // Hostname Job string // The command that was run Output []byte // Package errors, not output from SSH. Makes the concurrency easier to manage without returning an error. Error error // Stream-specific IsSlow bool // Activity timeout for StdOut StdOutStream chan []byte StdErrStream chan []byte DoneChannel chan struct{} // Written to when a host completes work. This does not indicate that all output from StdOutStream or StdErrStream has been read and/or processed. }
Result contains usable output from SSH commands.