ssh

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0 Imports: 34 Imported by: 0

README

执行远程命令

执行远程ssh命令标准库

Documentation

Index

Constants

View Source
const DefaultSSHPort = "22"
View Source
const (
	Md5sumCmd = "md5sum %s | cut -d\" \" -f1"
)
View Source
const SUDO = "sudo "

Variables

This section is empty.

Functions

func GetClusterPlatform

func GetClusterPlatform(cluster *v2.Cluster) (map[string]v1.Platform, error)

func ReadPipe

func ReadPipe(stdout, stderr io.Reader, isStdout bool)

func WaitSSHReady

func WaitSSHReady(ssh Interface, tryTimes int, hosts ...net.IP) error

Types

type Interface

type Interface interface {
	// Copy local files to remote host
	// scp -r /tmp root@192.168.0.2:/root/tmp => Copy("192.168.0.2","tmp","/root/tmp")
	// need check md5sum
	Copy(host net.IP, srcFilePath, dstFilePath string) error
	// Fetch copy remote host files to localhost
	Fetch(host net.IP, srcFilePath, dstFilePath string) error
	// CmdAsync exec command on remote host, and asynchronous return logs
	CmdAsync(host net.IP, cmd ...string) error
	// Cmd exec command on remote host, and return combined standard output and standard error
	Cmd(host net.IP, cmd string) ([]byte, error)
	// IsFileExist check remote file exist or not
	IsFileExist(host net.IP, remoteFilePath string) (bool, error)
	// RemoteDirExist Remote file existence returns true, nil
	RemoteDirExist(host net.IP, remoteDirpath string) (bool, error)
	// CmdToString exec command on remote host, and return spilt standard output and standard error
	CmdToString(host net.IP, cmd, spilt string) (string, error)
	// Platform Get remote platform
	Platform(host net.IP) (v1.Platform, error)

	Ping(host net.IP) error
}

func GetHostSSHClient

func GetHostSSHClient(hostIP net.IP, cluster *v2.Cluster) (Interface, error)

GetHostSSHClient is used to executed bash command and no std out to be printed.

func NewSSHClient

func NewSSHClient(ssh *v1.SSH, isStdout bool) Interface

func NewStdoutSSHClient

func NewStdoutSSHClient(hostIP net.IP, cluster *v2.Cluster) (Interface, error)

NewStdoutSSHClient is used to show std out when execute bash command.

type SSH

type SSH struct {
	IsStdout     bool
	Encrypted    bool
	User         string
	Password     string
	Port         string
	PkFile       string
	PkPassword   string
	Timeout      *time.Duration
	LocalAddress []net.Addr
	Fs           fs.Interface
}

func (*SSH) Cmd

func (s *SSH) Cmd(host net.IP, cmd string) ([]byte, error)

func (*SSH) CmdAsync

func (s *SSH) CmdAsync(host net.IP, cmds ...string) error

func (*SSH) CmdToString

func (s *SSH) CmdToString(host net.IP, cmd, split string) (string, error)

CmdToString is in host exec cmd and replace to spilt str

func (*SSH) Connect

func (s *SSH) Connect(host net.IP) (*ssh.Client, *ssh.Session, error)

func (*SSH) Copy

func (s *SSH) Copy(host net.IP, localPath, remotePath string) error

Copy file or dir to remotePath, add md5 validate

func (*SSH) Fetch

func (s *SSH) Fetch(host net.IP, localFilePath, remoteFilePath string) error

Fetch scp remote file to local

func (*SSH) IsFileExist

func (s *SSH) IsFileExist(host net.IP, remoteFilePath string) (bool, error)

func (*SSH) NewSudoSftpClient

func (s *SSH) NewSudoSftpClient(conn *ssh.Client, opts ...sftp.ClientOption) (*sftp.Client, error)

func (*SSH) Ping

func (s *SSH) Ping(host net.IP) error

func (*SSH) Platform

func (s *SSH) Platform(host net.IP) (v1.Platform, error)

func (*SSH) RemoteDirExist

func (s *SSH) RemoteDirExist(host net.IP, remoteDirPath string) (bool, error)

RemoteDirExist if remote file not exist return false and nil

Jump to

Keyboard shortcuts

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