mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	实现DNS节点远程安装
This commit is contained in:
		@@ -30,8 +30,8 @@ func (this *InstallManualAction) RunGet(params struct {
 | 
			
		||||
	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 node.NodeLogin != nil && len(node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err := json.Unmarshal(node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -56,7 +56,7 @@ func (this *InstallManualAction) RunGet(params struct {
 | 
			
		||||
			"isOn":          node.IsOn,
 | 
			
		||||
			"name":          node.Name,
 | 
			
		||||
			"addresses":     node.IpAddresses,
 | 
			
		||||
			"login":         node.Login,
 | 
			
		||||
			"login":         node.NodeLogin,
 | 
			
		||||
			"loginParams":   loginParams,
 | 
			
		||||
			"installStatus": installStatus,
 | 
			
		||||
		})
 | 
			
		||||
 
 | 
			
		||||
@@ -32,8 +32,8 @@ func (this *InstallRemoteAction) RunGet(params struct {
 | 
			
		||||
	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 node.NodeLogin != nil && len(node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err := json.Unmarshal(node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -58,7 +58,7 @@ func (this *InstallRemoteAction) RunGet(params struct {
 | 
			
		||||
			"isOn":          node.IsOn,
 | 
			
		||||
			"name":          node.Name,
 | 
			
		||||
			"addresses":     node.IpAddresses,
 | 
			
		||||
			"login":         node.Login,
 | 
			
		||||
			"login":         node.NodeLogin,
 | 
			
		||||
			"loginParams":   loginParams,
 | 
			
		||||
			"installStatus": installStatus,
 | 
			
		||||
		})
 | 
			
		||||
 
 | 
			
		||||
@@ -141,10 +141,10 @@ func (this *DetailAction) RunGet(params struct {
 | 
			
		||||
 | 
			
		||||
	// 登录信息
 | 
			
		||||
	var loginMap maps.Map = nil
 | 
			
		||||
	if node.Login != nil {
 | 
			
		||||
	if node.NodeLogin != nil {
 | 
			
		||||
		loginParams := maps.Map{}
 | 
			
		||||
		if len(node.Login.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.Login.Params, &loginParams)
 | 
			
		||||
		if len(node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -170,9 +170,9 @@ func (this *DetailAction) RunGet(params struct {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		loginMap = maps.Map{
 | 
			
		||||
			"id":     node.Login.Id,
 | 
			
		||||
			"name":   node.Login.Name,
 | 
			
		||||
			"type":   node.Login.Type,
 | 
			
		||||
			"id":     node.NodeLogin.Id,
 | 
			
		||||
			"name":   node.NodeLogin.Name,
 | 
			
		||||
			"type":   node.NodeLogin.Type,
 | 
			
		||||
			"params": loginParams,
 | 
			
		||||
			"grant":  grantMap,
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -126,10 +126,10 @@ func (this *UpdateAction) RunGet(params struct {
 | 
			
		||||
 | 
			
		||||
	// 登录信息
 | 
			
		||||
	var loginMap maps.Map = nil
 | 
			
		||||
	if node.Login != nil {
 | 
			
		||||
	if node.NodeLogin != nil {
 | 
			
		||||
		loginParams := maps.Map{}
 | 
			
		||||
		if len(node.Login.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.Login.Params, &loginParams)
 | 
			
		||||
		if len(node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -155,9 +155,9 @@ func (this *UpdateAction) RunGet(params struct {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		loginMap = maps.Map{
 | 
			
		||||
			"id":     node.Login.Id,
 | 
			
		||||
			"name":   node.Login.Name,
 | 
			
		||||
			"type":   node.Login.Type,
 | 
			
		||||
			"id":     node.NodeLogin.Id,
 | 
			
		||||
			"name":   node.NodeLogin.Name,
 | 
			
		||||
			"type":   node.NodeLogin.Type,
 | 
			
		||||
			"params": loginParams,
 | 
			
		||||
			"grant":  grantMap,
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -44,10 +44,10 @@ func (this *UpdateNodeSSHAction) RunGet(params struct {
 | 
			
		||||
		"grantId": 0,
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["loginId"] = 0
 | 
			
		||||
	if node.Login != nil {
 | 
			
		||||
		this.Data["loginId"] = node.Login.Id
 | 
			
		||||
		if len(node.Login.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.Login.Params, &loginParams)
 | 
			
		||||
	if node.NodeLogin != nil {
 | 
			
		||||
		this.Data["loginId"] = node.NodeLogin.Id
 | 
			
		||||
		if len(node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
 
 | 
			
		||||
@@ -31,8 +31,8 @@ func (this *UpgradeRemoteAction) RunGet(params struct {
 | 
			
		||||
	}
 | 
			
		||||
	for _, node := range resp.Nodes {
 | 
			
		||||
		loginParams := maps.Map{}
 | 
			
		||||
		if node.Node.Login != nil && len(node.Node.Login.Params) > 0 {
 | 
			
		||||
			err := json.Unmarshal(node.Node.Login.Params, &loginParams)
 | 
			
		||||
		if node.Node.NodeLogin != nil && len(node.Node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err := json.Unmarshal(node.Node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -46,7 +46,7 @@ func (this *UpgradeRemoteAction) RunGet(params struct {
 | 
			
		||||
			"arch":          node.Arch,
 | 
			
		||||
			"oldVersion":    node.OldVersion,
 | 
			
		||||
			"newVersion":    node.NewVersion,
 | 
			
		||||
			"login":         node.Node.Login,
 | 
			
		||||
			"login":         node.Node.NodeLogin,
 | 
			
		||||
			"loginParams":   loginParams,
 | 
			
		||||
			"addresses":     node.Node.IpAddresses,
 | 
			
		||||
			"installStatus": node.Node.InstallStatus,
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ func init() {
 | 
			
		||||
			GetPost("/createNode", new(CreateNodeAction)).
 | 
			
		||||
			Post("/deleteNode", new(DeleteNodeAction)).
 | 
			
		||||
			Get("/upgradeRemote", new(UpgradeRemoteAction)).
 | 
			
		||||
			GetPost("/updateNodeSSH", new(UpdateNodeSSHAction)).
 | 
			
		||||
 | 
			
		||||
			// 节点相关
 | 
			
		||||
			Prefix("/ns/clusters/cluster/node").
 | 
			
		||||
@@ -30,7 +31,6 @@ func init() {
 | 
			
		||||
			GetPost("/install", new(node.InstallAction)).
 | 
			
		||||
			Post("/status", new(node.StatusAction)).
 | 
			
		||||
			Post("/updateInstallStatus", new(node.UpdateInstallStatusAction)).
 | 
			
		||||
 | 
			
		||||
			EndAll()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,123 @@
 | 
			
		||||
package cluster
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type UpdateNodeSSHAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *UpdateNodeSSHAction) Init() {
 | 
			
		||||
	this.Nav("", "", "")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *UpdateNodeSSHAction) RunGet(params struct {
 | 
			
		||||
	NodeId int64
 | 
			
		||||
}) {
 | 
			
		||||
	nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if nodeResp.NsNode == nil {
 | 
			
		||||
		this.NotFound("node", params.NodeId)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	node := nodeResp.NsNode
 | 
			
		||||
	this.Data["node"] = maps.Map{
 | 
			
		||||
		"id":   node.Id,
 | 
			
		||||
		"name": node.Name,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// SSH
 | 
			
		||||
	loginParams := maps.Map{
 | 
			
		||||
		"host":    "",
 | 
			
		||||
		"port":    "",
 | 
			
		||||
		"grantId": 0,
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["loginId"] = 0
 | 
			
		||||
	if node.NodeLogin != nil {
 | 
			
		||||
		this.Data["loginId"] = node.NodeLogin.Id
 | 
			
		||||
		if len(node.NodeLogin.Params) > 0 {
 | 
			
		||||
			err = json.Unmarshal(node.NodeLogin.Params, &loginParams)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["params"] = loginParams
 | 
			
		||||
 | 
			
		||||
	// 认证信息
 | 
			
		||||
	grantId := loginParams.GetInt64("grantId")
 | 
			
		||||
	grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
	}
 | 
			
		||||
	var grantMap maps.Map = nil
 | 
			
		||||
	if grantResp.NodeGrant != nil {
 | 
			
		||||
		grantMap = maps.Map{
 | 
			
		||||
			"id":         grantResp.NodeGrant.Id,
 | 
			
		||||
			"name":       grantResp.NodeGrant.Name,
 | 
			
		||||
			"method":     grantResp.NodeGrant.Method,
 | 
			
		||||
			"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["grant"] = grantMap
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *UpdateNodeSSHAction) RunPost(params struct {
 | 
			
		||||
	NodeId  int64
 | 
			
		||||
	LoginId int64
 | 
			
		||||
	SshHost string
 | 
			
		||||
	SshPort int
 | 
			
		||||
	GrantId int64
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	params.Must.
 | 
			
		||||
		Field("sshHost", params.SshHost).
 | 
			
		||||
		Require("请输入SSH主机地址").
 | 
			
		||||
		Field("sshPort", params.SshPort).
 | 
			
		||||
		Gt(0, "SSH主机端口需要大于0").
 | 
			
		||||
		Lt(65535, "SSH主机端口需要小于65535")
 | 
			
		||||
 | 
			
		||||
	if params.GrantId <= 0 {
 | 
			
		||||
		this.Fail("需要选择或填写至少一个认证信息")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	login := &pb.NodeLogin{
 | 
			
		||||
		Id:   params.LoginId,
 | 
			
		||||
		Name: "SSH",
 | 
			
		||||
		Type: "ssh",
 | 
			
		||||
		Params: maps.Map{
 | 
			
		||||
			"grantId": params.GrantId,
 | 
			
		||||
			"host":    params.SshHost,
 | 
			
		||||
			"port":    params.SshPort,
 | 
			
		||||
		}.AsJSON(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err := this.RPC().NSNodeRPC().UpdateNSNodeLogin(this.AdminContext(), &pb.UpdateNSNodeLoginRequest{
 | 
			
		||||
		NsNodeId:  params.NodeId,
 | 
			
		||||
		NodeLogin: login,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 创建日志
 | 
			
		||||
	defer this.CreateLog(oplogs.LevelInfo, "修改节点 %d 配置", params.NodeId)
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								web/views/@default/ns/clusters/cluster/updateNodeSSH.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								web/views/@default/ns/clusters/cluster/updateNodeSSH.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
{$layout "layout_popup"}
 | 
			
		||||
 | 
			
		||||
<h3>修改节点"{{node.name}}"的SSH登录信息</h3>
 | 
			
		||||
 | 
			
		||||
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
 | 
			
		||||
	<input type="hidden" name="nodeId" :value="node.id"/>
 | 
			
		||||
	<input type="hidden" name="loginId" :value="loginId"/>
 | 
			
		||||
	<table class="ui table definition">
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td class="title">SSH主机地址 *</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<input type="text" name="sshHost" maxlength="64" v-model="params.host" ref="focus"/>
 | 
			
		||||
				<p class="comment">比如192.168.1.100</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td>SSH主机端口 *</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<input type="text" name="sshPort" maxlength="5" v-model="params.port" style="width:6em"/>
 | 
			
		||||
				<p class="comment">比如22。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td>SSH登录认证 *</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<grant-selector :v-grant="grant"></grant-selector>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
	</table>
 | 
			
		||||
	<submit-btn></submit-btn>
 | 
			
		||||
</form>
 | 
			
		||||
							
								
								
									
										5
									
								
								web/views/@default/ns/clusters/cluster/updateNodeSSH.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								web/views/@default/ns/clusters/cluster/updateNodeSSH.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	if (this.params.port <= 0) {
 | 
			
		||||
		this.params.port = 22
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user