Make sure other than user VMs can have multiple NICs in a network (#5896)

* only check user VMs

* Update engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Co-authored-by: Daan Hoogland <dahn@onecht.net>
Co-authored-by: Wei Zhou <weizhou@apache.org>
This commit is contained in:
dahn 2022-01-31 14:35:27 +01:00 committed by GitHub
parent c1bba2a308
commit fde34df560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4043,7 +4043,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
/**
* duplicated in {@see UserVmManagerImpl} for a {@see UserVmVO}
*/
private void checkIfNetworkExistsForVM(VirtualMachine virtualMachine, Network network) {
private void checkIfNetworkExistsForUserVM(VirtualMachine virtualMachine, Network network) {
if (virtualMachine.getType() != VirtualMachine.Type.User) {
return; // others may have multiple nics in the same network
}
List<NicVO> allNics = _nicsDao.listByVmId(virtualMachine.getId());
for (NicVO nic : allNics) {
if (nic.getNetworkId() == network.getId()) {
@ -4056,7 +4059,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
InsufficientCapacityException {
final CallContext cctx = CallContext.current();
checkIfNetworkExistsForVM(vm, network);
checkIfNetworkExistsForUserVM(vm, network);
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
final VMInstanceVO vmVO = _vmDao.findById(vm.getId());
final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount());