Search in sources :

Example 1 with NetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.NetworkInterface in project ovirt-engine by oVirt.

the class SyncMacsOfDbNicsWithSnapshot method reallocateMacsWhichCouldntBeAddedToMacPool.

private void reallocateMacsWhichCouldntBeAddedToMacPool(List<String> macsFailedToBeAdded, List<? extends NetworkInterface> snapshotedNics) {
    if (macsFailedToBeAdded.isEmpty()) {
        return;
    }
    // not to ruin original for error reporting.
    List<String> macsFailedToBeAddedCopy = new ArrayList<>(macsFailedToBeAdded);
    try {
        List<Pair<String, String>> macReplacements = new ArrayList<>();
        for (NetworkInterface vmInterface : snapshotedNics) {
            String originalMacAddress = vmInterface.getMacAddress();
            if (macsFailedToBeAddedCopy.contains(originalMacAddress)) {
                macsFailedToBeAddedCopy.remove(originalMacAddress);
                String replacingMac = macPool.allocateNewMac();
                vmInterface.setMacAddress(replacingMac);
                macReplacements.add(new Pair<>(originalMacAddress, replacingMac));
            }
        }
        auditLogPerformedReplacements(macReplacements);
    } catch (EngineException ex) {
        if (EngineError.MAC_POOL_NO_MACS_LEFT.equals(ex.getErrorCode())) {
            auditLogImpossibilityToReplaceDuplicateMacs(macsFailedToBeAdded);
        }
        throw ex;
    }
}
Also used : ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) NetworkInterface(org.ovirt.engine.core.common.businessentities.network.NetworkInterface) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

ArrayList (java.util.ArrayList)1 NetworkInterface (org.ovirt.engine.core.common.businessentities.network.NetworkInterface)1 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 Pair (org.ovirt.engine.core.common.utils.Pair)1