Merge release branch 4.20 to main

* 4.20:
  Rollback of changes with errors during the VM assign (#7061)
  [VMware] Consider CD/DVD drive when calculating next free unit number for volume attachment over IDE controller (#9644)
  consider a valid ipv4 address as a validish ipv4 /32 cidr (#10174)
This commit is contained in:
Daan Hoogland 2025-01-15 17:52:07 +01:00
commit 0c13ded943
7 changed files with 2260 additions and 515 deletions

View File

@ -469,7 +469,7 @@ public interface UserVmService {
VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException, VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException,
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
UserVm moveVMToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException, UserVm moveVmToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException; InsufficientCapacityException;
VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool); VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);

View File

@ -120,27 +120,16 @@ public class AssignVMCmd extends BaseCmd {
@Override @Override
public void execute() { public void execute() {
try { try {
UserVm userVm = _userVmService.moveVMToUser(this); UserVm userVm = _userVmService.moveVmToUser(this);
if (userVm == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
}
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0); UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());
setResponseObject(response); setResponseObject(response);
} catch (InvalidParameterValueException e){
e.printStackTrace();
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to move vm due to: " + e.getStackTrace()); ApiErrorCode errorCode = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
if (e.getMessage() != null) { String msg = String.format("Failed to move VM [%s].", getVmId());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage()); logger.error(msg, e);
} else if (e.getCause() != null) { throw new ServerApiException(errorCode, msg);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
}
} }
} }
@Override @Override

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -477,7 +477,7 @@ public class UserVmManagerTest {
CallContext.register(user, caller); CallContext.register(user, caller);
try { try {
_userVmMgr.moveVMToUser(cmd); _userVmMgr.moveVmToUser(cmd);
} finally { } finally {
CallContext.unregister(); CallContext.unregister();
} }
@ -527,7 +527,7 @@ public class UserVmManagerTest {
when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true); when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true);
try { try {
_userVmMgr.moveVMToUser(cmd); _userVmMgr.moveVmToUser(cmd);
} finally { } finally {
CallContext.unregister(); CallContext.unregister();
} }

View File

@ -400,10 +400,13 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
} }
String[] cidrs = _allowedInternalSites.split(","); String[] cidrs = _allowedInternalSites.split(",");
for (String cidr : cidrs) { for (String cidr : cidrs) {
if (NetUtils.isValidIp4Cidr(cidr) || NetUtils.isValidIp4(cidr) || !cidr.startsWith("0.0.0.0")) { if (NetUtils.isValidIp4Cidr(cidr) && !cidr.startsWith("0.0.0.0")) {
if (NetUtils.getCleanIp4Cidr(cidr).equals(cidr)) { if (! NetUtils.getCleanIp4Cidr(cidr).equals(cidr)) {
logger.warn(String.format("Invalid CIDR %s in %s", cidr, SecStorageAllowedInternalDownloadSites.key())); logger.warn("Invalid CIDR {} in {}", cidr, SecStorageAllowedInternalDownloadSites.key());
} }
allowedCidrs.add(NetUtils.getCleanIp4Cidr(cidr));
} else if (NetUtils.isValidIp4(cidr) && !cidr.startsWith("0.0.0.0")) {
logger.warn("Ip address is not a valid CIDR; {} consider using {}/32", cidr, cidr);
allowedCidrs.add(cidr); allowedCidrs.add(cidr);
} }
} }

View File

@ -3168,9 +3168,12 @@ public class VirtualMachineMO extends BaseMO {
int deviceCount = 0; int deviceCount = 0;
int ideDeviceUnitNumber = -1; int ideDeviceUnitNumber = -1;
if (devices != null && devices.size() > 0) { if (devices != null) {
for (VirtualDevice device : devices) { for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk && (controllerKey == device.getControllerKey())) { if (device.getControllerKey() == null || device.getControllerKey() != controllerKey) {
continue;
}
if (device instanceof VirtualDisk || device instanceof VirtualCdrom) {
deviceCount++; deviceCount++;
ideDeviceUnitNumber = device.getUnitNumber(); ideDeviceUnitNumber = device.getUnitNumber();
} }