Source:
<code>protected void executeVmCommand() { boolean isNicToBePlugged = getParameters().getAction() == PlugAction.PLUG; if (isNicToBePlugged){ clearAddressIfPciSlotIsDuplicated(vmDevice); } if (hotPlugVmNicRequired(getVm().getStatus())) { boolean externalNetworkIsPlugged = isNicToBePlugged && getNetwork() != null && getNetwork().isExternal(); if (externalNetworkIsPlugged) { plugToExternalNetwork(); } String vfToUse = null; try { boolean shouldAcquireVF = isNicToBePlugged && isPassthrough(); if (shouldAcquireVF) { vfToUse = acquireVF(); if (vfToUse == null) { failValidationCannotPlugPassthroughVnicNoSuitableVf(); return; } vmDevice.setHostDevice(vfToUse); } VDSReturnValue returnValue = runVdsCommand(getParameters().getAction().getCommandType(), new VmNicDeviceVDSParameters(getVdsId(), getVm(), getParameters().getNic(), vmDevice)); if (returnValue.getSucceeded()) { <START> boolean passthroughHotPlug = vfToUse != null; END> boolean passthroughHotUnplug = isPassthrough() && getParameters().getAction() == PlugAction.UNPLUG; if (passthroughHotUnplug) { networkDeviceHelper.setVmIdOnVfs(getVdsId(), null, new HashSet<>(Arrays.asList(vmDevice.getHostDevice()))); } if (passthroughHotPlug || passthroughHotUnplug) { runInternalAction(VdcActionType.RefreshHost, new VdsActionParameters(getVdsId())); } } else { clearPassthroughData(vfToUse); } } catch (EngineException e) { if (externalNetworkIsPlugged && getParameters().isNewNic()) { unplugFromExternalNetwork(); } clearPassthroughData(vfToUse); throw e; } } TransactionSupport.executeInNewTransaction(updateDevice()); setSucceeded(true); }</code><technical_language>Logically correct, readable. rename shouldAcquireVF => passthroughHotUnplug skip variable? Additionally if extract a method out of acquiring visible acquire a VF for passthroughHotPlug</technical_language>

Target:
protected void executeVmCommand() { boolean isNicToBePlugged = getParameters().getAction() == PlugAction.PLUG; if (isNicToBePlugged){ clearAddressIfPciSlotIsDuplicated(vmDevice); } if (hotPlugVmNicRequired(getVm().getStatus())) { boolean externalNetworkIsPlugged = isNicToBePlugged && getNetwork() != null && getNetwork().isExternal(); if (externalNetworkIsPlugged) { plugToExternalNetwork(); } String vfToUse = null; try { boolean shouldAcquireVF = isNicToBePlugged && isPassthrough(); if (shouldAcquireVF) { vfToUse = acquireVF(); if (vfToUse == null) { failValidationCannotPlugPassthroughVnicNoSuitableVf(); return; } networkDeviceHelper.setVmIdOnVfs(getVdsId(), getVmId(), Collections.singleton(vfToUse)); vmDevice.setHostDevice(vfToUse); } VDSReturnValue returnValue = runVdsCommand(getParameters().getAction().getCommandType(), new VmNicDeviceVDSParameters(getVdsId(), getVm(), getParameters().getNic(), vmDevice)); if (returnValue.getSucceeded()) { boolean passthroughHotPlug = vfToUse != null; boolean passthroughHotUnplug = isPassthrough() && getParameters().getAction() == PlugAction.UNPLUG; if (passthroughHotUnplug) { networkDeviceHelper.setVmIdOnVfs(getVdsId(), null, new HashSet<>(Arrays.asList(vmDevice.getHostDevice()))); } if (passthroughHotPlug || passthroughHotUnplug) { runInternalAction(VdcActionType.RefreshHost, new VdsActionParameters(getVdsId())); } } else { clearPassthroughData(vfToUse); } } catch (EngineException e) { if (externalNetworkIsPlugged && getParameters().isNewNic()) { unplugFromExternalNetwork(); } clearPassthroughData(vfToUse); throw e; } } TransactionSupport.executeInNewTransaction(updateDevice()); setSucceeded(true); }