Search in sources :

Example 1 with MacPool

use of org.ovirt.engine.core.bll.network.macpool.MacPool in project ovirt-engine by oVirt.

the class MoveMacs method migrateMacsToAnotherMacPool.

public void migrateMacsToAnotherMacPool(Guid sourceMacPoolId, Guid targetMacPoolId, List<String> macsToMigrate, CommandContext commandContext) {
    Objects.requireNonNull(sourceMacPoolId);
    Objects.requireNonNull(targetMacPoolId);
    Objects.requireNonNull(macsToMigrate);
    Objects.requireNonNull(commandContext);
    if (macsToMigrate.isEmpty() || sourceMacPoolId.equals(targetMacPoolId)) {
        return;
    }
    MacPool sourcePool = poolPerCluster.getMacPoolById(sourceMacPoolId, commandContext);
    MacPool targetPool = poolPerCluster.getMacPoolById(targetMacPoolId, commandContext);
    sourcePool.freeMacs(macsToMigrate);
    List<String> notAddedMacs = targetPool.addMacs(macsToMigrate);
    boolean allMacsWereAdded = notAddedMacs.isEmpty();
    if (!allMacsWereAdded) {
        /* exception is thrown, because this is the easiest way, how to nullify updated VM data
             * and return macs to original pool.
             */
        throw new IllegalStateException(createMessageCannotChangeClusterDueToDuplicatesInTargetPool(notAddedMacs));
    }
}
Also used : ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool)

Example 2 with MacPool

use of org.ovirt.engine.core.bll.network.macpool.MacPool in project ovirt-engine by oVirt.

the class SnapshotsManager method synchronizeNics.

/**
 * Synchronize the VM's {@link VmNetworkInterface}s with the ones from the snapshot.<br>
 * All existing NICs will be deleted, and the ones from the snapshot re-added.<br>
 * In case a MAC address is already in use, the user will be issued a warning in the audit log.
 *
 * @param user
 *            The user that performs the action
 * @param vmInterfaceManager vmInterfaceManager instance
 */
private void synchronizeNics(VM snapshotedVm, CompensationContext compensationContext, DbUser user, VmInterfaceManager vmInterfaceManager, boolean macsInSnapshotAreExpectedToBeAlreadyAllocated) {
    VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(snapshotedVm.getClusterId(), snapshotedVm.getStoragePoolId(), AuditLogType.IMPORTEXPORT_SNAPSHOT_VM_INVALID_INTERFACES);
    MacPool macPool = vmInterfaceManager.getMacPool();
    /*what is at moment of calling this in DB are data related to (stateless) VM being updated/overwritten by
         * snapshot data.
         */
    List<VmNic> dbNics = vmNicDao.getAllForVm(snapshotedVm.getId());
    /*
         * while snapshotedVm.getInterfaces() are interfaces taken from VM passed into here via parameter. This instance originates from same DB
         * record, but it was updated with ovf snapshot, so at the moment of calling this, VM is filled with data to
         * which we need to revert for example stateless VM being stopped.
         */
    new SyncMacsOfDbNicsWithSnapshot(macPool, auditLogDirector, macsInSnapshotAreExpectedToBeAlreadyAllocated).sync(dbNics, snapshotedVm.getInterfaces());
    vmInterfaceManager.removeAll(dbNics);
    for (VmNetworkInterface vmInterface : snapshotedVm.getInterfaces()) {
        vmInterface.setVmId(snapshotedVm.getId());
        // These fields might not be saved in the OVF, so fill them with reasonable values.
        if (vmInterface.getId() == null) {
            vmInterface.setId(Guid.newGuid());
        }
        vnicProfileHelper.updateNicWithVnicProfileForUser(vmInterface, user);
        vmInterfaceManager.persistIface(vmInterface, compensationContext);
    }
    vnicProfileHelper.auditInvalidInterfaces(snapshotedVm.getName());
}
Also used : MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) VnicProfileHelper(org.ovirt.engine.core.bll.network.vm.VnicProfileHelper) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 3 with MacPool

use of org.ovirt.engine.core.bll.network.macpool.MacPool in project ovirt-engine by oVirt.

the class StorageHandlingCommandBase method releaseStorageDomainMacPool.

protected void releaseStorageDomainMacPool(List<VM> vmList) {
    Map<Guid, List<Guid>> vmsByCluster = vmList.stream().collect(Collectors.groupingBy(VM::getClusterId, Collectors.mapping(VM::getId, Collectors.toList())));
    vmsByCluster.entrySet().forEach(e -> {
        Guid clusterId = e.getKey();
        List<Guid> vmsId = e.getValue();
        MacPool macPool = macPoolPerCluster.getMacPoolForCluster(clusterId, getContext());
        macPool.freeMacs(vmsId.stream().flatMap(v -> vmNicDao.getAllForVm(v).stream()).map(VmNic::getMacAddress).filter(Objects::nonNull).collect(Collectors.toList()));
    });
}
Also used : MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) VM(org.ovirt.engine.core.common.businessentities.VM) Objects(java.util.Objects) List(java.util.List) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with MacPool

use of org.ovirt.engine.core.bll.network.macpool.MacPool in project ovirt-engine by oVirt.

the class SnapshotsManager method canSynchronizeNics.

public boolean canSynchronizeNics(VM snapshotedVm, VmInterfaceManager vmInterfaceManager, List<VmNetworkInterface> interfaces, boolean macsInSnapshotAreExpectedToBeAlreadyAllocated) {
    MacPool macPool = vmInterfaceManager.getMacPool();
    List<VmNic> dbNics = vmNicDao.getAllForVm(snapshotedVm.getId());
    return new SyncMacsOfDbNicsWithSnapshot(macPool, auditLogDirector, macsInSnapshotAreExpectedToBeAlreadyAllocated).canSyncNics(dbNics, interfaces);
}
Also used : MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 5 with MacPool

use of org.ovirt.engine.core.bll.network.macpool.MacPool in project ovirt-engine by oVirt.

the class ImportVmCommandBase method vNicHasBadMac.

protected boolean vNicHasBadMac(VmNetworkInterface vnic) {
    MacPool macPool = getMacPool();
    Predicate<VmNetworkInterface> vnicWithBadMacPredicate = new VnicWithBadMacPredicate(macPool);
    return vnicWithBadMacPredicate.test(vnic);
}
Also used : MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VnicWithBadMacPredicate(org.ovirt.engine.core.bll.network.predicate.VnicWithBadMacPredicate)

Aggregations

MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)7 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)2 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 ReadMacPool (org.ovirt.engine.core.bll.network.macpool.ReadMacPool)1 VnicWithBadMacPredicate (org.ovirt.engine.core.bll.network.predicate.VnicWithBadMacPredicate)1 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 Guid (org.ovirt.engine.core.compat.Guid)1