Source:
public void updateUsbSlots(VmBase oldVm, Cluster oldVmCluster, VmBase newVm, Cluster newVmCluster) { final UsbPolicy oldUsbPolicy = oldVm.getUsbPolicy(); final UsbPolicy newUsbPolicy = newVm.getUsbPolicy(); final int oldNumberOfSlots = getUsbSlots(oldVm.getId()).size(); final BiosType effectiveBiosType = BiosTypeUtils.getEffective(newVm, newVmCluster); final int newNumberOfUsbSlots = Config.<Integer> getValue(ConfigValues.NumberOfUSBSlots); if (UsbPolicy.DISABLED == newUsbPolicy && newVm.getVmType() == VmType.HighPerformance) { disableAnyUsb(oldVm, newVm); return; } if (UsbPolicy.DISABLED == oldUsbPolicy && UsbPolicy.ENABLED_NATIVE == newUsbPolicy) { disableNormalUsb(newVm.getId()); enableSpiceUsb(newVm.getId(), effectiveBiosType, newNumberOfUsbSlots); return; } if (UsbPolicy.ENABLED_NATIVE == oldUsbPolicy && UsbPolicy.ENABLED_NATIVE == newUsbPolicy) { BiosType oldBiosType = BiosTypeUtils.getEffective(oldVm, oldVmCluster); BiosType newBiosType = BiosTypeUtils.getEffective(oldVm, newVmCluster); if (!oldBiosType.getChipsetType().equals(newBiosType.getChipsetType())) { disableSpiceUsb(newVm.getId()); enableSpiceUsb(newVm.getId(), effectiveBiosType, newNumberOfUsbSlots); } else { updateSpiceUsb(newVm.getId(), effectiveBiosType, oldNumberOfSlots, newNumberOfUsbSlots); } return; } if (UsbPolicy.ENABLED_NATIVE == oldUsbPolicy && UsbPolicy.DISABLED == newUsbPolicy) { disableSpiceUsb(newVm.getId()); enableNormalUsb(newVm); return; } if (UsbPolicy.DISABLED == oldUsbPolicy && UsbPolicy.DISABLED == newUsbPolicy) { updateNormalUsb(newVm); return; } throw new RuntimeException( format("Unexpected state: oldUsbPolicy=%s, newUsbPolicy=%s", oldUsbPolicy, newUsbPolicy)); }

Target:
public void updateUsbSlots(VmBase oldVm, Cluster oldVmCluster, VmBase newVm, Cluster newVmCluster) { final UsbPolicy oldUsbPolicy = oldVm.getUsbPolicy(); final UsbPolicy newUsbPolicy = newVm.getUsbPolicy(); final int oldNumberOfSlots = getUsbSlots(oldVm.getId()).size(); final BiosType effectiveBiosType = BiosTypeUtils.getEffective(newVm, newVmCluster); final int newNumberOfUsbSlots = Config.<Integer> getValue(ConfigValues.NumberOfUSBSlots); if (UsbPolicy.DISABLED == newUsbPolicy && newVm.getVmType() == VmType.HighPerformance) { disableAnyUsb(oldVm, newVm); return; } if (UsbPolicy.DISABLED == oldUsbPolicy && UsbPolicy.ENABLED_NATIVE == newUsbPolicy) { disableNormalUsb(newVm.getId()); enableSpiceUsb(newVm.getId(), effectiveBiosType, newNumberOfUsbSlots); return; } if (UsbPolicy.ENABLED_NATIVE == oldUsbPolicy && UsbPolicy.ENABLED_NATIVE == newUsbPolicy) { BiosType oldBiosType = BiosTypeUtils.getEffective(oldVm, oldVmCluster); BiosType newBiosType = BiosTypeUtils.getEffective(newVm, newVmCluster); if (!oldBiosType.getChipsetType().equals(newBiosType.getChipsetType())) { disableSpiceUsb(newVm.getId()); enableSpiceUsb(newVm.getId(), effectiveBiosType, newNumberOfUsbSlots); } else { updateSpiceUsb(newVm.getId(), effectiveBiosType, oldNumberOfSlots, newNumberOfUsbSlots); } return; } if (UsbPolicy.ENABLED_NATIVE == oldUsbPolicy && UsbPolicy.DISABLED == newUsbPolicy) { disableSpiceUsb(newVm.getId()); enableNormalUsb(newVm); return; } if (UsbPolicy.DISABLED == oldUsbPolicy && UsbPolicy.DISABLED == newUsbPolicy) { updateNormalUsb(newVm); return; } throw new RuntimeException( format("Unexpected state: oldUsbPolicy=%s, newUsbPolicy=%s", oldUsbPolicy, newUsbPolicy)); }