fix: avoid panic when sync vmware host

This commit is contained in:
ioito
2023-04-13 19:29:32 +08:00
parent 13ad64a3b4
commit ece9195dfb
2 changed files with 9 additions and 7 deletions
+4 -2
View File
@@ -2113,6 +2113,7 @@ func getZoneForPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCr
if err != nil {
return nil, errors.Wrap(err, "unable to GetIHosts")
}
ips := []string{}
for _, extHost := range extHosts {
// onpremise host
accessIp := extHost.GetAccessIp()
@@ -2121,6 +2122,7 @@ func getZoneForPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCr
log.Errorf(msg)
continue
}
ips = append(ips, accessIp)
wire, err := WireManager.GetOnPremiseWireOfIp(accessIp)
if err != nil {
msg := fmt.Sprintf("fail to find wire for host %s %s: %s", extHost.GetName(), accessIp, err)
@@ -2129,7 +2131,7 @@ func getZoneForPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCr
}
return wire.GetZone()
}
return nil, errors.Wrap(errors.ErrNotFound, "no suitable zone")
return nil, errors.Wrapf(errors.ErrNotFound, "no suitable zone with accessIp %s", ips)
}
func syncOnPremiseCloudProviderStorage(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, iregion cloudprovider.ICloudRegion, driver cloudprovider.ICloudProvider, syncRange *SSyncRange) []sStoragecacheSyncPair {
@@ -2141,7 +2143,7 @@ func syncOnPremiseCloudProviderStorage(ctx context.Context, userCred mcclient.To
}
zone, err := getZoneForPremiseCloudRegion(ctx, userCred, iregion)
if err != nil {
msg := fmt.Sprintf("Can't get zone for Premise cloud region %s", iregion.GetName())
msg := fmt.Sprintf("Can't get zone for Premise cloud region %s error: %v", iregion.GetName(), err)
log.Errorf(msg)
return nil
}
+5 -5
View File
@@ -2118,16 +2118,16 @@ func (manager *SHostManager) NewFromCloudHost(ctx context.Context, userCred mccl
accessIp := extHost.GetAccessIp()
if len(accessIp) == 0 {
msg := fmt.Sprintf("fail to find wire for host %s: empty host access ip", extHost.GetName())
log.Errorf(msg)
return nil, fmt.Errorf(msg)
}
wire, err := WireManager.GetOnPremiseWireOfIp(accessIp)
if err != nil {
msg := fmt.Sprintf("fail to find wire for host %s %s: %s", extHost.GetName(), accessIp, err)
log.Errorf(msg)
return nil, fmt.Errorf(msg)
return nil, errors.Wrapf(err, "GetOnPremiseWireOfIp for host %s with ip %s", extHost.GetName(), accessIp)
}
izone, err = wire.GetZone()
if err != nil {
return nil, errors.Wrapf(err, "get zone for wire %s", wire.Name)
}
izone, _ = wire.GetZone()
}
host.ExternalId = extHost.GetGlobalId()