mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-16 05:30:27 +08:00
可以在集群中查看待安装节点、并直接安装节点
This commit is contained in:
98
internal/web/actions/default/clusters/cluster/createBatch.go
Normal file
98
internal/web/actions/default/clusters/cluster/createBatch.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CreateBatchAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreateBatchAction) Init() {
|
||||
this.Nav("", "node", "create")
|
||||
this.SecondMenu("nodes")
|
||||
}
|
||||
|
||||
func (this *CreateBatchAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
leftMenuItems := []maps.Map{
|
||||
{
|
||||
"name": "单个创建",
|
||||
"url": "/clusters/cluster/createNode?clusterId=" + strconv.FormatInt(params.ClusterId, 10),
|
||||
"isActive": false,
|
||||
},
|
||||
{
|
||||
"name": "批量创建",
|
||||
"url": "/clusters/cluster/createBatch?clusterId=" + strconv.FormatInt(params.ClusterId, 10),
|
||||
"isActive": true,
|
||||
},
|
||||
}
|
||||
this.Data["leftMenuItems"] = leftMenuItems
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreateBatchAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
IpList string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择正确的集群")
|
||||
}
|
||||
|
||||
// 校验
|
||||
// TODO 支持IP范围,比如:192.168.1.[100-105]
|
||||
realIPList := []string{}
|
||||
for _, ip := range strings.Split(params.IpList, "\n") {
|
||||
ip = strings.TrimSpace(ip)
|
||||
if len(ip) == 0 {
|
||||
continue
|
||||
}
|
||||
ip = strings.ReplaceAll(ip, " ", "")
|
||||
|
||||
if net.ParseIP(ip) == nil {
|
||||
this.Fail("发现错误的IP地址:" + ip)
|
||||
}
|
||||
|
||||
if lists.ContainsString(realIPList, ip) {
|
||||
continue
|
||||
}
|
||||
realIPList = append(realIPList, ip)
|
||||
}
|
||||
|
||||
// 保存
|
||||
for _, ip := range realIPList {
|
||||
resp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
|
||||
Name: ip,
|
||||
ClusterId: params.ClusterId,
|
||||
Login: nil,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
nodeId := resp.NodeId
|
||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||
NodeId: nodeId,
|
||||
Name: "IP地址",
|
||||
Ip: ip,
|
||||
CanAccess: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user