runner

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoteRun

func RemoteRun(item RemoteRunItem) command.RunErr

RemoteRun 远程执行输出结果

func SftpConnect

func SftpConnect(user, password, host string, port string, timeout time.Duration) (sftpClient *sftp.Client, err error)

Types

type DoRequestItem

type DoRequestItem struct {
	S    ServerInternal
	R    RemoteRunItem
	Mock bool
}

type ExecutorExternal

type ExecutorExternal struct {
	Servers  []ServerExternal `yaml:"server"`
	Excludes []string         `yaml:"excludes"`
	Script   string           `yaml:"script"`
	logrus.Logger
}

ExecutorExternal 执行器序列化对象

type ExecutorInternal

type ExecutorInternal struct {
	Servers        []ServerInternal
	Script         string
	Logger         *logrus.Logger
	OutPutRealTime bool
	RunShellFunc   func(shell string, server ServerInternal, timeout time.Duration, logger *logrus.Logger) ShellResult
}

ExecutorInternal 执行器内部对象

func ParseExecutor

func ParseExecutor(b []byte, logger *logrus.Logger) (ExecutorInternal, error)

ParseExecutor 执行器反序列化

func (ExecutorInternal) ParallelRun

func (executor ExecutorInternal) ParallelRun(timeout time.Duration) chan ShellResult

ParallelRun 并发执行 todo: 添加缓冲队列,避免过多goroutine

type InternelServersSlice

type InternelServersSlice []ServerInternal

InternelServersSlice 带有排序的server列表

func (InternelServersSlice) Len

func (servers InternelServersSlice) Len() int

func (InternelServersSlice) Less

func (servers InternelServersSlice) Less(i, j int) bool

func (InternelServersSlice) Swap

func (servers InternelServersSlice) Swap(i, j int)

type Item

type Item struct {
	Server         ServerInternal
	Cmd            string
	Logger         *logrus.Logger
	OutputRealTime bool
}

Item 执行run指令的对象

type RemoteRunItem

type RemoteRunItem struct {
	ManifestContent     []byte
	Logger              *logrus.Logger
	Cmd                 string
	RecordErrServerList bool
	SSHTimeout          time.Duration
	RunShellFunc        func(shell string, server ServerInternal, timeout time.Duration, logger *logrus.Logger) ShellResult
}

type ServerExternal

type ServerExternal struct {
	Host           interface{} `yaml:"host"`
	Port           string      `yaml:"port"`
	Username       string      `yaml:"username"`
	Password       string      `yaml:"password"`
	RootPassword   string      `yaml:"rootPassword"`
	PrivateKeyPath string      `yaml:"privateKeyPath"`
}

ServerExternal server序列化对象

type ServerInternal

type ServerInternal struct {
	Host           string
	Port           string
	UserName       string // ssh user's name -> root, e.g.
	Password       string
	RootPassword   string
	PrivateKeyPath string
}

ServerInternal server内部对象

func ParseServerList

func ParseServerList(b []byte, logger *logrus.Logger) ([]ServerInternal, error)

ParseServerList ServerList反序列化

func (ServerInternal) ReturnRunResult

func (server ServerInternal) ReturnRunResult(item RemoteRunItem) ShellResult

ReturnRunResult 获取执行结果

func (ServerInternal) SSHConnect

func (server ServerInternal) SSHConnect(timeout time.Duration) (*ssh.Session, error)

func (ServerInternal) TailFile

func (server ServerInternal) TailFile(path string, offset int64, whence int, stopCh <-chan struct{})

TailFile all & real time

type ServerListExternal

type ServerListExternal struct {
	Servers  []ServerExternal `yaml:"server"`
	Excludes []string         `yaml:"excludes"`
}

ServerListExternal server列表序列化对象

type ServerListInternal

type ServerListInternal struct {
	Servers  []ServerInternal
	Excludes []string
}

ServerListInternal server列表内部对象

type ShellResult

type ShellResult struct {
	Host      string `table:"主机地址"`
	Cmd       string `table:"执行语句"`
	Code      int    `table:"退出码"`
	Status    string `table:"执行状态"`
	StdOut    string `table:"执行结果"`
	Output    string `table:"标准输出"`
	StdErrMsg string
	Err       error
}

ShellResult shell执行结果

func GetResult

func GetResult(item RemoteRunItem) ([]ShellResult, error)

GetResult 远程执行,获取结果

func LocalRun

func LocalRun(shell string, logger *logrus.Logger) ShellResult

LocalRun 本地执行

func RunOnNode

func RunOnNode(shell string, server ServerInternal, timeout time.Duration, logger *logrus.Logger) (re ShellResult)

func RunOnNodeWithChangeToRoot

func RunOnNodeWithChangeToRoot(shell string, server ServerInternal, timeout time.Duration, logger *logrus.Logger) (re ShellResult)

type ShellResultSlice

type ShellResultSlice []ShellResult

ShellResultSlice shell执行结果切片

func (ShellResultSlice) Len

func (re ShellResultSlice) Len() int

func (ShellResultSlice) Less

func (re ShellResultSlice) Less(i, j int) bool

func (ShellResultSlice) Swap

func (re ShellResultSlice) Swap(i, j int)

type WindowsErr

type WindowsErr struct {
	Errors string
}

Directories

Path Synopsis
scp

Jump to

Keyboard shortcuts

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