mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(region): vmware vm nic sync (#25508)
This commit is contained in:
@@ -4358,13 +4358,22 @@ func (self *SGuest) SyncVMNics(
|
||||
ip := commonext[i].GetIP()
|
||||
ip6 := commonext[i].GetIP6()
|
||||
if len(ip) > 0 {
|
||||
if !network.Contains(ip) {
|
||||
needRebind := network == nil || !network.Contains(ip)
|
||||
// ESXi: force rebind if current network is not under the same manager wire
|
||||
if !needRebind && host.HostType == api.HOST_TYPE_ESXI {
|
||||
wire, _ := network.GetWire()
|
||||
if wire == nil || wire.ManagerId != host.ManagerId {
|
||||
needRebind = true
|
||||
}
|
||||
}
|
||||
if needRebind {
|
||||
localNet, err := getCloudNicNetwork(ctx, commonext[i], host, ipList, i)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "getCloudNicNetwork")
|
||||
}
|
||||
commondb[i].NetworkId = localNet.Id
|
||||
commondb[i].IpAddr = ip
|
||||
commondb[i].Ip6Addr = ip6
|
||||
} else {
|
||||
commondb[i].IpAddr = ip
|
||||
commondb[i].Ip6Addr = ip6
|
||||
|
||||
@@ -3325,6 +3325,23 @@ func (hh *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCredent
|
||||
|
||||
func (hh *SHost) getNetworkOfIPOnHost(ctx context.Context, ipAddr string) (*SNetwork, error) {
|
||||
netInterfaces := hh.GetHostNetInterfaces()
|
||||
// VMware: only associate networks under wires of the same manager_id
|
||||
if hh.HostType == api.HOST_TYPE_ESXI {
|
||||
if len(hh.ManagerId) == 0 {
|
||||
return nil, fmt.Errorf("ESXi host %s has empty manager_id, cannot resolve network for IP %s", hh.Id, ipAddr)
|
||||
}
|
||||
for _, netInterface := range netInterfaces {
|
||||
wire := netInterface.GetWire()
|
||||
if wire == nil || wire.ManagerId != hh.ManagerId {
|
||||
continue
|
||||
}
|
||||
network, err := netInterface.GetCandidateNetworkForIp(ctx, nil, nil, rbacscope.ScopeNone, ipAddr)
|
||||
if err == nil && network != nil {
|
||||
return network, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("IP %s not reachable on ESXi host %s under manager %s", ipAddr, hh.Id, hh.ManagerId)
|
||||
}
|
||||
for _, netInterface := range netInterfaces {
|
||||
network, err := netInterface.GetCandidateNetworkForIp(ctx, nil, nil, rbacscope.ScopeNone, ipAddr)
|
||||
if err == nil && network != nil {
|
||||
|
||||
Reference in New Issue
Block a user