Documentation
¶
Index ¶
- func Debug(f interface{}, v ...interface{})
- func Error(f interface{}, v ...interface{})
- func Fatal(f interface{}, v ...interface{})
- func GetHostIPAndPortOrDefault(host, Default string) (string, string)
- func GetSSHHostIPAndPort(host string) (string, string)
- func GetTimeoutContext() (context.Context, context.CancelFunc)
- func Info(f interface{}, v ...interface{})
- func IsDebugMode() bool
- func NewSudoSftpClient(conn *ssh.Client, sudopwd string, opts ...sftp.ClientOption) (*sftp.Client, error)
- func Panic(f interface{}, v ...interface{})
- func PathIsExist(fileName string) bool
- func RegisterFlags(fs *pflag.FlagSet)
- func WaitReady(client Interface, _ int, hosts ...string) error
- func Warn(f interface{}, v ...interface{})
- type Client
- func (c *Client) Cmd(host, cmd string) ([]byte, error)
- func (c *Client) CmdAsync(host string, cmds ...string) error
- func (c *Client) CmdAsyncWithContext(ctx context.Context, host string, cmds ...string) error
- func (c *Client) CmdToString(host, cmd, sep string) (string, error)
- func (c *Client) Connect(host string) (sshClient *ssh.Client, session *ssh.Session, err error)
- func (c *Client) Copy(host, localPath, remotePath string) error
- func (c *Client) Fetch(host, src, dst string) error
- func (c *Client) Ping(host string) error
- func (c *Client) RemoteSha256Sum(host, remoteFilePath string) string
- type HostClient
- type HostClientMap
- type Interface
- type Option
- type OptionFunc
- func WithHostKeyCallback(fn ssh.HostKeyCallback) OptionFunc
- func WithPassword(p string) OptionFunc
- func WithPrivateKeyAndPhrase(pk, passphrase string) OptionFunc
- func WithRawPrivateKeyDataAndPhrase(raw, passphrase string) OptionFunc
- func WithStdoutEnable(b bool) OptionFunc
- func WithSudoEnable(b bool) OptionFunc
- func WithTimeout(timeout time.Duration) OptionFunc
- func WithUsername(u string) OptionFunc
- type SSH
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
func Fatal(f interface{}, v ...interface{})
Fatal logs a message at emergency level and exit.
func GetSSHHostIPAndPort ¶
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 Panic ¶
func Panic(f interface{}, v ...interface{})
Panic logs a message at emergency level and exit.
func PathIsExist ¶
func RegisterFlags ¶
Types ¶
type Client ¶
type Client struct {
*ssh.ClientConfig
*Option
}
func (*Client) CmdAsyncWithContext ¶
CmdAsyncWithContext 异步执行cmd
func (*Client) CmdToString ¶
CmdToString execute command on host and replace output with sep to oneline call Cmd
func (*Client) RemoteSha256Sum ¶
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 ¶
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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.