Files
EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/updatePopup.go

116 lines
2.7 KiB
Go
Raw Normal View History

2020-08-21 21:09:42 +08:00
package ipAddresses
import (
2021-08-18 16:19:07 +08:00
"encoding/json"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
2021-12-07 18:22:46 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
2020-08-21 21:09:42 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2023-03-01 11:38:21 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
2021-08-18 16:19:07 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-08-21 21:09:42 +08:00
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net"
2020-08-21 21:09:42 +08:00
)
type UpdatePopupAction struct {
actionutils.ParentAction
}
func (this *UpdatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdatePopupAction) RunGet(params struct {
2023-03-01 11:38:21 +08:00
NodeId int64
2021-08-31 17:24:30 +08:00
AddressId int64
SupportThresholds bool
2020-08-21 21:09:42 +08:00
}) {
2023-03-01 11:38:21 +08:00
// 专属集群
clusterMaps, err := ipaddressutils.FindNodeClusterMapsWithNodeId(this.Parent(), params.NodeId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["clusters"] = clusterMaps
2021-08-31 17:24:30 +08:00
this.Data["supportThresholds"] = params.SupportThresholds
2020-08-21 21:09:42 +08:00
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
2021-08-18 16:19:07 +08:00
AddressId int64
IP string `alias:"ip"`
Name string
CanAccess bool
IsOn bool
2021-09-12 20:21:32 +08:00
IsUp bool
2021-08-18 16:19:07 +08:00
ThresholdsJSON []byte
2023-03-01 11:38:21 +08:00
ClusterIds []int64
2020-08-21 21:09:42 +08:00
Must *actions.Must
}) {
params.Must.
Field("ip", params.IP).
Require("请输入IP地址")
// 获取IP地址信息
2021-09-12 20:21:32 +08:00
var isUp = params.IsUp
2021-08-18 16:19:07 +08:00
if params.AddressId > 0 {
2021-08-31 17:24:30 +08:00
addressResp, err := this.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(this.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{NodeIPAddressId: params.AddressId})
2021-08-18 16:19:07 +08:00
if err != nil {
this.ErrorPage(err)
return
}
2021-08-31 17:24:30 +08:00
var address = addressResp.NodeIPAddress
2021-08-18 16:19:07 +08:00
if address == nil {
this.Fail("找不到要修改的地址")
}
}
2021-12-07 18:22:46 +08:00
if params.AddressId > 0 {
ip := net.ParseIP(params.IP)
if len(ip) == 0 {
this.Fail("请输入正确的IP")
}
} else {
result, err := utils.ExtractIP(params.IP)
if err != nil {
this.Fail("IP格式错误'" + params.IP + "'")
}
for _, ip := range result {
if len(net.ParseIP(ip)) == 0 {
this.FailField("ip", "请输入正确的IP")
}
}
2020-08-21 21:09:42 +08:00
}
2021-09-14 19:39:41 +08:00
var thresholds = []*nodeconfigs.IPAddressThresholdConfig{}
2021-08-18 16:19:07 +08:00
if teaconst.IsPlus && len(params.ThresholdsJSON) > 0 {
_ = json.Unmarshal(params.ThresholdsJSON, &thresholds)
}
2023-03-01 11:38:21 +08:00
// 专属集群
// 目前只考虑CDN边缘集群
clusterMaps, err := ipaddressutils.FindNodeClusterMaps(this.Parent(), params.ClusterIds)
if err != nil {
this.ErrorPage(err)
return
}
2020-08-21 21:09:42 +08:00
this.Data["ipAddress"] = maps.Map{
2021-08-18 16:19:07 +08:00
"name": params.Name,
"ip": params.IP,
"id": params.AddressId,
"canAccess": params.CanAccess,
"isOn": params.IsOn,
"isUp": isUp,
"thresholds": thresholds,
2023-03-01 11:38:21 +08:00
"clusters": clusterMaps,
2020-08-21 21:09:42 +08:00
}
this.Success()
}