feature: lbagent register (#15872)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2023-02-02 21:32:30 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 692b5512da
commit c2f2ceafd4
20 changed files with 686 additions and 253 deletions
+3 -33
View File
@@ -32,6 +32,7 @@ import (
"yunion.io/x/onecloud/pkg/hostman/storageman"
"yunion.io/x/onecloud/pkg/mcclient"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/util/netutils2"
)
type SZoneInfo struct {
@@ -54,45 +55,14 @@ type SBaseAgent struct {
stop bool
}
func getIfaceIPs(iface *net.Interface) ([]net.IP, error) {
addrs, err := iface.Addrs()
if err != nil {
return nil, err
}
ips := make([]net.IP, 0)
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ips = append(ips, ipnet.IP)
}
}
}
return ips, nil
}
func (agent *SBaseAgent) IAgent() iagent.IAgent {
return agent.GetVirtualObject().(iagent.IAgent)
}
func (agent *SBaseAgent) Init(iagent iagent.IAgent, ifname string, cachePath string) error {
iface, err := net.InterfaceByName(ifname)
iface, ips, err := netutils2.WaitIfaceIps(ifname)
if err != nil {
return err
}
var ips []net.IP
MAX := 60
wait := 0
for wait < MAX {
ips, err = getIfaceIPs(iface)
if err != nil {
return err
}
if len(ips) == 0 {
time.Sleep(2 * time.Second)
wait += 2
} else {
break
}
return errors.Wrap(err, "WaitIfaceIps")
}
if len(ips) == 0 {
return fmt.Errorf("Interface %s ip address not found", ifname)