[Excution] - base function start -2
This commit is contained in:
@@ -7,9 +7,9 @@ type BaseFunc interface {
|
||||
}
|
||||
|
||||
type AgentOsOperator struct {
|
||||
InstallCommandPrefix string `json:"install_command_prefix",comment:"apt-get install or yum install"`
|
||||
InstallCommandPrefix []string `json:"install_command_prefix",comment:"apt-get install or yum install"`
|
||||
|
||||
RemoveCommandPrefix string `json:"remove_command_prefix",comment:"apt-get remove or yum remove"`
|
||||
RemoveCommandPrefix []string `json:"remove_command_prefix",comment:"apt-get remove or yum remove"`
|
||||
|
||||
CanAccessInternet bool `json:"can_access_internet",comment:"是否可以访问公网"`
|
||||
|
||||
@@ -31,6 +31,9 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) string
|
||||
case "modifyHostname":
|
||||
multiLineCommand = op.modifyHostname(funcArgs)
|
||||
break
|
||||
case "enableSwap":
|
||||
multiLineCommand = op.enableSwap()
|
||||
break
|
||||
case "disableSwap":
|
||||
multiLineCommand = op.disableSwap()
|
||||
break
|
||||
@@ -72,11 +75,15 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) string
|
||||
|
||||
}
|
||||
|
||||
log.DebugF("multiLineCommand are => %v", multiLineCommand)
|
||||
|
||||
// exec the command here
|
||||
result, _ := MultiLineCommandExecutor(multiLineCommand)
|
||||
for _, singleLineCommand := range multiLineCommand {
|
||||
ReadTimeCommandExecutor(singleLineCommand)
|
||||
}
|
||||
|
||||
// 归一化处理
|
||||
return strings.Join(result, "")
|
||||
return strings.Join([]string{}, "")
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) shutdownFirewall() [][]string {
|
||||
@@ -105,6 +112,24 @@ func (op *AgentOsOperator) modifyHostname(args []string) [][]string {
|
||||
return [][]string{}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) enableSwap() [][]string {
|
||||
|
||||
enableSwapFunc := [][]string{
|
||||
{
|
||||
"cp",
|
||||
"-f",
|
||||
"/etc/fstab_back",
|
||||
"/etc/fstab",
|
||||
},
|
||||
{
|
||||
"cat",
|
||||
"/etc/fstab",
|
||||
},
|
||||
}
|
||||
|
||||
return enableSwapFunc
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) disableSwap() [][]string {
|
||||
|
||||
disableSwapFunc := [][]string{
|
||||
@@ -116,16 +141,12 @@ func (op *AgentOsOperator) disableSwap() [][]string {
|
||||
"cp",
|
||||
"-f",
|
||||
"/etc/fstab",
|
||||
"/etc/fstab_bak",
|
||||
"/etc/fstab_back",
|
||||
},
|
||||
{
|
||||
"cat",
|
||||
"/etc/fstab_bak",
|
||||
"|",
|
||||
"grep",
|
||||
"-v",
|
||||
"swap",
|
||||
">",
|
||||
"sed",
|
||||
"-i",
|
||||
"/swap/d",
|
||||
"/etc/fstab",
|
||||
},
|
||||
}
|
||||
@@ -135,24 +156,25 @@ func (op *AgentOsOperator) disableSwap() [][]string {
|
||||
|
||||
func (op *AgentOsOperator) removeDocker() [][]string {
|
||||
|
||||
removeDockerLine := append(op.RemoveCommandPrefix, []string{
|
||||
"docker",
|
||||
"docker-client",
|
||||
"docker-client-latest",
|
||||
"docker-ce-cli",
|
||||
"docker-common",
|
||||
"docker-latest",
|
||||
"docker-latest-logrotate",
|
||||
"docker-logrotate",
|
||||
"docker-selinux",
|
||||
"docker-engine-selinux",
|
||||
"docker-engine",
|
||||
"kubelet",
|
||||
"kubeadm",
|
||||
"kubectl",
|
||||
}...)
|
||||
|
||||
removeDockerFunc := [][]string{
|
||||
{
|
||||
op.RemoveCommandPrefix,
|
||||
"docker",
|
||||
"docker-client",
|
||||
"docker-client-latest",
|
||||
"docker-ce-cli",
|
||||
"docker-common",
|
||||
"docker-latest",
|
||||
"docker-latest-logrotate",
|
||||
"docker-logrotate",
|
||||
"docker-selinux",
|
||||
"docker-engine-selinux",
|
||||
"docker-engine",
|
||||
"kubelet",
|
||||
"kubeadm",
|
||||
"kubectl",
|
||||
},
|
||||
removeDockerLine,
|
||||
}
|
||||
|
||||
return removeDockerFunc
|
||||
@@ -164,37 +186,81 @@ func (op *AgentOsOperator) installDocker(args []string) [][]string {
|
||||
installDockerFunc := op.removeDocker()
|
||||
|
||||
if op.IsOsTypeUbuntu {
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
{
|
||||
op.InstallCommandPrefix,
|
||||
"apt-transport-https ca-certificates curl gnupg-agent software-properties-common",
|
||||
},
|
||||
{
|
||||
"apt-key",
|
||||
"add",
|
||||
"-",
|
||||
"$(curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg)",
|
||||
},
|
||||
//
|
||||
installFirstLine := append(op.InstallCommandPrefix, []string{
|
||||
"apt-transport-https",
|
||||
"ca-certificates",
|
||||
"curl",
|
||||
"gnupg-agent",
|
||||
"software-properties-common",
|
||||
}...)
|
||||
|
||||
if op.IsAgentInnerWall {
|
||||
// inner gfw
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
installFirstLine,
|
||||
{
|
||||
"curl",
|
||||
"-o",
|
||||
"/etc/docker/docker-utsc.gpg",
|
||||
"https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg",
|
||||
},
|
||||
{
|
||||
"apt-key",
|
||||
"add",
|
||||
"/etc/docker/docker-utsc.gpg",
|
||||
},
|
||||
}...)
|
||||
} else {
|
||||
// outside world
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
installFirstLine,
|
||||
{
|
||||
"curl",
|
||||
"-o",
|
||||
"/etc/docker/docker-utsc.gpg",
|
||||
"https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg",
|
||||
},
|
||||
{
|
||||
"apt-key",
|
||||
"add",
|
||||
"/etc/docker/docker-utsc.gpg",
|
||||
},
|
||||
}...)
|
||||
}
|
||||
|
||||
// look for specific docker-version to install
|
||||
|
||||
} else {
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
{
|
||||
op.InstallCommandPrefix,
|
||||
"yum-utils device-mapper-persistent-data lvm2",
|
||||
},
|
||||
{
|
||||
"yum-config-manager",
|
||||
"--add-repo",
|
||||
"https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo",
|
||||
},
|
||||
{
|
||||
"sed ",
|
||||
"-i ",
|
||||
"'s/download.docker.com/mirrors.ustc.edu.cn\\/docker-ce/g' ",
|
||||
"/etc/yum.repos.d/docker-ce.repo",
|
||||
},
|
||||
{},
|
||||
}...)
|
||||
installFirstLine := append(op.InstallCommandPrefix,
|
||||
[]string{
|
||||
"yum-utils",
|
||||
"device-mapper-persistent-data",
|
||||
"lvm2",
|
||||
}...,
|
||||
)
|
||||
|
||||
if op.IsAgentInnerWall {
|
||||
// inner gfw
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
installFirstLine,
|
||||
{
|
||||
"yum-config-manager",
|
||||
"--add-repo",
|
||||
"https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo",
|
||||
},
|
||||
{
|
||||
"sed ",
|
||||
"-i ",
|
||||
"'s/download.docker.com/mirrors.ustc.edu.cn\\/docker-ce/g' ",
|
||||
"/etc/yum.repos.d/docker-ce.repo",
|
||||
},
|
||||
{},
|
||||
}...)
|
||||
} else {
|
||||
// outside world
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return installDockerFunc
|
||||
|
||||
Reference in New Issue
Block a user