mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
region: attachnetwork: allow attach by network name
isValidNetworkInfo allows names. Otherwise the code will panic when a named was passed and nil was returned by the fetch call
This commit is contained in:
@@ -2259,7 +2259,7 @@ func (self *SGuest) PerformAttachnetwork(ctx context.Context, userCred mcclient.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if IsExitNetworkInfo(input.Nets[i]) {
|
||||
if IsExitNetworkInfo(userCred, input.Nets[i]) {
|
||||
enicCnt = count
|
||||
// ebw = input.BwLimit
|
||||
} else {
|
||||
|
||||
@@ -1753,7 +1753,7 @@ func getGuestResourceRequirements(
|
||||
eBw := 0
|
||||
iBw := 0
|
||||
for _, netConfig := range input.Networks {
|
||||
if IsExitNetworkInfo(netConfig) {
|
||||
if IsExitNetworkInfo(userCred, netConfig) {
|
||||
eNicCnt += 1
|
||||
eBw += netConfig.BwLimit
|
||||
} else {
|
||||
|
||||
@@ -1052,9 +1052,9 @@ func isValidNetworkInfo(userCred mcclient.TokenCredential, netConfig *api.Networ
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsExitNetworkInfo(netConfig *api.NetworkConfig) bool {
|
||||
func IsExitNetworkInfo(userCred mcclient.TokenCredential, netConfig *api.NetworkConfig) bool {
|
||||
if len(netConfig.Network) > 0 {
|
||||
netObj, _ := NetworkManager.FetchById(netConfig.Network)
|
||||
netObj, _ := NetworkManager.FetchByIdOrName(userCred, netConfig.Network)
|
||||
net := netObj.(*SNetwork)
|
||||
if net.IsExitNetwork() {
|
||||
return true
|
||||
|
||||
@@ -59,7 +59,7 @@ func fetchGuestUsageFromSchedInfo(s *api.SchedInfo) (computemodels.SQuota, compu
|
||||
iNicCnt := 0
|
||||
|
||||
for _, netConfig := range s.Networks {
|
||||
if computemodels.IsExitNetworkInfo(netConfig) {
|
||||
if computemodels.IsExitNetworkInfo(s.UserCred, netConfig) {
|
||||
eNicCnt += 1
|
||||
} else {
|
||||
iNicCnt += 1
|
||||
|
||||
Reference in New Issue
Block a user