Documentation
¶
Index ¶
Constants ¶
View Source
const ( // TransferGet get file from remote servers TransferGet = "GET" // TransferPut put file to remote servers TransferPut = "PUT" // TransferDefaultMaxSize default max size to transfer TransferDefaultMaxSize = 1099511627776 // 100MB )
Variables ¶
View Source
var ConfigFileList = []string{
"./optool.yml",
homeDir() + "/optool.yml",
"/etc/optool.yml",
"/tmp/optool.yml",
}
ConfigFileList read config file one by one if not exists
View Source
var UUIDPath = homeDir() + "/.optool-id"
UUIDPath default path for saving machine ID
Functions ¶
func GetAuth ¶
func GetAuth() (auth []ssh.AuthMethod, err error)
GetAuth get auth method list from configs
Types ¶
type AuthConfig ¶
type AuthConfig struct {
User string `yaml:"user"`
Password string `yaml:"password"`
PrivateKey string `yaml:"private_key"`
PrivateKeyContent string `yaml:"private_key_content"`
PrivateKeyPhrase string `yaml:"private_key_phrase"`
PlainPassword bool `yaml:"plain_password"` // 是否是明文的密码(通用password和phrase)
}
AuthConfig configures for host authorization
type Configure ¶
type Configure struct {
Server Server `yaml:"server"`
//Hosts map[string][]string `yaml:"hosts"` // structure: group => host list
Auth AuthConfig `yaml:"auth"`
Tags map[string]string `yaml:"tags"` // shortcut for frequently used commands
Gzip bool `yaml:"-"` // enable gzip transfer
//DefaultGroup string `yaml:"default_group"` // set default host group
TransferMaxSize int64 `yaml:"transfer_max_size"`
}
Configure global configure
var C *Configure
C exported parsed configure
type FileTransfer ¶
FileTransfer transfer file info
type RemoteCommand ¶
type RemoteCommand struct {
Hosts []string
Cmd string
PipeMode bool
PipeChan chan bool
PipeIn map[string]io.WriteCloser
PipeOut map[string]io.Reader
PipeError map[string]io.Reader
Output map[string]string
Error map[string]string
Running map[string]*ssh.Session
// contains filtered or unexported fields
}
RemoteCommand remote command structure
func NewRemoteCommand ¶
func NewRemoteCommand(hosts []string, cmd string) *RemoteCommand
NewRemoteCommand prepare a remote execution
func (*RemoteCommand) PrettyPrint ¶
PrettyPrint print output and errors
type Server ¶
type Server struct {
DefaultGroup string `yaml:"default_group"`
DefaultPort int `yaml:"default_port"`
Hosts map[string][]string `yaml:"hosts"`
}
Server server groups and default port/group config
type Transfer ¶
type Transfer struct {
Inited bool
Method string // GET,PUT
LocalPath string
RemotePath string
Recursive bool
Hosts []string
Clients map[string]*ssh.Client
SftpClient map[string]*sftp.Client
Override bool // override remote existed file?
TransferResult map[string]FileTransfer // result of transfering
Lock sync.Mutex
}
Transfer transfer files via ssh
func NewTransfer ¶
NewTransfer get file transfer instance
Click to show internal directories.
Click to hide internal directories.