Skip to content

Commit

Permalink
Merge release branch 4.19 to main
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoJandre committed Sep 19, 2024
2 parents 94a47ac + 075f981 commit 41e7a2a
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private List<String> getRulesForPool(final LoadBalancerTO lbTO, final boolean ke
sb.append("\tbind ").append(publicIP).append(":").append(publicPort);
result.add(sb.toString());
sb = new StringBuilder();
sb.append("\t").append("balance ").append(algorithm);
sb.append("\t").append("balance ").append(algorithm.toLowerCase());
result.add(sb.toString());

int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1973,16 +1973,8 @@ protected void ensureDiskControllers(VirtualMachineMO vmMo, Pair<String, String>
return;
}

String msg;
String rootDiskController = controllerInfo.first();
String dataDiskController = controllerInfo.second();
String scsiDiskController;
String recommendedDiskController = null;

if (VmwareHelper.isControllerOsRecommended(dataDiskController) || VmwareHelper.isControllerOsRecommended(rootDiskController)) {
recommendedDiskController = vmMo.getRecommendedDiskController(null);
}
scsiDiskController = HypervisorHostHelper.getScsiController(new Pair<String, String>(rootDiskController, dataDiskController), recommendedDiskController);
Pair<String, String> chosenDiskControllers = VmwareHelper.chooseRequiredDiskControllers(controllerInfo, vmMo, null, null);
String scsiDiskController = HypervisorHostHelper.getScsiController(chosenDiskControllers);
if (scsiDiskController == null) {
return;
}
Expand Down Expand Up @@ -2335,6 +2327,7 @@ protected StartAnswer execute(StartCommand cmd) {
}

int controllerKey;
Pair<String, String> chosenDiskControllers = VmwareHelper.chooseRequiredDiskControllers(controllerInfo,vmMo, null, null);

//
// Setup ROOT/DATA disk devices
Expand All @@ -2359,10 +2352,7 @@ protected StartAnswer execute(StartCommand cmd) {
}

VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
String diskController = getDiskController(vmMo, matchingExistingDisk, vol, controllerInfo, deployAsIs);
if (DiskControllerType.getType(diskController) == DiskControllerType.osdefault) {
diskController = vmMo.getRecommendedDiskController(null);
}
String diskController = getDiskController(vmMo, matchingExistingDisk, vol, chosenDiskControllers, deployAsIs);
if (DiskControllerType.getType(diskController) == DiskControllerType.ide) {
controllerKey = vmMo.getIDEControllerKey(ideUnitNumber);
if (vol.getType() == Volume.Type.DATADISK) {
Expand Down Expand Up @@ -2846,27 +2836,10 @@ private String getGuestOsIdFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsI
}

private Pair<String, String> getControllerInfoFromVmSpec(VirtualMachineTO vmSpec) throws CloudRuntimeException {
String dataDiskController = vmSpec.getDetails().get(VmDetailConstants.DATA_DISK_CONTROLLER);
String rootDiskController = vmSpec.getDetails().get(VmDetailConstants.ROOT_DISK_CONTROLLER);

// If root disk controller is scsi, then data disk controller would also be scsi instead of using 'osdefault'
// This helps avoid mix of different scsi subtype controllers in instance.
if (DiskControllerType.osdefault == DiskControllerType.getType(dataDiskController) && DiskControllerType.lsilogic == DiskControllerType.getType(rootDiskController)) {
dataDiskController = DiskControllerType.scsi.toString();
}

// Validate the controller types
dataDiskController = DiskControllerType.getType(dataDiskController).toString();
rootDiskController = DiskControllerType.getType(rootDiskController).toString();

if (DiskControllerType.getType(rootDiskController) == DiskControllerType.none) {
throw new CloudRuntimeException("Invalid root disk controller detected : " + rootDiskController);
}
if (DiskControllerType.getType(dataDiskController) == DiskControllerType.none) {
throw new CloudRuntimeException("Invalid data disk controller detected : " + dataDiskController);
}

return new Pair<>(rootDiskController, dataDiskController);
String rootDiskControllerDetail = vmSpec.getDetails().get(VmDetailConstants.ROOT_DISK_CONTROLLER);
String dataDiskControllerDetail = vmSpec.getDetails().get(VmDetailConstants.DATA_DISK_CONTROLLER);
VmwareHelper.validateDiskControllerDetails(rootDiskControllerDetail, dataDiskControllerDetail);
return new Pair<>(rootDiskControllerDetail, dataDiskControllerDetail);
}

private String getBootModeFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs) {
Expand Down Expand Up @@ -3614,15 +3587,7 @@ private String getDiskController(VirtualMachineMO vmMo, VirtualMachineDiskInfo m
return controllerType.toString();
}

if (vol.getType() == Volume.Type.ROOT) {
logger.info("Chose disk controller for vol " + vol.getType() + " -> " + controllerInfo.first()
+ ", based on root disk controller settings at global configuration setting.");
return controllerInfo.first();
} else {
logger.info("Chose disk controller for vol " + vol.getType() + " -> " + controllerInfo.second()
+ ", based on default data disk controller setting i.e. Operating system recommended."); // Need to bring in global configuration setting & template level setting.
return controllerInfo.second();
}
return VmwareHelper.getControllerBasedOnDiskType(controllerInfo, vol);
}

private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO[] sortedDisks, int ideControllerKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2101,15 +2101,18 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean
AttachAnswer answer = new AttachAnswer(disk);

if (isAttach) {
String diskController = getLegacyVmDataDiskController();

String rootDiskControllerDetail = DiskControllerType.ide.toString();
if (controllerInfo != null && StringUtils.isNotEmpty(controllerInfo.get(VmDetailConstants.ROOT_DISK_CONTROLLER))) {
rootDiskControllerDetail = controllerInfo.get(VmDetailConstants.ROOT_DISK_CONTROLLER);
}
String dataDiskControllerDetail = getLegacyVmDataDiskController();
if (controllerInfo != null && StringUtils.isNotEmpty(controllerInfo.get(VmDetailConstants.DATA_DISK_CONTROLLER))) {
diskController = controllerInfo.get(VmDetailConstants.DATA_DISK_CONTROLLER);
dataDiskControllerDetail = controllerInfo.get(VmDetailConstants.DATA_DISK_CONTROLLER);
}

if (DiskControllerType.getType(diskController) == DiskControllerType.osdefault) {
diskController = vmMo.getRecommendedDiskController(null);
}
VmwareHelper.validateDiskControllerDetails(rootDiskControllerDetail, dataDiskControllerDetail);
Pair<String, String> chosenDiskControllers = VmwareHelper.chooseRequiredDiskControllers(new Pair<>(rootDiskControllerDetail, dataDiskControllerDetail), vmMo, null, null);
String diskController = VmwareHelper.getControllerBasedOnDiskType(chosenDiskControllers, disk);

vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs, diskController, storagePolicyId, volumeTO.getIopsReadRate() + volumeTO.getIopsWriteRate());
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
Expand Down
22 changes: 15 additions & 7 deletions server/src/main/java/com/cloud/network/IpAddressManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import com.cloud.network.dao.PublicIpQuarantineDao;
import com.cloud.network.vo.PublicIpQuarantineVO;
import com.cloud.resourcelimit.CheckedReservation;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.annotation.AnnotationService;
Expand All @@ -53,6 +54,7 @@
import org.apache.cloudstack.region.PortableIpDao;
import org.apache.cloudstack.region.PortableIpVO;
import org.apache.cloudstack.region.Region;
import org.apache.cloudstack.reservation.dao.ReservationDao;
import org.apache.commons.collections.CollectionUtils;

import com.cloud.agent.AgentManager;
Expand Down Expand Up @@ -259,6 +261,8 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
@Inject
ResourceLimitService _resourceLimitMgr;

@Inject
ReservationDao reservationDao;
@Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
@Inject
Expand Down Expand Up @@ -1548,21 +1552,25 @@ public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean

logger.debug("Associating ip " + ipToAssoc + " to network " + network);

IPAddressVO ip = _ipAddressDao.findById(ipId);
//update ip address with networkId
ip.setAssociatedWithNetworkId(networkId);
ip.setSourceNat(isSourceNat);
_ipAddressDao.update(ipId, ip);

boolean success = false;
try {
IPAddressVO ip = null;
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) {
ip = _ipAddressDao.findById(ipId);
//update ip address with networkId
ip.setAssociatedWithNetworkId(networkId);
ip.setSourceNat(isSourceNat);
_ipAddressDao.update(ipId, ip);

success = applyIpAssociations(network, false);
if (success) {
logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network);
} else {
logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network);
}
return _ipAddressDao.findById(ipId);
} catch (Exception e) {
s_logger.error(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e);
throw new CloudRuntimeException(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e);
} finally {
if (!success && releaseOnFailure) {
if (ip != null) {
Expand Down
27 changes: 18 additions & 9 deletions server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
import javax.naming.ConfigurationException;

import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.Vlan;
import com.cloud.network.dao.NsxProviderDao;
import com.cloud.network.element.NsxProviderVO;
import com.cloud.configuration.ConfigurationManagerImpl;
import com.cloud.dc.ASNumberVO;
import com.cloud.bgp.BGPService;
import com.cloud.dc.ASNumberVO;
import com.cloud.dc.dao.ASNumberDao;
import com.cloud.dc.Vlan;
import com.cloud.network.dao.NsxProviderDao;
import com.cloud.network.element.NsxProviderVO;
import com.cloud.resourcelimit.CheckedReservation;
import com.google.common.collect.Sets;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.alert.AlertService;
Expand All @@ -75,6 +76,7 @@
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.query.QueryService;
import org.apache.cloudstack.reservation.dao.ReservationDao;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.ObjectUtils;
Expand Down Expand Up @@ -250,6 +252,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Inject
ResourceLimitService _resourceLimitMgr;
@Inject
ReservationDao reservationDao;
@Inject
VpcServiceMapDao _vpcSrvcDao;
@Inject
DataCenterDao _dcDao;
Expand Down Expand Up @@ -3175,9 +3179,10 @@ public IpAddress associateIPToVpc(final long ipId, final long vpcId) throws Reso
logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);

final boolean isSourceNatFinal = isSrcNatIpRequired(vpc.getVpcOfferingId()) && getExistingSourceNatInVpc(vpc.getAccountId(), vpcId, false) == null;
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final IPAddressVO ip = _ipAddressDao.findById(ipId);
// update ip address with networkId
ip.setVpcId(vpcId);
Expand All @@ -3187,8 +3192,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {

// mark ip as allocated
_ipAddrMgr.markPublicIpAsAllocated(ip);
}
});
}
});
} catch (Exception e) {
s_logger.error("Failed to associate ip " + ipToAssoc + " to vpc " + vpc, e);
throw new CloudRuntimeException("Failed to associate ip " + ipToAssoc + " to vpc " + vpc, e);
}

logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
CallContext.current().putContextParameter(IpAddress.class, ipToAssoc.getUuid());
Expand Down
Loading

0 comments on commit 41e7a2a

Please sign in to comment.