mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	可以在集群中查看待安装节点、并直接安装节点
This commit is contained in:
		@@ -0,0 +1,94 @@
 | 
			
		||||
package cluster
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type InstallRemoteAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *InstallRemoteAction) Init() {
 | 
			
		||||
	this.Nav("", "node", "install")
 | 
			
		||||
	this.SecondMenu("nodes")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *InstallRemoteAction) RunGet(params struct {
 | 
			
		||||
	ClusterId int64
 | 
			
		||||
}) {
 | 
			
		||||
	this.Data["leftMenuItems"] = []maps.Map{
 | 
			
		||||
		{
 | 
			
		||||
			"name":     "自动注册",
 | 
			
		||||
			"url":      "/clusters/cluster/installNodes?clusterId=" + numberutils.FormatInt64(params.ClusterId),
 | 
			
		||||
			"isActive": false,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			"name":     "远程安装",
 | 
			
		||||
			"url":      "/clusters/cluster/installRemote?clusterId=" + numberutils.FormatInt64(params.ClusterId),
 | 
			
		||||
			"isActive": true,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{ClusterId: params.ClusterId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nodeMaps := []maps.Map{}
 | 
			
		||||
	for _, node := range nodesResp.Nodes {
 | 
			
		||||
		loginParams := maps.Map{}
 | 
			
		||||
		if node.Login != nil && len(node.Login.Params) > 0 {
 | 
			
		||||
			err := json.Unmarshal(node.Login.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		installStatus := maps.Map{
 | 
			
		||||
			"isRunning":  false,
 | 
			
		||||
			"isFinished": false,
 | 
			
		||||
		}
 | 
			
		||||
		if node.InstallStatus != nil {
 | 
			
		||||
			installStatus = maps.Map{
 | 
			
		||||
				"isRunning":  node.InstallStatus.IsRunning,
 | 
			
		||||
				"isFinished": node.InstallStatus.IsFinished,
 | 
			
		||||
				"isOk":       node.InstallStatus.IsOk,
 | 
			
		||||
				"error":      node.InstallStatus.Error,
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		nodeMaps = append(nodeMaps, maps.Map{
 | 
			
		||||
			"id":            node.Id,
 | 
			
		||||
			"isOn":          node.IsOn,
 | 
			
		||||
			"name":          node.Name,
 | 
			
		||||
			"addresses":     node.IpAddresses,
 | 
			
		||||
			"login":         node.Login,
 | 
			
		||||
			"loginParams":   loginParams,
 | 
			
		||||
			"installStatus": installStatus,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["nodes"] = nodeMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *InstallRemoteAction) RunPost(params struct {
 | 
			
		||||
	NodeId int64
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	_, err := this.RPC().NodeRPC().InstallNode(this.AdminContext(), &pb.InstallNodeRequest{NodeId: params.NodeId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user