optimize(region,host): add details error message when adding net interface (#21062)

This commit is contained in:
Zexi Li
2024-08-20 18:38:58 +08:00
committed by GitHub
parent 5b9ef62f5b
commit aee9c6db46
3 changed files with 6 additions and 5 deletions
+2 -1
View File
@@ -5259,6 +5259,7 @@ func (h *SHost) EnableNetif(ctx context.Context, userCred mcclient.TokenCredenti
log.Errorf("Cannot allocate IP %s, not reachable", ipAddr)
return fmt.Errorf("Cannot allocate IP %s, not reachable", ipAddr)
} else {
log.Infof("not found network with scope: %s, ip_addr: %s", NetworkManager.AllowScope(userCred), ipAddr)
// the ipaddr is not usable, should be reset to empty
ipAddr = ""
}
@@ -5302,7 +5303,7 @@ func (h *SHost) EnableNetif(ctx context.Context, userCred mcclient.TokenCredenti
return fmt.Errorf("fail to find public network %s", err)
}
if net == nil {
return fmt.Errorf("No network found")
return fmt.Errorf("No auto_alloc network found of wire: %s(%s), netTypes: %v", wire.GetName(), wire.GetId(), netTypes)
}
}
}
+3 -3
View File
@@ -1015,7 +1015,7 @@ func (swire *SWire) GetCandidatePrivateNetwork(ctx context.Context, userCred mcc
func (swire *SWire) GetCandidateAutoAllocNetwork(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, isExit bool, serverTypes []string) (*SNetwork, error) {
nets, err := swire.getAutoAllocNetworks(ctx, userCred, ownerId, scope)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "getAutoAllocNetworks with scope %s", scope)
}
return ChooseCandidateNetworks(nets, isExit, serverTypes), nil
}
@@ -1023,11 +1023,11 @@ func (swire *SWire) GetCandidateAutoAllocNetwork(ctx context.Context, userCred m
func (swire *SWire) GetCandidateNetworkForIp(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, ipAddr string) (*SNetwork, error) {
ip, err := netutils.NewIPV4Addr(ipAddr)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "netutils.NewIPV4Addr: %s", ipAddr)
}
netPrivates, err := swire.getPrivateNetworks(ctx, userCred, ownerId, scope)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "swire.getPrivateNetworks %s", swire.GetId())
}
for _, net := range netPrivates {
if net.IsAddressInRange(ip) {
+1 -1
View File
@@ -1847,7 +1847,7 @@ func (h *SHostInfo) doUploadNicInfoInternal(ifname, mac string, vlanId int, wire
}
res, err := modules.Hosts.PerformAction(h.GetSession(), h.HostId, "add-netif", content)
if err != nil {
return nil, errors.Wrap(err, "modules.Hosts.PerformAction add-netif")
return nil, errors.Wrapf(err, "modules.Hosts.PerformAction add-netif: %s", content.String())
}
return json2HostDetails(res)