mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-06 07:25:48 +08:00
可以修改节点的DNS设置
This commit is contained in:
@@ -598,6 +598,52 @@ func (this *NodeDAO) CountAllEnabledNodesWithGroupId(groupId int64) (int64, erro
|
||||
Count()
|
||||
}
|
||||
|
||||
// 获取一个集群的节点DNS信息
|
||||
func (this *NodeDAO) FindAllEnabledNodesDNSWithClusterId(clusterId int64) (result []*Node, err error) {
|
||||
_, err = this.Query().
|
||||
State(NodeStateEnabled).
|
||||
Attr("clusterId", clusterId).
|
||||
Attr("isOn", true).
|
||||
Result("id", "name", "dnsRoutes").
|
||||
DescPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取单个节点的DNS信息
|
||||
func (this *NodeDAO) FindEnabledNodeDNS(nodeId int64) (*Node, error) {
|
||||
one, err := this.Query().
|
||||
State(NodeStateEnabled).
|
||||
Pk(nodeId).
|
||||
Attr("isOn", true).
|
||||
Result("id", "name", "dnsRoutes", "clusterId").
|
||||
Find()
|
||||
if err != nil || one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*Node), nil
|
||||
}
|
||||
|
||||
// 修改节点的DNS信息
|
||||
func (this *NodeDAO) UpdateNodeDNS(nodeId int64, routes map[int64]string) error {
|
||||
if nodeId <= 0 {
|
||||
return errors.New("invalid nodeId")
|
||||
}
|
||||
if routes == nil {
|
||||
routes = map[int64]string{}
|
||||
}
|
||||
routesJSON, err := json.Marshal(routes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
op := NewNodeOperator()
|
||||
op.Id = nodeId
|
||||
op.DnsRoutes = routesJSON
|
||||
_, err = this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 生成唯一ID
|
||||
func (this *NodeDAO) genUniqueId() (string, error) {
|
||||
for {
|
||||
|
||||
@@ -115,6 +115,18 @@ func (this *NodeIPAddressDAO) UpdateAddress(addressId int64, name string, ip str
|
||||
return err
|
||||
}
|
||||
|
||||
// 修改IP地址中的IP
|
||||
func (this *NodeIPAddressDAO) UpdateAddressIP(addressId int64, ip string) error {
|
||||
if addressId <= 0 {
|
||||
return errors.New("invalid addressId")
|
||||
}
|
||||
op := NewNodeIPAddressOperator()
|
||||
op.Id = addressId
|
||||
op.Ip = ip
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 修改IP地址所属节点
|
||||
func (this *NodeIPAddressDAO) UpdateAddressNodeId(addressId int64, nodeId int64) error {
|
||||
_, err := this.Query().
|
||||
@@ -148,3 +160,15 @@ func (this *NodeIPAddressDAO) FindFirstNodeIPAddress(nodeId int64) (string, erro
|
||||
Result("ip").
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 查找节点的第一个可访问的IP地址ID
|
||||
func (this *NodeIPAddressDAO) FindFirstNodeIPAddressId(nodeId int64) (int64, error) {
|
||||
return this.Query().
|
||||
Attr("nodeId", nodeId).
|
||||
State(NodeIPAddressStateEnabled).
|
||||
Attr("canAccess", true).
|
||||
Desc("order").
|
||||
AscPk().
|
||||
Result("id").
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,19 @@ func (this *Node) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
|
||||
return status, nil
|
||||
}
|
||||
|
||||
// 所有的DNS线路
|
||||
func (this *Node) DNSRoutes() (map[int64]string, error) {
|
||||
routes := map[int64]string{} // domainId => route
|
||||
if len(this.DnsRoutes) == 0 || this.DnsRoutes == "null" {
|
||||
return routes, nil
|
||||
}
|
||||
err := json.Unmarshal([]byte(this.DnsRoutes), &routes)
|
||||
if err != nil {
|
||||
return map[int64]string{}, err
|
||||
}
|
||||
return routes, nil
|
||||
}
|
||||
|
||||
// DNS线路
|
||||
func (this *Node) DNSRoute(dnsDomainId int64) (string, error) {
|
||||
routes := map[int64]string{} // domainId => route
|
||||
|
||||
Reference in New Issue
Block a user