|
34 | 34 | import javax.naming.ConfigurationException; |
35 | 35 |
|
36 | 36 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
| 37 | +import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; |
37 | 38 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
38 | 39 | import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao; |
39 | 40 | import org.apache.commons.codec.binary.Base64; |
@@ -990,33 +991,43 @@ public Integer getNetworkRate(long networkId, Long vmId) { |
990 | 991 | if (vmId != null) { |
991 | 992 | vm = _vmDao.findById(vmId); |
992 | 993 | } |
993 | | - Network network = getNetwork(networkId); |
994 | | - NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); |
995 | | - |
996 | | - // For default userVm Default network and domR guest/public network, get rate information from the service |
997 | | - // offering; for other situations get information |
998 | | - // from the network offering |
999 | | - boolean isUserVmsDefaultNetwork = false; |
1000 | | - boolean isDomRGuestOrPublicNetwork = false; |
1001 | | - boolean isSystemVmNetwork = false; |
| 994 | + final Network network = getNetwork(networkId); |
| 995 | + final NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); |
| 996 | + |
| 997 | + // For user VM: For default nic use network rate from the service/compute offering, |
| 998 | + // or on NULL from vm.network.throttling.rate global setting |
| 999 | + // For router: Get network rate for guest and public networks from the guest network offering |
| 1000 | + // or on NULL from network.throttling.rate |
| 1001 | + // For others: Use network rate from their network offering, |
| 1002 | + // or on NULL from network.throttling.rate setting at zone > global level |
| 1003 | + // http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/service_offerings.html#network-throttling |
1002 | 1004 | if (vm != null) { |
1003 | | - Nic nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vmId); |
1004 | | - if (vm.getType() == Type.User && nic != null && nic.isDefaultNic()) { |
1005 | | - isUserVmsDefaultNetwork = true; |
1006 | | - } else if (vm.getType() == Type.DomainRouter && ntwkOff != null && |
1007 | | - (ntwkOff.getTrafficType() == TrafficType.Public || ntwkOff.getTrafficType() == TrafficType.Guest)) { |
1008 | | - isDomRGuestOrPublicNetwork = true; |
1009 | | - } else if (vm.getType() == Type.ConsoleProxy || vm.getType() == Type.SecondaryStorageVm) { |
1010 | | - isSystemVmNetwork = true; |
1011 | | - } |
1012 | | - } |
1013 | | - if (isUserVmsDefaultNetwork || isDomRGuestOrPublicNetwork) { |
1014 | | - return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId(), network.getDataCenterId()); |
1015 | | - } else if (isSystemVmNetwork) { |
1016 | | - return -1; |
1017 | | - } else { |
| 1005 | + if (vm.getType() == Type.User) { |
| 1006 | + final Nic nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vmId); |
| 1007 | + if (nic != null && nic.isDefaultNic()) { |
| 1008 | + return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId(), network.getDataCenterId()); |
| 1009 | + } |
| 1010 | + } |
| 1011 | + if (vm.getType() == Type.DomainRouter && (network.getTrafficType() == TrafficType.Public || network.getTrafficType() == TrafficType.Guest)) { |
| 1012 | + for (final Nic nic: _nicDao.listByVmId(vmId)) { |
| 1013 | + final NetworkVO nw = _networksDao.findById(nic.getNetworkId()); |
| 1014 | + if (nw.getTrafficType() == TrafficType.Guest) { |
| 1015 | + return _configMgr.getNetworkOfferingNetworkRate(nw.getNetworkOfferingId(), network.getDataCenterId()); |
| 1016 | + } |
| 1017 | + } |
| 1018 | + } |
| 1019 | + if (vm.getType() == Type.ConsoleProxy || vm.getType() == Type.SecondaryStorageVm) { |
| 1020 | + return -1; |
| 1021 | + } |
| 1022 | + } |
| 1023 | + if (ntwkOff != null) { |
1018 | 1024 | return _configMgr.getNetworkOfferingNetworkRate(ntwkOff.getId(), network.getDataCenterId()); |
1019 | 1025 | } |
| 1026 | + final Integer networkRate = NetworkOrchestrationService.NetworkThrottlingRate.valueIn(network.getDataCenterId()); |
| 1027 | + if (networkRate != null && networkRate > 0) { |
| 1028 | + return networkRate; |
| 1029 | + } |
| 1030 | + return -1; |
1020 | 1031 | } |
1021 | 1032 |
|
1022 | 1033 | @Override |
|
0 commit comments