connector

package
v3.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 23 Imported by: 39

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SudoPrefix

func SudoPrefix(cmd string) string

Types

type BaseHost

type BaseHost struct {
	Name            string `yaml:"name,omitempty" json:"name,omitempty"`
	Address         string `yaml:"address,omitempty" json:"address,omitempty"`
	InternalAddress string `yaml:"internalAddress,omitempty" json:"internalAddress,omitempty"`
	Port            int    `yaml:"port,omitempty" json:"port,omitempty"`
	User            string `yaml:"user,omitempty" json:"user,omitempty"`
	Password        string `yaml:"password,omitempty" json:"password,omitempty"`
	PrivateKey      string `yaml:"privateKey,omitempty" json:"privateKey,omitempty"`
	PrivateKeyPath  string `yaml:"privateKeyPath,omitempty" json:"privateKeyPath,omitempty"`
	Arch            string `yaml:"arch,omitempty" json:"arch,omitempty"`
	Timeout         int64  `yaml:"timeout,omitempty" json:"timeout,omitempty"`

	Roles     []string        `json:"-"`
	RoleTable map[string]bool `json:"-"`
	Cache     *cache.Cache    `json:"-"`
}

func NewHost

func NewHost() *BaseHost

func (*BaseHost) GetAddress

func (b *BaseHost) GetAddress() string

func (*BaseHost) GetArch

func (b *BaseHost) GetArch() string

func (*BaseHost) GetCache

func (b *BaseHost) GetCache() *cache.Cache

func (*BaseHost) GetInternalAddress

func (b *BaseHost) GetInternalAddress() string

func (*BaseHost) GetName

func (b *BaseHost) GetName() string

func (*BaseHost) GetPassword

func (b *BaseHost) GetPassword() string

func (*BaseHost) GetPort

func (b *BaseHost) GetPort() int

func (*BaseHost) GetPrivateKey

func (b *BaseHost) GetPrivateKey() string

func (*BaseHost) GetPrivateKeyPath

func (b *BaseHost) GetPrivateKeyPath() string

func (*BaseHost) GetRoles

func (b *BaseHost) GetRoles() []string

func (*BaseHost) GetTimeout

func (b *BaseHost) GetTimeout() int64

func (*BaseHost) GetUser

func (b *BaseHost) GetUser() string

func (*BaseHost) IsRole

func (b *BaseHost) IsRole(role string) bool

func (*BaseHost) SetAddress

func (b *BaseHost) SetAddress(str string)

func (*BaseHost) SetArch

func (b *BaseHost) SetArch(arch string)

func (*BaseHost) SetCache

func (b *BaseHost) SetCache(c *cache.Cache)

func (*BaseHost) SetInternalAddress

func (b *BaseHost) SetInternalAddress(str string)

func (*BaseHost) SetName

func (b *BaseHost) SetName(name string)

func (*BaseHost) SetPassword

func (b *BaseHost) SetPassword(password string)

func (*BaseHost) SetPort

func (b *BaseHost) SetPort(port int)

func (*BaseHost) SetPrivateKey

func (b *BaseHost) SetPrivateKey(privateKey string)

func (*BaseHost) SetPrivateKeyPath

func (b *BaseHost) SetPrivateKeyPath(path string)

func (*BaseHost) SetRole

func (b *BaseHost) SetRole(role string)

func (*BaseHost) SetRoles

func (b *BaseHost) SetRoles(roles []string)

func (*BaseHost) SetTimeout

func (b *BaseHost) SetTimeout(timeout int64)

func (*BaseHost) SetUser

func (b *BaseHost) SetUser(u string)

type BaseRuntime

type BaseRuntime struct {
	ObjName string
	// contains filtered or unexported fields
}

func NewBaseRuntime

func NewBaseRuntime(name string, connector Connector, verbose bool, ignoreErr bool) BaseRuntime

func (*BaseRuntime) AppendHost

func (b *BaseRuntime) AppendHost(host Host)

func (*BaseRuntime) AppendRoleMap

func (b *BaseRuntime) AppendRoleMap(host Host)

func (*BaseRuntime) Copy

func (b *BaseRuntime) Copy() Runtime

func (*BaseRuntime) DeleteHost

func (b *BaseRuntime) DeleteHost(host Host)

func (*BaseRuntime) GenerateRoleMap

func (b *BaseRuntime) GenerateRoleMap()

func (*BaseRuntime) GenerateWorkDir

func (b *BaseRuntime) GenerateWorkDir() error

func (*BaseRuntime) GetAllHosts

func (b *BaseRuntime) GetAllHosts() []Host

func (*BaseRuntime) GetConnector

func (b *BaseRuntime) GetConnector() Connector

func (*BaseRuntime) GetHostWorkDir

func (b *BaseRuntime) GetHostWorkDir() string

func (*BaseRuntime) GetHostsByRole

func (b *BaseRuntime) GetHostsByRole(role string) []Host

func (*BaseRuntime) GetIgnoreErr

func (b *BaseRuntime) GetIgnoreErr() bool

func (*BaseRuntime) GetObjName

func (b *BaseRuntime) GetObjName() string

func (*BaseRuntime) GetRunner

func (b *BaseRuntime) GetRunner() *Runner

func (*BaseRuntime) GetWorkDir

func (b *BaseRuntime) GetWorkDir() string

func (*BaseRuntime) HostIsDeprecated

func (b *BaseRuntime) HostIsDeprecated(host Host) bool

func (*BaseRuntime) InitLogger

func (b *BaseRuntime) InitLogger() error

func (*BaseRuntime) RemoteHost

func (b *BaseRuntime) RemoteHost() Host

func (*BaseRuntime) RoleMapDelete

func (b *BaseRuntime) RoleMapDelete(host Host)

func (*BaseRuntime) SetAllHosts

func (b *BaseRuntime) SetAllHosts(hosts []Host)

func (*BaseRuntime) SetConnector

func (b *BaseRuntime) SetConnector(c Connector)

func (*BaseRuntime) SetObjName

func (b *BaseRuntime) SetObjName(name string)

func (*BaseRuntime) SetRunner

func (b *BaseRuntime) SetRunner(r *Runner)

type Cfg

type Cfg struct {
	Username    string
	Password    string
	Address     string
	Port        int
	PrivateKey  string
	KeyFile     string
	AgentSocket string
	Timeout     time.Duration
	Bastion     string
	BastionPort int
	BastionUser string
}

type Connection

type Connection interface {
	Exec(cmd string, host Host) (stdout string, code int, err error)
	PExec(cmd string, stdin io.Reader, stdout io.Writer, stderr io.Writer, host Host) (code int, err error)
	Fetch(local, remote string, host Host) error
	Scp(local, remote string, host Host) error
	RemoteFileExist(remote string, host Host) bool
	RemoteDirExist(remote string, host Host) (bool, error)
	MkDirAll(path string, mode string, host Host) error
	Chmod(path string, mode os.FileMode) error
	Close()
}

func NewConnection

func NewConnection(cfg Cfg) (Connection, error)

type Connector

type Connector interface {
	Connect(host Host) (Connection, error)
	Close(host Host)
}

type Dialer

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

func NewDialer

func NewDialer() *Dialer

func (*Dialer) Close

func (d *Dialer) Close(host Host)

func (*Dialer) Connect

func (d *Dialer) Connect(host Host) (Connection, error)

type Host

type Host interface {
	GetName() string
	SetName(name string)
	GetAddress() string
	SetAddress(str string)
	GetInternalAddress() string
	SetInternalAddress(str string)
	GetPort() int
	SetPort(port int)
	GetUser() string
	SetUser(u string)
	GetPassword() string
	SetPassword(password string)
	GetPrivateKey() string
	SetPrivateKey(privateKey string)
	GetPrivateKeyPath() string
	SetPrivateKeyPath(path string)
	GetArch() string
	SetArch(arch string)
	GetTimeout() int64
	SetTimeout(timeout int64)
	GetRoles() []string
	SetRoles(roles []string)
	IsRole(role string) bool
	GetCache() *cache.Cache
	SetCache(c *cache.Cache)
}

type ModuleRuntime

type ModuleRuntime interface {
	GetObjName() string
	SetObjName(name string)
	GenerateWorkDir() error
	GetHostWorkDir() string
	GetWorkDir() string
	GetIgnoreErr() bool
	GetAllHosts() []Host
	SetAllHosts([]Host)
	GetHostsByRole(role string) []Host
	DeleteHost(host Host)
	HostIsDeprecated(host Host) bool
	InitLogger() error
}

type Runner

type Runner struct {
	Conn  Connection
	Debug bool
	Host  Host
	Index int
}

func (*Runner) Chmod

func (r *Runner) Chmod(path string, mode os.FileMode) error

func (*Runner) Cmd

func (r *Runner) Cmd(cmd string, printOutput bool) (string, error)

func (*Runner) DirExist

func (r *Runner) DirExist(remote string) (bool, error)

func (*Runner) Exec

func (r *Runner) Exec(cmd string, printOutput bool) (string, int, error)

func (*Runner) Fetch

func (r *Runner) Fetch(local, remote string) error

func (*Runner) FileExist

func (r *Runner) FileExist(remote string) (bool, error)

func (*Runner) FileMd5

func (r *Runner) FileMd5(path string) (string, error)

func (*Runner) MkDir

func (r *Runner) MkDir(path string) error

func (*Runner) Scp

func (r *Runner) Scp(local, remote string) error

func (*Runner) SudoCmd

func (r *Runner) SudoCmd(cmd string, printOutput bool) (string, error)

func (*Runner) SudoExec

func (r *Runner) SudoExec(cmd string, printOutput bool) (string, int, error)

func (*Runner) SudoScp

func (r *Runner) SudoScp(local, remote string) error

type Runtime

type Runtime interface {
	GetRunner() *Runner
	SetRunner(r *Runner)
	GetConnector() Connector
	SetConnector(c Connector)
	RemoteHost() Host
	Copy() Runtime
	ModuleRuntime
}

type Tee

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

func NewTee

func NewTee(wc io.WriteCloser) *Tee

NewTee constructor

func (*Tee) Close

func (t *Tee) Close() error

Close underlying io.Closer

func (*Tee) String

func (t *Tee) String() string

func (*Tee) Write

func (t *Tee) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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