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:
Yousong Zhou
2021-03-22 19:34:01 +08:00
parent 1d19289ccb
commit 90fd8c868f
4 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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