sshutils

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const KB = 1024
View Source
const MB = 1024 * 1024

Variables

This section is empty.

Functions

func Cmd

func Cmd(name string, arg ...string) error

func CmdBatch

func CmdBatch(sshConfig *SSH, hosts []string, cmd string, walk Walk) error

CmdBatch parallel run cmd on many hosts

func CmdBatchWithSudo

func CmdBatchWithSudo(sshConfig *SSH, hosts []string, cmd string, walk Walk) error

CmdBatchWithSudo parallel run cmd with sudo on many hosts

func Combine

func Combine(cmdList []string) string

func DefaultWalk

func DefaultWalk(result Result, err error) error

func ExtraExitCode added in v1.1.1

func ExtraExitCode(err error) (bool, int)

func GetRemoteHostName added in v1.1.1

func GetRemoteHostName(sshConfig *SSH, hostIP string) (string, error)

func IsFileExist

func IsFileExist(filepath string) (bool, error)

func IsFloatIP added in v1.1.1

func IsFloatIP(sshConfig *SSH, ip string) (bool, error)

func MD5FromLocal

func MD5FromLocal(localPath string) (string, error)

func NewSSHClient

func NewSSHClient(username, password, ip string, port int) (*ssh.Client, error)

func SSHToCmd added in v1.1.1

func SSHToCmd(sshConfig *SSH, host string) bool

SSHToCmd if caller don't provide enough config for run ssh cmd,change to run cmd by os.exec on localhost. for aio deploy now.

func Whoami added in v1.1.1

func Whoami() string

func WrapEcho

func WrapEcho(data, dest string) string

WrapEcho use sh -c to wrap echo and > in one cmd for sudo.

func WrapSh

func WrapSh(cmd string) string

WrapSh use sh -c to wrap cmd for sudo.

Types

type LogicSSHWsSession

type LogicSSHWsSession struct {
	IsFlagged bool
	// contains filtered or unexported fields
}

func NewLoginSSHWSSession

func NewLoginSSHWSSession(cols, rows int, isAdmin bool, sshClient *ssh.Client, wsConn *websocket.Conn) (*LogicSSHWsSession, error)

func (*LogicSSHWsSession) Close

func (sws *LogicSSHWsSession) Close()

Close 关闭

func (*LogicSSHWsSession) LogString

func (sws *LogicSSHWsSession) LogString() string

func (*LogicSSHWsSession) Start

func (sws *LogicSSHWsSession) Start(quitChan chan struct{})

func (*LogicSSHWsSession) Wait

func (sws *LogicSSHWsSession) Wait(quitChan chan struct{}, gracefulExitChan chan struct{})

type PtyHandler

type PtyHandler interface {
	io.Reader
	io.Writer
	remotecommand.TerminalSizeQueue
}

PtyHandler is what remotecommand expects from a pty

type Result

type Result struct {
	User     string
	Host     string
	Cmd      string
	PrintCmd string
	Stdout   string
	Stderr   string
	ExitCode int
}

func CmdToString

func CmdToString(name string, arg ...string) (Result, error)

func RunCmdAsSSH added in v1.1.1

func RunCmdAsSSH(cmdStr string) (Result, error)

func SSHCmd

func SSHCmd(sshConfig *SSH, host, cmd string) (Result, error)

SSHCmd synchronously SSHs to a node running on provider and runs cmd. If there is no error performing the SSH, the stdout, stderr, and exit code are returned.

func SSHCmdWithSudo

func SSHCmdWithSudo(sshConfig *SSH, host, cmd string) (Result, error)

SSHCmdWithSudo try to run cmd with sudo.

func (Result) Error

func (r Result) Error() error

func (Result) Short

func (r Result) Short() string

func (Result) StdoutToString

func (r Result) StdoutToString(place string) string

func (Result) String

func (r Result) String() string

type SSH

type SSH struct {
	User              string         `json:"user" yaml:"user,omitempty"`
	Password          string         `json:"password" yaml:"password,omitempty"`
	Port              int            `json:"port" yaml:"port,omitempty"`
	PkFile            string         `json:"pkFile" yaml:"pkFile,omitempty"`
	PrivateKey        string         `json:"privateKey" yaml:"privateKey,omitempty"`
	PkPassword        string         `json:"pkPassword" yaml:"pkPassword,omitempty"`
	ConnectionTimeout *time.Duration `json:"connectionTimeout,omitempty" yaml:"connectionTimeout,omitempty"`
}

func NewSSH added in v1.2.1

func NewSSH() *SSH

func (*SSH) Copy

func (ss *SSH) Copy(host, localFilePath, remoteFilePath string) error

Copy is

func (*SSH) CopyForMD5V2

func (ss *SSH) CopyForMD5V2(host, localFilePath, remoteFilePath, localMD5 string) (bool, error)

CopyForMD5V2 copy and check md5

func (*SSH) CopySudo

func (ss *SSH) CopySudo(host, localFilePath, remoteFilePath string) error

func (*SSH) CopySudoWithBar added in v1.2.0

func (ss *SSH) CopySudoWithBar(bar *mpb.Bar, host, localFilePath, remoteFilePath string) error

func (*SSH) CopyWithBar added in v1.2.0

func (ss *SSH) CopyWithBar(bar *mpb.Bar, host, localFilePath, remoteFilePath string) error

func (*SSH) DownloadSudo

func (ss *SSH) DownloadSudo(host, localFilePath, remoteFilePath string) error

func (*SSH) IsFileExistV2

func (ss *SSH) IsFileExistV2(host, remoteFilePath string) (bool, error)

func (*SSH) MD5FromRemote

func (ss *SSH) MD5FromRemote(host, remoteFilePath string) (string, error)

func (*SSH) NewClient

func (ss *SSH) NewClient(host string) (*ssh.Client, error)

func (*SSH) ValidateMd5sumLocalWithRemote

func (ss *SSH) ValidateMd5sumLocalWithRemote(host, localFile, remoteFile string) (bool, error)

type SSHConn

type SSHConn struct {
	// calling Write() to write data into ssh server
	StdinPipe io.WriteCloser
	// Write() be called to receive data from ssh server
	ComboOutput *wsBufferWriter
	Session     *ssh.Session
}

connect to ssh server using ssh session.

func NewSSHConn

func NewSSHConn(cols, rows int, sshClient *ssh.Client) (*SSHConn, error)

setup ssh shell session set Session and StdinPipe here, and the Session.Stdout and Session.Sdterr are also set.

func (*SSHConn) Close

func (s *SSHConn) Close()

type SSHRunCmd

type SSHRunCmd func(sshConfig *SSH, host, cmd string) (Result, error)

type TerminalSession

type TerminalSession struct {
	Conn     *websocket.Conn
	SizeChan chan remotecommand.TerminalSize
}

TerminalSession implements PtyHandler (using a SockJS connection)

func (TerminalSession) Close

func (t TerminalSession) Close(status uint32, reason string)

func (TerminalSession) Next

Next handles pty->process resize events Called in a loop from remotecommand as long as the process is running

func (TerminalSession) Read

func (t TerminalSession) Read(p []byte) (int, error)

Read handles pty->process messages (stdin, resize) Called in a loop from remotecommand as long as the process is running

func (TerminalSession) Toast

func (t TerminalSession) Toast(p string) error

func (TerminalSession) Write

func (t TerminalSession) Write(p []byte) (int, error)

Write handles process->pty stdout Called from remotecommand whenever there is any output

type Terminaler

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

func NewTerminaler

func NewTerminaler(client kubernetes.Interface, config *rest.Config) *Terminaler

func (*Terminaler) StartProcess

func (t *Terminaler) StartProcess(namespace, podName, containerName string, cmd []string, ptyHandler PtyHandler) error

type Walk

type Walk func(result Result, err error) error

Jump to

Keyboard shortcuts

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