ssh

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 8 more Imports: 23 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupFile added in v1.3.1

func BackupFile(s Interface, file string) (string, error)

func CheckNFS added in v1.9.1

func CheckNFS(s Interface, server string, path string) (err error)

func DiskAvail added in v1.3.1

func DiskAvail(s Interface, path string) (int, error)

DiskAvail returns available disk space in GiB.

func FirewallEnabled added in v1.9.1

func FirewallEnabled(s Interface) (enabled bool, err error)

func GetDefaultRouteIP added in v1.9.1

func GetDefaultRouteIP(s Interface) string

GetDefaultRouteIP returns default router network interface

func GetDefaultRouteInterface added in v1.9.1

func GetDefaultRouteInterface(s Interface) string

GetDefaultRouteInterface returns default router network interface

func GetNetworkInterface

func GetNetworkInterface(s Interface, ip string) string

GetNetworkInterface return network interface name by ip

func MakePrivateKeySigner

func MakePrivateKeySigner(privateKey []byte, passPhrase []byte) (ssh.Signer, error)

func MakePrivateKeySignerFromFile

func MakePrivateKeySignerFromFile(key string) (ssh.Signer, error)

func MemoryCapacity added in v1.3.1

func MemoryCapacity(s Interface) (uint64, error)

MemoryCapacity returns the machine's total memory from /proc/meminfo. Returns the total memory capacity as an uint64 (number of bytes).

func NumCPU added in v1.3.1

func NumCPU(s Interface) (int, error)

NumCPU returns the number of logical CPUs.

func OSVersion added in v1.9.1

func OSVersion(s Interface) (os string, err error)

OSVersion returns os version.

func ParsePublicKeyFromFile

func ParsePublicKeyFromFile(keyFile string) (*rsa.PublicKey, error)

func ReservePorts added in v1.9.1

func ReservePorts(s Interface, ip string, ports []int) (isInused bool, message string, err error)

func RestoreFile added in v1.3.1

func RestoreFile(s Interface, file string) error

func SelinuxEnabled added in v1.9.1

func SelinuxEnabled(s Interface) (enabled bool, err error)

func Timestamp added in v1.2.5

func Timestamp(s Interface) (int, error)

Timestamp returns target node timestamp.

Types

type Config

type Config struct {
	User       string `validate:"required"`
	Host       string `validate:"required"`
	Port       int    `validate:"required"`
	Sudo       bool
	Password   string
	PrivateKey []byte
	PassPhrase []byte
	// 150 seconds is longer than the underlying default TCP backoff delay (127
	// seconds). This timeout is only intended to catch otherwise uncaught hangs.
	DialTimeOut time.Duration
	Retry       int
	Proxy       Proxy
}

type Interface

type Interface interface {
	Ping() error

	CombinedOutput(cmd string) ([]byte, error)
	Execf(format string, a ...interface{}) (stdout string, stderr string, exit int, err error)
	Exec(cmd string) (stdout string, stderr string, exit int, err error)

	CopyFile(src, dst string) error
	WriteFile(src io.Reader, dst string) error
	ReadFile(filename string) ([]byte, error)
	ReadDir(dirname string) (string, error)
	Exist(filename string) (bool, error)

	LookPath(file string) (string, error)
}

type JumpServer added in v1.9.1

type JumpServer struct {
	Config
}

func (JumpServer) CheckTunnel added in v1.9.1

func (sj JumpServer) CheckTunnel() error

func (JumpServer) ProxyConn added in v1.9.1

func (sj JumpServer) ProxyConn(targetAddr string) (net.Conn, func(), error)

type Proxy added in v1.9.1

type Proxy interface {
	ProxyConn(targetAddr string) (conn net.Conn, closer func(), err error)
	CheckTunnel() (err error)
}

type SOCKS5 added in v1.9.1

type SOCKS5 struct {
	Host            string
	Port            int
	User            string
	Password        string
	DialTimeOut     time.Duration
	CheckTargetAddr string
}

func (SOCKS5) CheckTunnel added in v1.9.1

func (sk SOCKS5) CheckTunnel() error

func (SOCKS5) ProxyConn added in v1.9.1

func (sk SOCKS5) ProxyConn(targetAddr string) (net.Conn, func(), error)

type SSH

type SSH struct {
	*Config
	// contains filtered or unexported fields
}

func New

func New(c *Config) (*SSH, error)

func (*SSH) CheckProxyTunnel added in v1.9.1

func (s *SSH) CheckProxyTunnel() error

func (*SSH) CombinedOutput

func (s *SSH) CombinedOutput(cmd string) ([]byte, error)

func (*SSH) CopyDir added in v1.4.0

func (s *SSH) CopyDir(src, dst string) error

func (*SSH) CopyFile

func (s *SSH) CopyFile(src, dst string) error

func (*SSH) Exec

func (s *SSH) Exec(cmd string) (stdout string, stderr string, exit int, err error)

func (*SSH) Execf

func (s *SSH) Execf(format string, a ...interface{}) (stdout string, stderr string, exit int, err error)

func (*SSH) Exist added in v1.3.1

func (s *SSH) Exist(filename string) (bool, error)

func (*SSH) LookPath

func (s *SSH) LookPath(file string) (string, error)

func (*SSH) Ping

func (s *SSH) Ping() error

func (*SSH) ReadDir added in v1.8.0

func (s *SSH) ReadDir(dir string) (string, error)

func (*SSH) ReadFile

func (s *SSH) ReadFile(filename string) ([]byte, error)

func (*SSH) WriteFile

func (s *SSH) WriteFile(src io.Reader, dst string) error

Jump to

Keyboard shortcuts

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