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

83 lines
1.6 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-30 22:41:35 +08:00
GrantId int64
SshHost string
SshPort int
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("请选择所在集群")
}
2020-07-30 22:41:35 +08:00
// TODO 检查登录授权
loginInfo := &pb.NodeLogin{
Id: 0,
Name: "SSH",
Type: "ssh",
Params: maps.Map{
"grantId": params.GrantId,
"host": params.SshHost,
"port": params.SshPort,
}.AsJSON(),
}
2020-07-29 19:34:54 +08:00
// 保存
_, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
Name: params.Name,
ClusterId: params.ClusterId,
2020-07-30 22:41:35 +08:00
Login: loginInfo,
2020-07-29 19:34:54 +08:00
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
2020-07-22 22:19:39 +08:00
}