mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #10474 from yousong/bugfix/yousong-guestnic
Bugfix/yousong guestnic
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 {
|
||||
@@ -2702,12 +2702,26 @@ func (self *SGuest) getAttach2NetworkCount(net *SNetwork) (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SGuest) getMaxNicIndex() int8 {
|
||||
func (self *SGuest) getUsableNicIndex() int8 {
|
||||
nics, err := self.GetNetworks("")
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
return int8(len(nics))
|
||||
maxIndex := int8(len(nics))
|
||||
for i := int8(0); i <= maxIndex; i++ {
|
||||
found := true
|
||||
for j := range nics {
|
||||
if nics[j].Index == i {
|
||||
found = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
return i
|
||||
}
|
||||
}
|
||||
panic(fmt.Sprintf("cannot find usable nic index for guest %s(%s)",
|
||||
self.Name, self.Id))
|
||||
}
|
||||
|
||||
func (self *SGuest) setOSProfile(ctx context.Context, userCred mcclient.TokenCredential, profile jsonutils.JSONObject) error {
|
||||
@@ -2848,7 +2862,7 @@ func (self *SGuest) attach2NetworkOnce(
|
||||
nicDriver = args.nicDriver
|
||||
)
|
||||
if index < 0 {
|
||||
index = self.getMaxNicIndex()
|
||||
index = self.getUsableNicIndex()
|
||||
}
|
||||
if nicDriver == "" {
|
||||
osProf := self.GetOSProfile()
|
||||
|
||||
@@ -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