diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 132d5eaa37d..71f173aa2d6 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3446,11 +3446,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager txn.commit(); + VMInstanceVO vmoi = _itMgr.findByIdAndType(vm.getType(), vm.getId()); + VirtualMachineProfileImpl vmOldProfile = new VirtualMachineProfileImpl(vmoi); + // OS 3: update the network List networkIdList = cmd.getNetworkIds(); List securityGroupIdList = cmd.getSecurityGroupIdList(); if (zone.getNetworkType() == NetworkType.Basic) { + //cleanup the network for the oldOwner + _networkMgr.cleanupNics(vmOldProfile); + _networkMgr.expungeNics(vmOldProfile); //cleanup the old security groups _securityGroupMgr.removeInstanceFromGroups(cmd.getVmId()); //security groups will be recreated for the new account, when the VM is started @@ -3516,9 +3522,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) { throw new InvalidParameterValueException("Can't move vm with security groups; security group feature is not enabled in this zone"); } - VMInstanceVO vmoi = _itMgr.findByIdAndType(vm.getType(), vm.getId()); - VirtualMachineProfileImpl vmOldProfile = new VirtualMachineProfileImpl(vmoi); - //cleanup the network for the oldOwner _networkMgr.cleanupNics(vmOldProfile); _networkMgr.expungeNics(vmOldProfile);