ssh

package
v1.14.1-0...-2138f46 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(sshClient Interface, host, src, dest string, filter func(fs.DirEntry) bool) error

func GetTimeoutContext

func GetTimeoutContext() (context.Context, context.CancelFunc)

GetTimeoutContext create a context.Context with default timeout default execution timeout in sealos is just fine, if you want to customize the timeout setting, you must invoke the `RegisterFlags` function above.

func NewSudoSftpClient

func NewSudoSftpClient(conn *ssh.Client, sudopwd string, opts ...sftp.ClientOption) (*sftp.Client, error)

func OverSSHConfig

func OverSSHConfig(original, override *v1beta1.SSH)

func RegisterFlags

func RegisterFlags(fs *pflag.FlagSet)

func WaitReady

func WaitReady(client Interface, _ int, hosts ...string) error

Types

type Client

type Client struct {
	*ssh.ClientConfig
	*Option
}

func New

func New(opt *Option, opts ...OptionFunc) (*Client, error)

func (*Client) Cmd

func (c *Client) Cmd(host, cmd string) ([]byte, error)

func (*Client) CmdAsync

func (c *Client) CmdAsync(host string, cmds ...string) error

CmdAsync not actually asynchronously, just print output asynchronously

func (*Client) CmdAsyncWithContext

func (c *Client) CmdAsyncWithContext(ctx context.Context, host string, cmds ...string) error

func (*Client) CmdToString

func (c *Client) CmdToString(host, cmd, sep string) (string, error)

CmdToString execute command on host and replace output with sep to oneline

func (*Client) Connect

func (c *Client) Connect(host string) (sshClient *ssh.Client, session *ssh.Session, err error)

func (*Client) Copy

func (c *Client) Copy(host, localPath, remotePath string) error

Copy is copy file or dir to remotePath, add md5 validate

func (*Client) Fetch

func (c *Client) Fetch(host, src, dst string) error

func (*Client) Ping

func (c *Client) Ping(host string) error

func (*Client) RemoteSha256Sum

func (c *Client) RemoteSha256Sum(host, remoteFilePath string) string

type HostClient

type HostClient struct {
	SSHClient  *ssh.Client
	SftpClient *sftp.Client
}

type HostClientMap

type HostClientMap struct {
	ClientMap map[string]HostClient
	Mux       sync.Mutex
}

type Interface

type Interface interface {
	// Copy copy local file to remote
	// scp -r /tmp root@192.168.0.2:/root/tmp => Copy("192.168.0.2","tmp","/root/tmp")
	// skip checksum if env DO_NOT_CHECKSUM=true
	Copy(host, src, dst string) error
	// Fetch fetch remote file to local
	// scp -r root@192.168.0.2:/remote/path/file /local/path/file => Fetch("192.168.0.2","/remote/path/file", "/local/path/file",)
	Fetch(host, src, dst string) error
	// CmdAsync exec commands on remote host asynchronously
	CmdAsync(host string, cmds ...string) error
	CmdAsyncWithContext(ctx context.Context, host string, cmds ...string) error
	// Cmd exec command on remote host, and return combined standard output and standard error
	Cmd(host, cmd string) ([]byte, error)
	// CmdToString exec command on remote host, and return spilt standard output by separator and standard error
	CmdToString(host, cmd, spilt string) (string, error)
	Ping(host string) error
}

func MustNewClient

func MustNewClient(ssh *v2.SSH, isStdout bool) Interface

func NewCacheClientFromCluster

func NewCacheClientFromCluster(cluster *v2.Cluster, isStdout bool) Interface

type Option

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

func NewOption

func NewOption() *Option

func (*Option) BindFlags

func (o *Option) BindFlags(fs *pflag.FlagSet)

type OptionFunc

type OptionFunc func(*Option)

func WithHostKeyCallback

func WithHostKeyCallback(fn ssh.HostKeyCallback) OptionFunc

func WithPassword

func WithPassword(p string) OptionFunc

func WithPrivateKeyAndPhrase

func WithPrivateKeyAndPhrase(pk, passphrase string) OptionFunc

func WithRawPrivateKeyDataAndPhrase

func WithRawPrivateKeyDataAndPhrase(raw, passphrase string) OptionFunc

func WithStdoutEnable

func WithStdoutEnable(b bool) OptionFunc

func WithSudoEnable

func WithSudoEnable(b bool) OptionFunc

func WithTimeout

func WithTimeout(timeout time.Duration) OptionFunc

func WithUsername

func WithUsername(u string) OptionFunc

type Remote

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

func NewRemoteFromSSH

func NewRemoteFromSSH(clusterName string, sshInterface Interface) *Remote

func (*Remote) CGroup

func (s *Remote) CGroup(ip string) (string, error)

func (*Remote) Cert

func (s *Remote) Cert(ip string, altNames []string, nodeIP, nodeName, serviceCIRD, DNSDomain string) error

func (*Remote) Hostname

func (s *Remote) Hostname(ip string) (string, error)

func (*Remote) HostsAdd

func (s *Remote) HostsAdd(ip, host, domain string) error

func (*Remote) HostsDelete

func (s *Remote) HostsDelete(ip, domain string) error

func (*Remote) IPVS

func (s *Remote) IPVS(ip, vip string, masters []string) error

func (*Remote) IPVSClean

func (s *Remote) IPVSClean(ip, vip string) error

func (*Remote) InitSystem

func (s *Remote) InitSystem(ip string) initsystem.InitSystem

func (*Remote) Socket

func (s *Remote) Socket(ip string) (string, error)

func (*Remote) StaticPod

func (s *Remote) StaticPod(ip, vip, name, image string, masters []string, path string, options ...string) error

func (*Remote) Token

func (s *Remote) Token(ip, config, certificateKey string) (string, error)

type RenderTemplate

type RenderTemplate func(name, defaultStr string, data map[string]interface{}) (string, error)

Jump to

Keyboard shortcuts

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