Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/vm/Nic.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,7 @@ public enum ReservationStrategy {

Integer getMtu();

Integer getNetworkRate();

boolean isEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ public class ApiConstants {
public static final String NETSCALER_CONTROLCENTER_ID = "netscalercontrolcenterid";
public static final String NETSCALER_SERVICEPACKAGE_ID = "netscalerservicepackageid";
public static final String FETCH_ROUTER_HEALTH_CHECK_RESULTS = "fetchhealthcheckresults";
public static final String UNLIMITED = "unlimited";

public static final String ZONE_ID_LIST = "zoneids";
public static final String DESTINATION_ZONE_ID_LIST = "destzoneids";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
@Param(description = "MTU configured on the network VR's private interfaces")
private Integer privateMtu;

@SerializedName(ApiConstants.NETWORKRATE)
@Param(description = "Network rate (in Mb/s) configured for the Guest interface of this network", since = "4.24.0")
private String networkRate;

@SerializedName(ApiConstants.IP6_DNS1)
@Param(description = "The first IPv6 DNS for the network", since = "4.18.0")
private String ipv6Dns1;
Expand Down Expand Up @@ -707,6 +711,14 @@ public void setPrivateMtu(Integer privateMtu) {
this.privateMtu = privateMtu;
}

public String getNetworkRate() {
return networkRate;
}

public void setNetworkRate(String networkRate) {
this.networkRate = networkRate;
}

public void setIpv6Dns1(String ipv6Dns1) {
this.ipv6Dns1 = ipv6Dns1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public class NicResponse extends BaseResponse {
@Param(description = "MTU configured on the NIC", since="4.18.0")
private Integer mtu;

@SerializedName(ApiConstants.NETWORKRATE)
@Param(description = "Network rate (in Mb/s) configured for the NIC; absent if unlimited", since = "4.24.0")
private Integer networkRate;

@SerializedName(ApiConstants.PUBLIC_IP_ID)
@Param(description = "Public IP address ID associated with this NIC via Static NAT rule")
private String publicIpId;
Expand Down Expand Up @@ -413,6 +417,14 @@ public void setMtu(Integer mtu) {
this.mtu = mtu;
}

public Integer getNetworkRate() {
return networkRate;
}

public void setNetworkRate(Integer networkRate) {
this.networkRate = networkRate;
}

public String getVpcId() {
return vpcId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,12 @@ private void updateRouterIpInNetworkDetails(Long networkId, String routerIp, Str
}
}

private void saveNetworkRateInDetails(long networkId, NetworkOffering offering, long dataCenterId) {
Integer rate = _configMgr.getNetworkOfferingNetworkRate(offering.getId(), dataCenterId);
String networkRate = (rate == null || rate <= 0) ? ApiConstants.UNLIMITED : String.valueOf(rate);
networkDetailsDao.addDetail(networkId, ApiConstants.NETWORKRATE, networkRate, true);
}

@Override
public List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final DeploymentPlan plan, final String name, final String displayText, final boolean isDefault)
throws ConcurrentOperationException {
Expand Down Expand Up @@ -852,6 +858,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
}

updateRouterIpInNetworkDetails(networkPersisted.getId(), network.getRouterIp(), network.getRouterIpv6());
saveNetworkRateInDetails(networkPersisted.getId(), offering, plan.getDataCenterId());

if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions) {
final NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru;
Expand Down Expand Up @@ -1227,14 +1234,15 @@ public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final N
NicVO vo = checkForRaceAndAllocateNic(requested, network, isDefaultNic, deviceId, vm);

final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
vo.setNetworkRate(networkRate != null && networkRate > 0 ? networkRate : null);
final NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
_networkModel.getNetworkTag(vm.getHypervisorType(), network));
if (vm.getType() == Type.DomainRouter) {
Pair<NetworkVO, VpcVO> networks = getGuestNetworkRouterAndVpcDetails(vm.getId());
setMtuDetailsInVRNic(networks, network, vo);
_nicDao.update(vo.getId(), vo);
setMtuInVRNicProfile(networks, network.getTrafficType(), vmNic);
}
_nicDao.update(vo.getId(), vo);
return new Pair<>(vmNic, Integer.valueOf(deviceId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import com.cloud.upgrade.dao.Upgrade420to421;
import com.cloud.upgrade.dao.Upgrade421to430;
import com.cloud.upgrade.dao.Upgrade42210to42300;
import com.cloud.upgrade.dao.Upgrade42300to42400;
import com.cloud.upgrade.dao.Upgrade430to440;
import com.cloud.upgrade.dao.Upgrade431to440;
import com.cloud.upgrade.dao.Upgrade432to440;
Expand Down Expand Up @@ -248,6 +249,7 @@ public DatabaseUpgradeChecker() {
.next("4.21.0.0", new Upgrade42100to42200())
.next("4.22.0.0", new Upgrade42200to42210())
.next("4.22.1.0", new Upgrade42210to42300())
.next("4.23.0.0", new Upgrade42300to42400())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.upgrade.dao;

import java.io.InputStream;
import java.sql.Connection;

import com.cloud.utils.exception.CloudRuntimeException;

public class Upgrade42300to42400 extends DbUpgradeAbstractImpl implements DbUpgrade {

@Override
public String[] getUpgradableVersionRange() {
return new String[]{"4.23.0.0", "4.24.0.0"};
}

@Override
public String getUpgradedVersion() {
return "4.24.0.0";
}

@Override
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-42300to42400.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
return new InputStream[]{script};
}

@Override
public void performDataMigration(Connection conn) {
}

@Override
public InputStream[] getCleanupScripts() {
return null;
}
}
11 changes: 11 additions & 0 deletions engine/schema/src/main/java/com/cloud/vm/NicVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ protected NicVO() {
@Column(name = "mtu")
Integer mtu;

@Column(name = "network_rate")
Integer networkRate;

@Column(name = "enabled")
boolean enabled;

Expand Down Expand Up @@ -426,4 +429,12 @@ public Integer getMtu() {
public void setMtu(Integer mtu) {
this.mtu = mtu;
}

public Integer getNetworkRate() {
return networkRate;
}

public void setNetworkRate(Integer networkRate) {
this.networkRate = networkRate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

-- Schema upgrade from 4.23.0.0 to 4.24.0.0

ALTER TABLE `cloud`.`nics` ADD COLUMN `network_rate` int unsigned DEFAULT NULL COMMENT 'effective network rate in Mb/s for this NIC';
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ SELECT
`nics`.`broadcast_uri` AS `broadcast_uri`,
`nics`.`isolation_uri` AS `isolation_uri`,
`nics`.`enabled` AS `is_nic_enabled`,
`nics`.`network_rate` AS `nic_network_rate`,
`nic_details`.`value` AS `nic_dns_name`,
`vpc`.`id` AS `vpc_id`,
`vpc`.`uuid` AS `vpc_uuid`,
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/cloud/api/ApiDBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.InstanceGroup;
import com.cloud.vm.InstanceGroupVO;
import com.cloud.vm.NicDetailVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.VMInstanceDetailVO;
Expand All @@ -356,6 +357,7 @@
import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.NicDetailsDao;
import com.cloud.vm.dao.NicSecondaryIpDao;
import com.cloud.vm.dao.NicSecondaryIpVO;
import com.cloud.vm.dao.UserVmDao;
Expand Down Expand Up @@ -502,6 +504,7 @@ public class ApiDBUtils {
static BackupOfferingDao s_backupOfferingDao;
static BackupRepositoryDao s_backupRepositoryDao;
static NicDao s_nicDao;
static NicDetailsDao s_nicDetailsDao;
static ResourceManagerUtil s_resourceManagerUtil;
static ApiKeyPairDao s_apiKeyPairDao;
static SnapshotPolicyDetailsDao s_snapshotPolicyDetailsDao;
Expand Down Expand Up @@ -768,6 +771,8 @@ public class ApiDBUtils {
@Inject
private NicDao nicDao;
@Inject
private NicDetailsDao nicDetailsDao;
@Inject
private ResourceIconDao resourceIconDao;
@Inject
private ResourceManagerUtil resourceManagerUtil;
Expand Down Expand Up @@ -902,6 +907,7 @@ void init() {
s_clusterDetailsDao = clusterDetailsDao;
s_vmSnapshotDao = vmSnapshotDao;
s_nicDao = nicDao;
s_nicDetailsDao = nicDetailsDao;
s_nicSecondaryIpDao = nicSecondaryIpDao;
s_vpcProvSvc = vpcProvSvc;
s_affinityGroupDao = affinityGroupDao;
Expand Down Expand Up @@ -2250,6 +2256,10 @@ public static NicVO findNicById(long nicId) {
return s_nicDao.findById(nicId);
}

public static NicDetailVO findNicDetailByName(long nicId, String detailName) {
return s_nicDetailsDao.findDetail(nicId, detailName);
}

public static TemplateResponse newTemplateUpdateResponse(TemplateJoinVO vr) {
return s_templateJoinDao.newUpdateResponse(vr);
}
Expand Down
7 changes: 7 additions & 0 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,10 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
response.setNetworkDomain(network.getNetworkDomain());
response.setPublicMtu(network.getPublicMtu());
response.setPrivateMtu(network.getPrivateMtu());
NetworkDetailVO networkRateDetail = networkDetailsDao.findDetail(network.getId(), ApiConstants.NETWORKRATE);
if (networkRateDetail != null) {
response.setNetworkRate(networkRateDetail.getValue());
}
response.setDns1(profile.getDns1());
response.setDns2(profile.getDns2());
response.setIpv6Dns1(profile.getIp6Dns1());
Expand Down Expand Up @@ -4904,6 +4908,9 @@ public NicResponse createNicResponse(Nic result) {
}

response.setEnabled(result.isEnabled());

response.setNetworkRate(result.getNetworkRate());

return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
.collect(Collectors.toList());
nicResponse.setExtraDhcpOptions(nicExtraDhcpOptionResponses);

nicResponse.setNetworkRate(userVm.getNicNetworkRate());
userVmResponse.addNic(nicResponse);
}
}
Expand Down Expand Up @@ -744,6 +745,8 @@ public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVm
.map(vo -> new NicExtraDhcpOptionResponse(Dhcp.DhcpOptionCode.valueOfInt(vo.getCode()).getName(), vo.getCode(), vo.getValue()))
.collect(Collectors.toList());
nicResponse.setExtraDhcpOptions(nicExtraDhcpOptionResponses);

nicResponse.setNetworkRate(uvo.getNicNetworkRate());
userVmData.addNic(nicResponse);
}

Expand Down
7 changes: 7 additions & 0 deletions server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
@Column(name = "is_nic_enabled")
private boolean isNicEnabled;

@Column(name = "nic_network_rate")
private Integer nicNetworkRate;

@Column(name = "ip_address")
private String ipAddress;

Expand Down Expand Up @@ -1115,6 +1118,10 @@ public boolean isNicEnabled() {
return isNicEnabled;
}

public Integer getNicNetworkRate() {
return nicNetworkRate;
}

public String getNicDnsName() {
return nicDnsName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3604,6 +3604,9 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString, networkOfferingId,
null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
}
Integer rate = _configMgr.getNetworkOfferingNetworkRate(networkOfferingId, network.getDataCenterId());
String networkRate = (rate == null || rate <= 0) ? ApiConstants.UNLIMITED : String.valueOf(rate);
_networkDetailsDao.addDetail(networkId, ApiConstants.NETWORKRATE, networkRate, true);
}
});
} else {
Expand Down
14 changes: 13 additions & 1 deletion server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,15 @@ public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterV
return _vmDao.findById(vmInstance.getId());
}

private void refreshNicNetworkRates(long vmId) {
List<NicVO> nics = _nicDao.listByVmId(vmId);
for (NicVO nic : nics) {
Integer rate = _networkModel.getNetworkRate(nic.getNetworkId(), vmId);
nic.setNetworkRate(rate != null && rate > 0 ? rate : null);
_nicDao.update(nic.getId(), nic);
}
}

private void validateVmZoneTypeForAddNic(UserVmVO vmInstance, DataCenter dc) {
if (!NetworkType.Basic.equals(dc.getNetworkType())) {
return;
Expand Down Expand Up @@ -3578,7 +3587,10 @@ public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, Con
additonalParams.put(VirtualMachineProfile.Param.ConsiderLastHost, cmd.getConsiderLastHost().toString());
}

return startVirtualMachine(cmd.getId(), cmd.getPodId(), cmd.getClusterId(), cmd.getHostId(), additonalParams, cmd.getDeploymentPlanner(), false).first();
UserVm vm = startVirtualMachine(cmd.getId(), cmd.getPodId(), cmd.getClusterId(), cmd.getHostId(), additonalParams, cmd.getDeploymentPlanner(), false).first();
// Refresh nic_details with current network rates — the network offering may have changed since the VM was last running
refreshNicNetworkRates(vm.getId());
return vm;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion ui/src/config/section/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
const fields = ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'asnumber',
'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'egressdefaultpolicy', 'zonename',
'account', 'domainpath', 'associatednetwork', 'associatednetworkid', 'ip4routing', 'ip6firewall', 'ip6routing', 'ip6routes',
'dns1', 'dns2', 'ip6dns1', 'ip6dns2', 'publicmtu', 'privatemtu', 'dnszone', 'dnssubdomain']
'dns1', 'dns2', 'ip6dns1', 'ip6dns2', 'publicmtu', 'privatemtu', 'networkrate', 'dnszone', 'dnssubdomain']
if (isAdmin()) {
const vlanIndex = fields.findIndex(detail => detail === 'vlan')
fields.splice(vlanIndex + 1, 0, 'broadcasturi')
Expand Down
4 changes: 2 additions & 2 deletions ui/src/config/section/offering.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export default {
}
return []
},
columns: ['name', 'displaytext', 'state', 'cpunumber', 'cpuspeed', 'memory', 'gpu', 'domain', 'zone', 'order'],
columns: ['name', 'displaytext', 'state', 'cpunumber', 'cpuspeed', 'memory', 'gpu', 'domain', 'zone', 'order', 'networkrate'],
details: () => {
var fields = ['name', 'id', 'displaytext', 'offerha', 'provisioningtype', 'storagetype', 'iscustomized', 'iscustomizediops', 'limitcpuuse', 'cpunumber', 'cpuspeed', 'memory', 'hosttags', 'tags', 'storageaccessgroups', 'storagetags', 'domain', 'zone', 'created', 'dynamicscalingenabled', 'diskofferingstrictness', 'encryptroot', 'purgeresources', 'leaseduration', 'gpucardid', 'gpucardname', 'vgpuprofileid', 'vgpuprofilename', 'gpucount', 'gpudisplay', 'leaseexpiryaction', 'externaldetails']
var fields = ['name', 'id', 'displaytext', 'offerha', 'provisioningtype', 'storagetype', 'iscustomized', 'iscustomizediops', 'limitcpuuse', 'cpunumber', 'cpuspeed', 'memory', 'hosttags', 'tags', 'storageaccessgroups', 'storagetags', 'domain', 'zone', 'created', 'dynamicscalingenabled', 'diskofferingstrictness', 'encryptroot', 'purgeresources', 'leaseduration', 'gpucardid', 'gpucardname', 'vgpuprofileid', 'vgpuprofilename', 'gpucount', 'gpudisplay', 'leaseexpiryaction', 'externaldetails', 'networkrate']
if (store.getters.apis.createServiceOffering &&
store.getters.apis.createServiceOffering.params.filter(x => x.name === 'storagepolicy').length > 0) {
fields.splice(6, 0, 'vspherestoragepolicy')
Expand Down
Loading
Loading