Source:
<code>protected void executeVmCommand() { addCustomValue("InterfaceType", VmInterfaceType.forValue(getInterface().getType()).getDescription().toString()); boolean succeeded = false; boolean macAddedToPool = false; String macAddress = getMacAddress(); try { if (isVnicProfileChanged(oldIface, getInterface())) { Network newNetwork = networkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId()); Network oldNetwork = networkHelper.getNetworkByVnicProfileId(oldIface.getVnicProfileId()); if (!Objects.equals(oldNetwork, newNetwork)) { externalNetworkManagerFactory.create(oldIface).deallocateIfExternal(); } } <START> macAddedToPool = macShouldBeChanged && !belongsToOriginalSnapshot(macAddress) && addMacToPool(macAddress); <END> if (mustChangeAddress(oldIface.getType(), getInterface().getType())) { vmDeviceDao.clearDeviceAddress(getInterface().getId()); } getInterface().setSpeed(VmInterfaceType.forValue(getInterface().getType()).getSpeed()); TransactionSupport.executeInNewTransaction(() -> { bumpVmVersion(); updatePassthoughDeviceIfNeeded(); getCompensationContext().snapshotEntity(oldIface); vmNicDao.update(getInterface()); saveNetworkFilterParameters(); getCompensationContext().stateChanged(); return null; }); succeeded = updateHost(); } finally { setSucceeded(succeeded); MacPool macPool = getMacPool(); if (macAddedToPool) { if (succeeded) { String macToRelease = oldIface.getMacAddress(); boolean isRunningStatelessVm = getVm().isStateless() && getVm().isRunning(); boolean canReleaseOriginalMac = !isRunningStatelessVm || !belongsToOriginalSnapshot(macToRelease); if (canReleaseOriginalMac) { macPool.freeMac(macToRelease); } } else { macPool.freeMac(macAddress); } } } }</code><technical_language>if macPool allows duplicates changed a vnic mac another vnic. mac belongs original snapshot, another vnic. added pool. is enough check belongs original snapshot, check if belongs vnic compare count of macs, in SnapshotManager</technical_language>

Target:
protected void executeVmCommand() { addCustomValue("InterfaceType", VmInterfaceType.forValue(getInterface().getType()).getDescription().toString()); boolean succeeded = false; boolean macAddedToPool = false; try { if (isVnicProfileChanged(oldIface, getInterface())) { Network newNetwork = networkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId()); Network oldNetwork = networkHelper.getNetworkByVnicProfileId(oldIface.getVnicProfileId()); if (!Objects.equals(oldNetwork, newNetwork)) { externalNetworkManagerFactory.create(oldIface).deallocateIfExternal(); } } macAddedToPool = allocateMacFromRequest(); if (mustChangeAddress(oldIface.getType(), getInterface().getType())) { vmDeviceDao.clearDeviceAddress(getInterface().getId()); } getInterface().setSpeed(VmInterfaceType.forValue(getInterface().getType()).getSpeed()); succeeded = Boolean.TRUE.equals(TransactionSupport.executeInNewTransaction(() -> { bumpVmVersion(); updatePassthoughDeviceIfNeeded(); getCompensationContext().snapshotEntity(oldIface); vmNicDao.update(getInterface()); saveNetworkFilterParameters(); getCompensationContext().stateChanged(); return true; })); succeeded &= updateHost(); } finally { setSucceeded(succeeded); macPoolCleanupAfterExecution(macAddedToPool); } }