util

package
v0.0.0-...-46787ec Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CommandFailed show ssh command execute Failed
	CommandFailed = "Failed"
	// CommandSuccess show ssh command execute Success
	CommandSuccess = "Success"
	// CmdCommand show the according to params cmdType value,exec ssh command
	CmdCommand = "command"
	// CmdScript show the according to params cmdType value,exec ssh command
	CmdScript = "script"
	// Cobra* show cobra subcommand  name
	CobraInspect = "inspect"
)

Variables

This section is empty.

Functions

func CheckAndSplitCommandArgs

func CheckAndSplitCommandArgs(cmdArgs string) (cmdList []string)

CheckAndSplitCommandArgs function,check one and more command params whether flagFormat correct,for example: hostname;date;ip addr

func Cmp

func Cmp(a, b net.IP) int

Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1

func ColorPrintWithTerminalStyle

func ColorPrintWithTerminalStyle(logLevel string, textBefore interface{}, colorText string,
	textAfter ...interface{})

ColorPrintWithTerminalStyle function, console output color control, compatible with Windows & Linux

func DiffStringSlices

func DiffStringSlices(slice1 []string, slice2 []string) []string

DiffStringSlices function,Get the different items between two slices diffStringSlices function,Get difference items between two slices

func FileExists

func FileExists(path string) bool

determine if the given path file / folder exists

func FooterColorPrintStyleWithoutTotalHostInfo

func FooterColorPrintStyleWithoutTotalHostInfo(taskName string)

func FooterColorPrintWithStyle

func FooterColorPrintWithStyle(taskName, totalHostsInfo string)

func FormatResultLogWithBasicStyle

func FormatResultLogWithBasicStyle(k int, sshResult SSHResult)

func HeaderColorPrintWithStyle

func HeaderColorPrintWithStyle(taskName string)

func K8sVersionConvertToInt

func K8sVersionConvertToInt(version string) int

Kubernentes version convert to int

func Md5SumLocalFile

func Md5SumLocalFile(fileName string) string

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns IP incremented by 1

func ParseIPSegment

func ParseIPSegment(ips []string) []string

ParseIPSegment,for example IP 192.168.0.2-192.168.0.6

func SFTPCommandSessionExecMain

func SFTPCommandSessionExecMain(taskName string, ssHost []string, sshPort, sshUser, sshPassword, privateKeyFileName,
	sshKeyPassword string, localFilePath, remoteFilePath string)

SFTPCommandSessionExecMain function

func SFTPCopy

func SFTPCopy(sshHost, sshPort, sshUser, sshPassword, privateKeyFileName,
	sshKeyPassword string, localFilePath, remoteFilePath string)

SFTPCopy function,the local file is delivered to other hosts at the same path

func SessionCommandExec

func SessionCommandExec(cobraCmd string, taskName string, ssHost []string, cmdType string, sshUser, sshPort,
	sshPassword, privateKeyFileName, sshKeyPassword, command,
	scriptFileName, scriptArgs string)

SessionCommandExec function

func StringSliceCountValues

func StringSliceCountValues(args []string) (Status bool, AllRepeatValue []string, MaxCount int,
	MaxValue []string)

StringSliceCountValues function,find out how many times there are duplicate elements in an array and their values, If the number of slice elements is higher than 1, the array have duplicate elements

func StringSliceRemoveRepeat

func StringSliceRemoveRepeat(stringSliceList []string) []string

StringSliceRemoveRepeat is used for single string slice remove repeat

func StringTwoSliceRepeatElem

func StringTwoSliceRepeatElem(a, b []string) []string

StringTwoSliceRepeatElem function,find two slice repeat elem

Types

type CommandHostInfo

type CommandHostInfo struct {
	Host               string
	SSHUser            string
	SSHPort            string
	SSHPassword        string
	PrivateKeyFileName string
	SSHKeyPassword     string
	Command            string
}

CommandHostInfo struct

func CommandSSHResult

func CommandSSHResult(sshHost, sshUser, sshPort, sshPassword, privateKeyFileName, sshKeyPassword,
	command string) *CommandHostInfo

CommandSSHResult function

func (*CommandHostInfo) CommandSessionExec

func (ch *CommandHostInfo) CommandSessionExec(chCmd chan SSHResult)

CommandSessionExec function

type HostRequired

type HostRequired struct {
	Host   string
	Result interface{}
}

HostRequired struct

type LogicSFTPClient

type LogicSFTPClient struct {
	SFTPClient *sftp.Client
}

LogicSFTPClient struct

func (*LogicSFTPClient) CloseSFTPClient

func (l *LogicSFTPClient) CloseSFTPClient()

CloseSSHClient function

type LogicSSHClient

type LogicSSHClient struct {
	SSHClient *ssh.Client
}

LogicSSHClient struct

func (*LogicSSHClient) CloseSSHClient

func (l *LogicSSHClient) CloseSSHClient()

CloseSSHClient function

type LogicSSHSession

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

LogicSSHSession struct

func (*LogicSSHSession) CloseSSHSession

func (s *LogicSSHSession) CloseSSHSession()

CloseSSHSession function

type Pool

type Pool struct {
	Wg   *sync.WaitGroup
	Size int // pool size
	// contains filtered or unexported fields
}

Pool struct https://www.golangtc.com/t/559e97d6b09ecc22f6000053 control the number of Goroutine concurrency by waitGroup + channel

func NewPool

func NewPool(cap, total int) *Pool

NewPool function,create a shared lock with parallelism shared credentials

func (*Pool) Acquire

func (p *Pool) Acquire()

Acquire function,get a voucher

func (*Pool) AvailableCredential

func (p *Pool) AvailableCredential() int

AvailableCredential function

func (*Pool) Release

func (p *Pool) Release()

Release function,release a credential

func (*Pool) TryAcquire

func (p *Pool) TryAcquire() bool

TryAcquire function,try acquire credential

type SSHResult

type SSHResult struct {
	Host      string
	User      string
	Port      string
	Command   string
	Status    string
	Result    string
	StartTime string
	EndTime   string
	CostTime  string
}

SSHResult struct,show single machine run result

type SSHResultLog

type SSHResultLog struct {
	Task           string
	SuccessHosts   []SSHResult
	ErrorHosts     []SSHResult
	TotalHostsInfo string
}

SSHResultLog struct

func SSHCommandSessionExecMain

func SSHCommandSessionExecMain(taskName string, ssHost []string, cmdType string, sshUser, sshPort, sshPassword,
	privateKeyFileName,
	sshKeyPassword, command string, scriptFileName, scriptArgs string) *SSHResultLog

SSHCommandSessionExecMain function

func (*SSHResultLog) FormatResultLogWithJSONStyle

func (sl *SSHResultLog) FormatResultLogWithJSONStyle()

func (*SSHResultLog) FormatResultLogWithSimpleStyle

func (sl *SSHResultLog) FormatResultLogWithSimpleStyle()

FormatResultLogWithSimpleStyle function

func (*SSHResultLog) FormatResultLogWithStyle

func (sl *SSHResultLog) FormatResultLogWithStyle(taskName string)

FormatResultLogWithStyle function

func (*SSHResultLog) InspectCommandSystemEnvironmentResultCheck

func (sl *SSHResultLog) InspectCommandSystemEnvironmentResultCheck(taskName string)

InspectCommandSystemEnvironmentResultCheck function

func (*SSHResultLog) ResultCheckRemoteHostFileExist

func (sl *SSHResultLog) ResultCheckRemoteHostFileExist() (hostExist, hostNoExist []string)

Host file check, output array with or without host file

func (*SSHResultLog) ResultCheckRemoteHostFileMd5

func (sl *SSHResultLog) ResultCheckRemoteHostFileMd5(md5Sum string) (hostExist []string)

func (*SSHResultLog) ResultOutputCgroupDriver

func (sl *SSHResultLog) ResultOutputCgroupDriver() (cgroupDriver string)

func (*SSHResultLog) ResultOutputCheckAndProcessExit

func (sl *SSHResultLog) ResultOutputCheckAndProcessExit(taskName string)

ResultOutputCheckAndProcessExit function,mainly used for ssh session command run,check ssh result whether exist error host record.if exist,process exit,otherwise continue run other command.

func (*SSHResultLog) ResultOutputKubeadmJoinMasterCert

func (sl *SSHResultLog) ResultOutputKubeadmJoinMasterCert() (certificateKey string)

func (*SSHResultLog) ResultOutputKubeadmJoinParams

func (sl *SSHResultLog) ResultOutputKubeadmJoinParams() (joinToken, tokenCaCertHash string)

decode master0 output to join token hash and key

type ScriptHostInfo

type ScriptHostInfo struct {
	Host               string
	SSHUser            string
	SSHPort            string
	SSHPassword        string
	PrivateKeyFileName string
	SSHKeyPassword     string
	ScriptFileName     string
	ScriptArgs         string
}

ScriptHostInfo struct

func ScriptSSHResult

func ScriptSSHResult(host, sshUser, sshPort, sshPassword, privateKeyFileName, sshKeyPassword, scriptFileName, scriptArgs string) *ScriptHostInfo

ScriptSSHResult function

func (*ScriptHostInfo) ScriptSessionExec

func (sh *ScriptHostInfo) ScriptSessionExec(chScript chan SSHResult)

Jump to

Keyboard shortcuts

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