Skip to content

Commit 0c13ded

Browse files
committed
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)
2 parents baad8dd + bf1ff10 commit 0c13ded

File tree

7 files changed

+2214
-469
lines changed

7 files changed

+2214
-469
lines changed

api/src/main/java/com/cloud/vm/UserVmService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) throws Res
469469
VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException,
470470
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
471471

472-
UserVm moveVMToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
472+
UserVm moveVmToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
473473
InsufficientCapacityException;
474474

475475
VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java

+5-16
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,16 @@ public List<Long> getSecurityGroupIdList() {
120120
@Override
121121
public void execute() {
122122
try {
123-
UserVm userVm = _userVmService.moveVMToUser(this);
124-
if (userVm == null) {
125-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
126-
}
123+
UserVm userVm = _userVmService.moveVmToUser(this);
127124
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
128125
response.setResponseName(getCommandName());
129126
setResponseObject(response);
130-
} catch (InvalidParameterValueException e){
131-
e.printStackTrace();
132-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
133127
} catch (Exception e) {
134-
logger.error("Failed to move vm due to: " + e.getStackTrace());
135-
if (e.getMessage() != null) {
136-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
137-
} else if (e.getCause() != null) {
138-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
139-
} else {
140-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
141-
}
128+
ApiErrorCode errorCode = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
129+
String msg = String.format("Failed to move VM [%s].", getVmId());
130+
logger.error(msg, e);
131+
throw new ServerApiException(errorCode, msg);
142132
}
143-
144133
}
145134

146135
@Override

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

+681-426
Large diffs are not rendered by default.

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

+1,514-19
Large diffs are not rendered by default.

server/src/test/java/com/cloud/vm/UserVmManagerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public void testMoveVmToUser1() throws Exception {
477477
CallContext.register(user, caller);
478478
try {
479479

480-
_userVmMgr.moveVMToUser(cmd);
480+
_userVmMgr.moveVmToUser(cmd);
481481
} finally {
482482
CallContext.unregister();
483483
}
@@ -527,7 +527,7 @@ public void testMoveVmToUser2() throws Exception {
527527
when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true);
528528

529529
try {
530-
_userVmMgr.moveVMToUser(cmd);
530+
_userVmMgr.moveVmToUser(cmd);
531531
} finally {
532532
CallContext.unregister();
533533
}

services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,13 @@ private List<String> getAllowedInternalSiteCidrs() {
400400
}
401401
String[] cidrs = _allowedInternalSites.split(",");
402402
for (String cidr : cidrs) {
403-
if (NetUtils.isValidIp4Cidr(cidr) || NetUtils.isValidIp4(cidr) || !cidr.startsWith("0.0.0.0")) {
404-
if (NetUtils.getCleanIp4Cidr(cidr).equals(cidr)) {
405-
logger.warn(String.format("Invalid CIDR %s in %s", cidr, SecStorageAllowedInternalDownloadSites.key()));
403+
if (NetUtils.isValidIp4Cidr(cidr) && !cidr.startsWith("0.0.0.0")) {
404+
if (! NetUtils.getCleanIp4Cidr(cidr).equals(cidr)) {
405+
logger.warn("Invalid CIDR {} in {}", cidr, SecStorageAllowedInternalDownloadSites.key());
406406
}
407+
allowedCidrs.add(NetUtils.getCleanIp4Cidr(cidr));
408+
} else if (NetUtils.isValidIp4(cidr) && !cidr.startsWith("0.0.0.0")) {
409+
logger.warn("Ip address is not a valid CIDR; {} consider using {}/32", cidr, cidr);
407410
allowedCidrs.add(cidr);
408411
}
409412
}

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -3168,9 +3168,12 @@ public int getFreeUnitNumberOnIDEController(int controllerKey) throws Exception
31683168

31693169
int deviceCount = 0;
31703170
int ideDeviceUnitNumber = -1;
3171-
if (devices != null && devices.size() > 0) {
3171+
if (devices != null) {
31723172
for (VirtualDevice device : devices) {
3173-
if (device instanceof VirtualDisk && (controllerKey == device.getControllerKey())) {
3173+
if (device.getControllerKey() == null || device.getControllerKey() != controllerKey) {
3174+
continue;
3175+
}
3176+
if (device instanceof VirtualDisk || device instanceof VirtualCdrom) {
31743177
deviceCount++;
31753178
ideDeviceUnitNumber = device.getUnitNumber();
31763179
}

0 commit comments

Comments
 (0)