Documentation ¶
Overview ¶
Provides remote file and command functions
Index ¶
- Variables
- func CopyAll(srcHost Host, srcDir string, dstHost Host, dstDir string) (err error)
- func CopyFile(srcHost Host, srcPath string, dstHost Host, dstPath string) (err error)
- type Host
- type Local
- func (h *Local) Abs(dir string) (abs string, err error)
- func (h *Local) Chown(name string, uid, gid int) (err error)
- func (h *Local) Create(p string, perms fs.FileMode) (out io.WriteCloser, err error)
- func (h *Local) GetFs() afero.Fs
- func (h *Local) Getwd() (dir string, err error)
- func (h *Local) Glob(pattern string) (paths []string, err error)
- func (h *Local) Hostname() string
- func (h *Local) IsAvailable() bool
- func (h *Local) IsLocal() bool
- func (h *Local) LastError() error
- func (h *Local) Lchown(name string, uid, gid int) (err error)
- func (h *Local) Lstat(name string) (f fs.FileInfo, err error)
- func (h *Local) MkdirAll(p string, perm os.FileMode) (err error)
- func (h *Local) Open(name string) (f io.ReadSeekCloser, err error)
- func (h *Local) Path(p string) string
- func (h *Local) ReadDir(name string) (dirs []os.DirEntry, err error)
- func (h *Local) ReadFile(name string) (b []byte, err error)
- func (h *Local) Readlink(file string) (link string, err error)
- func (h *Local) Remove(name string) (err error)
- func (h *Local) RemoveAll(name string) (err error)
- func (h *Local) Rename(oldpath, newpath string) (err error)
- func (h *Local) Run(cmd *exec.Cmd, errfile string) (output []byte, err error)
- func (h *Local) ServerVersion() string
- func (h *Local) Signal(pid int, signal syscall.Signal) (err error)
- func (h *Local) Start(cmd *exec.Cmd, errfile string) (err error)
- func (h *Local) Stat(name string) (f fs.FileInfo, err error)
- func (h *Local) String() string
- func (h *Local) Symlink(oldname, newname string) (err error)
- func (h *Local) TempDir() string
- func (h *Local) Username() string
- func (h *Local) WriteFile(name string, data []byte, perm os.FileMode) (err error)
- type SSHOptions
- type SSHRemote
- func (h *SSHRemote) Abs(dir string) (string, error)
- func (h *SSHRemote) Chown(name string, uid, gid int) error
- func (h *SSHRemote) Close()
- func (h *SSHRemote) CloseSFTP()
- func (h *SSHRemote) Create(p string, perms fs.FileMode) (out io.WriteCloser, err error)
- func (h *SSHRemote) Dial() (sc *ssh.Client, err error)
- func (h *SSHRemote) DialSFTP() (f *sftp.Client, err error)
- func (h *SSHRemote) GetFs() afero.Fs
- func (h *SSHRemote) Getwd() (dir string, err error)
- func (h *SSHRemote) Glob(pattern string) ([]string, error)
- func (s *SSHRemote) Hostname() string
- func (h *SSHRemote) IsAvailable() bool
- func (h *SSHRemote) IsLocal() bool
- func (h *SSHRemote) LastError() error
- func (h *SSHRemote) Lchown(name string, uid, gid int) error
- func (h *SSHRemote) Lstat(name string) (fs.FileInfo, error)
- func (h *SSHRemote) MkdirAll(p string, perm os.FileMode) error
- func (h *SSHRemote) NewSession() (sess *ssh.Session, err error)
- func (h *SSHRemote) Open(name string) (io.ReadSeekCloser, error)
- func (h *SSHRemote) Path(p string) string
- func (h *SSHRemote) ReadDir(name string) (dirs []os.DirEntry, err error)
- func (h *SSHRemote) ReadFile(name string) (b []byte, err error)
- func (h *SSHRemote) Readlink(file string) (string, error)
- func (h *SSHRemote) Remove(name string) error
- func (h *SSHRemote) RemoveAll(name string) (err error)
- func (h *SSHRemote) Rename(oldpath, newpath string) error
- func (h *SSHRemote) Run(cmd *exec.Cmd, errfile string) (output []byte, err error)
- func (h *SSHRemote) ServerVersion() string
- func (h *SSHRemote) Signal(pid int, signal syscall.Signal) (err error)
- func (h *SSHRemote) Start(cmd *exec.Cmd, errfile string) (err error)
- func (h *SSHRemote) Stat(name string) (fs.FileInfo, error)
- func (h *SSHRemote) String() string
- func (h *SSHRemote) Symlink(oldname, newname string) error
- func (h *SSHRemote) TempDir() string
- func (h *SSHRemote) Username() string
- func (h *SSHRemote) WriteFile(name string, data []byte, perm os.FileMode) (err error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidArgs = errors.New("invalid arguments") ErrNotSupported = errors.New("not supported") ErrNotAvailable = errors.New("not available") ErrExist = errors.New("already exists") ErrNotExist = errors.New("does not exist") )
var Localhost = NewLocal()
Functions ¶
Types ¶
type Host ¶
type Host interface { // informational String() string GetFs() afero.Fs Path(p string) string Hostname() string ServerVersion() string IsAvailable() bool IsLocal() bool LastError() error Username() string // file operations Abs(name string) (string, error) Getwd() (dir string, err error) Chown(name string, uid, gid int) (err error) Glob(pattern string) (paths []string, err error) Lchown(name string, uid, gid int) (err error) Lstat(name string) (f fs.FileInfo, err error) MkdirAll(p string, perm os.FileMode) (err error) ReadDir(name string) (dirs []os.DirEntry, err error) ReadFile(name string) (b []byte, err error) Readlink(file string) (link string, err error) Remove(name string) (err error) RemoveAll(name string) (err error) Rename(oldpath, newpath string) (err error) Stat(name string) (f fs.FileInfo, err error) Symlink(oldname, newname string) (err error) TempDir() string WriteFile(name string, data []byte, perm os.FileMode) (err error) // these two do not conform to the afero / os interface Open(name string) (f io.ReadSeekCloser, err error) Create(p string, perms fs.FileMode) (out io.WriteCloser, err error) // process control Signal(pid int, signal syscall.Signal) (err error) Start(cmd *exec.Cmd, errfile string) (err error) Run(cmd *exec.Cmd, errfile string) (stdout []byte, err error) }
Host encapsulates all the methods required by callers to manage Geneos installs on a host.
This should have been based on (and extending) something like Afero, but this was quicker for the moment. This interface also provides process handling etc.
func NewSSHRemote ¶
type Local ¶
type Local struct { }
Localhost operations
func (*Local) ReadDir ¶
ReadDir reads the named directory and returns all its directory entries sorted by name.
func (*Local) Run ¶
Run starts a program, waits for completion and returns the output and/or any error. errfile is either absolute or relative to home.
func (*Local) ServerVersion ¶
type SSHOptions ¶
type SSHOptions func(*SSHRemote)
func Hostname ¶
func Hostname(hostname string) SSHOptions
func Keys ¶
func Keys(paths ...string) SSHOptions
func Password ¶
func Password(password *memguard.Enclave) SSHOptions
func Port ¶
func Port(port uint16) SSHOptions
func Username ¶
func Username(username string) SSHOptions
type SSHRemote ¶
type SSHRemote struct {
// contains filtered or unexported fields
}
An SSHRemote a type that satisfies the Host interface for SSH attached remote hosts
func (*SSHRemote) Dial ¶
Dial connects to a remote host using ssh and returns an *ssh.Client on success. Each connection is cached and returned if found without checking if it is still valid. To remove a session call Close()
func (*SSHRemote) DialSFTP ¶
DialSFTP connects to the remote host using SSH and returns an *sftp.Client is successful
func (*SSHRemote) IsAvailable ¶
IsAvailable returns true is the remote host can be contacted
func (*SSHRemote) NewSession ¶ added in v1.10.2
NewSession wraps ssh.NewSession but does some retries
func (*SSHRemote) ReadDir ¶
ReadDir reads the named directory and returns all its directory entries sorted by name.
func (*SSHRemote) Run ¶
Run starts a process on an SSH attached remote host h. It uses a shell and waits for the process status before returning. It returns the output and any error. errfile is an optional (remote) file for stderr output
func (*SSHRemote) ServerVersion ¶
func (*SSHRemote) Start ¶
Start starts a process on an SSH attached remote host h. It uses a shell and backgrounds and redirects. May not work on all remotes and for all processes.