Files
EdgeAPI/internal/db/models/node_ip_address_model_ext.go

45 lines
1.1 KiB
Go
Raw Normal View History

2020-08-30 16:12:00 +08:00
package models
2021-08-18 16:19:16 +08:00
import (
"encoding/json"
2021-09-08 19:34:31 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
2021-08-18 16:19:16 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
)
2021-09-13 10:51:05 +08:00
// DecodeConnectivity 解析联通数值
2021-09-08 19:34:31 +08:00
func (this *NodeIPAddress) DecodeConnectivity() *nodeconfigs.Connectivity {
var connectivity = &nodeconfigs.Connectivity{}
if len(this.Connectivity) > 0 {
2022-03-22 19:30:30 +08:00
err := json.Unmarshal(this.Connectivity, connectivity)
2021-09-08 19:34:31 +08:00
if err != nil {
remotelogs.Error("NodeIPAddress.DecodeConnectivity", "decode failed: "+err.Error())
}
}
return connectivity
}
2021-09-13 10:51:05 +08:00
// DNSIP 获取当前DNS可以使用的IP
func (this *NodeIPAddress) DNSIP() string {
var backupIP = this.DecodeBackupIP()
if len(backupIP) > 0 {
return backupIP
}
return this.Ip
}
// DecodeBackupIP 获取备用IP
func (this *NodeIPAddress) DecodeBackupIP() string {
if this.BackupThresholdId > 0 && len(this.BackupIP) > 0 {
// 阈值是否存在
b, err := SharedNodeIPAddressThresholdDAO.ExistsEnabledThreshold(nil, int64(this.BackupThresholdId))
if err != nil {
remotelogs.Error("NodeIPAddress.DNSIP", "check enabled threshold failed: "+err.Error())
} else {
if b {
return this.BackupIP
}
}
}
return ""
}