64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package clusters
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils"
|
|
"github.com/iwind/TeaGo/actions"
|
|
)
|
|
|
|
type CreateNodeAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *CreateNodeAction) Init() {
|
|
this.Nav("httpdns", "cluster", "createNode")
|
|
}
|
|
|
|
func (this *CreateNodeAction) RunGet(params struct {
|
|
ClusterId int64
|
|
}) {
|
|
httpdnsutils.AddLeftMenu(this.Parent())
|
|
|
|
cluster, err := findClusterMap(this.Parent(), params.ClusterId)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
httpdnsutils.AddClusterTabbar(this.Parent(), cluster.GetString("name"), params.ClusterId, "node")
|
|
this.Data["clusterId"] = params.ClusterId
|
|
this.Data["cluster"] = cluster
|
|
this.Show()
|
|
}
|
|
|
|
func (this *CreateNodeAction) RunPost(params struct {
|
|
ClusterId int64
|
|
Name string
|
|
InstallDir string
|
|
|
|
Must *actions.Must
|
|
}) {
|
|
params.Name = strings.TrimSpace(params.Name)
|
|
params.InstallDir = strings.TrimSpace(params.InstallDir)
|
|
params.Must.Field("clusterId", params.ClusterId).Gt(0, "请选择集群")
|
|
params.Must.Field("name", params.Name).Require("请输入节点名称")
|
|
|
|
if len(params.InstallDir) == 0 {
|
|
cluster, err := findClusterMap(this.Parent(), params.ClusterId)
|
|
if err == nil {
|
|
params.InstallDir = strings.TrimSpace(cluster.GetString("installDir"))
|
|
}
|
|
if len(params.InstallDir) == 0 {
|
|
params.InstallDir = "/opt/edge-httpdns"
|
|
}
|
|
}
|
|
|
|
if err := createNode(this.Parent(), params.ClusterId, params.Name, params.InstallDir); err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
this.Success()
|
|
}
|