fix(region): raise GetNamedNetworkConfiguration error

This commit is contained in:
Zexi Li
2021-07-28 17:23:29 +08:00
parent 705d7a0076
commit cc5bc646bf
5 changed files with 26 additions and 19 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ type IGuestDriver interface {
PrepareDiskRaidConfig(userCred mcclient.TokenCredential, host *SHost, params []*api.BaremetalDiskConfig, disks []*api.DiskConfig) ([]*api.DiskConfig, error)
GetNamedNetworkConfiguration(guest *SGuest, ctx context.Context, userCred mcclient.TokenCredential, host *SHost, netConfig *api.NetworkConfig) (*SNetwork, []SNicConfig, api.IPAllocationDirection, bool)
GetNamedNetworkConfiguration(guest *SGuest, ctx context.Context, userCred mcclient.TokenCredential, host *SHost, netConfig *api.NetworkConfig) (*SNetwork, []SNicConfig, api.IPAllocationDirection, bool, error)
Attach2RandomNetwork(guest *SGuest, ctx context.Context, userCred mcclient.TokenCredential, host *SHost, netConfig *api.NetworkConfig, pendingUsage quotas.IQuota) ([]SGuestnetwork, error)
GetRandomNetworkTypes() []string
+5 -3
View File
@@ -3481,7 +3481,10 @@ func (self *SGuest) attach2NetworkDesc(
func (self *SGuest) attach2NamedNetworkDesc(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, netConfig *api.NetworkConfig, pendingUsage quotas.IQuota) ([]SGuestnetwork, error) {
driver := self.GetDriver()
net, nicConfs, allocDir, reuseAddr := driver.GetNamedNetworkConfiguration(self, ctx, userCred, host, netConfig)
net, nicConfs, allocDir, reuseAddr, err := driver.GetNamedNetworkConfiguration(self, ctx, userCred, host, netConfig)
if err != nil {
return nil, errors.Wrapf(err, "GetNamedNetworkConfiguration on host %q", host.GetName())
}
if net != nil {
if len(nicConfs) == 0 {
return nil, fmt.Errorf("no avaialble network interface?")
@@ -3500,8 +3503,7 @@ func (self *SGuest) attach2NamedNetworkDesc(ctx context.Context, userCred mcclie
NicConfs: nicConfs,
})
if err != nil {
log.Errorf("Attach2Network fail %s", err)
return nil, err
return nil, errors.Wrap(err, "Attach2Network fail")
} else {
return gn, nil
}
+6 -6
View File
@@ -2453,18 +2453,18 @@ func (self *SHost) getNetworkOfIPOnHost(ipAddr string) (*SNetwork, error) {
return nil, fmt.Errorf("IP %s not reachable on this host", ipAddr)
}
func (self *SHost) GetNetinterfacesWithIdAndCredential(netId string, userCred mcclient.TokenCredential, reserved bool) ([]SNetInterface, *SNetwork) {
func (self *SHost) GetNetinterfacesWithIdAndCredential(netId string, userCred mcclient.TokenCredential, reserved bool) ([]SNetInterface, *SNetwork, error) {
netObj, err := NetworkManager.FetchById(netId)
if err != nil {
return nil, nil
return nil, nil, errors.Wrapf(err, "fetch by id %q", netId)
}
net := netObj.(*SNetwork)
used, err := net.getFreeAddressCount()
if err != nil {
return nil, nil
return nil, nil, errors.Wrapf(err, "get network %q free address count", net.GetName())
}
if used == 0 && !reserved && !options.Options.BaremetalServerReuseHostIp {
return nil, nil
return nil, nil, errors.Errorf("network %q out of usage", net.GetName())
}
matchNetIfs := make([]SNetInterface, 0)
netifs := self.GetNetInterfaces()
@@ -2478,9 +2478,9 @@ func (self *SHost) GetNetinterfacesWithIdAndCredential(netId string, userCred mc
}
}
if len(matchNetIfs) > 0 {
return matchNetIfs, net
return matchNetIfs, net, nil
}
return nil, nil
return nil, nil, errors.Errorf("not found matched netinterface by net %q wire %q", net.GetName(), net.WireId)
}
func (self *SHost) GetNetworkWithId(netId string, reserved bool) (*SNetwork, error) {