Files
EdgeAdmin/internal/web/actions/default/nodes/create.go

69 lines
1.4 KiB
Go
Raw Normal View History

2020-07-22 22:19:39 +08:00
package nodes
import (
2020-07-29 19:34:54 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
2020-07-22 22:19:39 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
2020-07-29 19:34:54 +08:00
"github.com/iwind/TeaGo/maps"
2020-07-22 22:19:39 +08:00
)
type CreateAction struct {
actionutils.ParentAction
}
func (this *CreateAction) Init() {
2020-07-29 19:34:54 +08:00
this.Nav("", "node", "create")
2020-07-22 22:19:39 +08:00
}
func (this *CreateAction) RunGet(params struct{}) {
// 所有集群
2020-07-29 19:34:54 +08:00
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
}
2020-07-22 22:19:39 +08:00
if err != nil {
this.ErrorPage(err)
return
}
clusterMaps := []maps.Map{}
2020-07-29 19:34:54 +08:00
for _, cluster := range resp.Clusters {
2020-07-22 22:19:39 +08:00
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
2020-07-29 19:34:54 +08:00
this.Data["clusters"] = clusterMaps
2020-07-22 22:19:39 +08:00
this.Show()
}
func (this *CreateAction) RunPost(params struct {
Name string
2020-07-29 19:34:54 +08:00
ClusterId int64
2020-07-22 22:19:39 +08:00
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入节点名称")
// TODO 检查cluster
if params.ClusterId <= 0 {
this.Fail("请选择所在集群")
}
// TODO 检查SSH授权
2020-07-29 19:34:54 +08:00
// 保存
_, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
Name: params.Name,
ClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
2020-07-22 22:19:39 +08:00
}