fix(region,baremetal): ipv6 baremetal register support (#23422)

This commit is contained in:
wanyaoqi
2025-09-29 15:22:22 +08:00
committed by GitHub
parent 1f31c00819
commit 8e6e30d57f
9 changed files with 140 additions and 32 deletions
+12 -1
View File
@@ -17,6 +17,7 @@ package agent
import (
"fmt"
"net"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -82,7 +83,14 @@ func (agent *SBaseAgent) GetListenIPs() []net.IP {
func (agent *SBaseAgent) FindListenIP(listenAddr string) (net.IP, error) {
ips := agent.GetListenIPs()
if listenAddr == "" {
return ips[0], nil
for i := range ips {
ipstr := ips[i].String()
if strings.HasPrefix(ipstr, netutils2.SECRET_PREFIX) {
continue
}
return ips[i], nil
}
return nil, fmt.Errorf("Not Address on Interface %#v", agent.ListenInterface)
}
if listenAddr == "0.0.0.0" {
return net.ParseIP(listenAddr), nil
@@ -287,6 +295,9 @@ func (agent *SBaseAgent) GetManagerUri() string {
if agent.IAgent().GetEnableSsl() {
proto = "https"
}
if accessIP.To4() == nil { // ipv6 addr
return fmt.Sprintf("%s://[%s]:%d", proto, accessIP, agent.IAgent().GetPort())
}
return fmt.Sprintf("%s://%s:%d", proto, accessIP, agent.IAgent().GetPort())
}