Search in sources :

Example 56 with VmNetworkInterface

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

the class VmNetworkInterfaceDaoTest method testGetAllInterfacesForVmFilteredWithoutPermissionsAndWithoutFiltering.

/**
 * Ensures that the VMs for an unprivileged user are returned if no filtering is requested
 */
@Test
public void testGetAllInterfacesForVmFilteredWithoutPermissionsAndWithoutFiltering() {
    List<VmNetworkInterface> result = dao.getAllForVm(VM_ID, UNPRIVILEGED_USER_ID, false);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    for (VmNetworkInterface iface : result) {
        assertEquals(VM_ID, iface.getVmId());
    }
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Test(org.junit.Test)

Example 57 with VmNetworkInterface

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

the class BackendTemplateNicsResource method list.

@Override
public Nics list() {
    Nics nics = new Nics();
    List<VmNetworkInterface> entities = getBackendCollection(QueryType.GetTemplateInterfacesByTemplateId, new IdQueryParameters(templateId));
    for (VmNetworkInterface entity : entities) {
        Nic nic = populate(map(entity), entity);
        nics.getNics().add(addLinks(nic));
    }
    return nics;
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Nic(org.ovirt.engine.api.model.Nic) Nics(org.ovirt.engine.api.model.Nics)

Example 58 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface 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 59 with VmNetworkInterface

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

the class MatchUserMappingToOvfVnicTest method testFindMappingEntry.

@Test
public void testFindMappingEntry() {
    VmNetworkInterface vnic = new VmNetworkInterface();
    vnic.setNetworkName(NETWORK_NAME);
    vnic.setVnicProfileName(VNIC_PROFILE1_NAME);
    MapVnicsContext ctx = new MapVnicsContext();
    ctx.setUserMappings(externalVnicProfileMappings);
    ctx.setOvfVnics(singletonList(vnic));
    underTest.handle(ctx);
    assertThat(ctx.getMatched().get(vnic), sameInstance(externalVnicProfileMapping1));
}
Also used : MapVnicsContext(org.ovirt.engine.core.bll.exportimport.vnics.MapVnicsContext) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Test(org.junit.Test)

Example 60 with VmNetworkInterface

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

the class MatchUserMappingToOvfVnicTest method testFindMappingEntryEmptyExternal.

@Test
public void testFindMappingEntryEmptyExternal() {
    VmNetworkInterface vnic = new VmNetworkInterface();
    vnic.setNetworkName(NETWORK_NAME);
    vnic.setVnicProfileName(VNIC_PROFILE1_NAME);
    MapVnicsContext ctx = new MapVnicsContext();
    ctx.setUserMappings(singletonList(emptySourceMapping));
    ctx.setOvfVnics(singletonList(vnic));
    underTest.handle(ctx);
    assertEquals(null, ctx.getMatched().get(vnic));
}
Also used : MapVnicsContext(org.ovirt.engine.core.bll.exportimport.vnics.MapVnicsContext) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Test(org.junit.Test)

Aggregations

VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)115 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 Guid (org.ovirt.engine.core.compat.Guid)19 VM (org.ovirt.engine.core.common.businessentities.VM)16 HashMap (java.util.HashMap)11 List (java.util.List)9 Map (java.util.Map)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 PairQueryable (org.ovirt.engine.core.common.utils.PairQueryable)6 MapVnicsContext (org.ovirt.engine.core.bll.exportimport.vnics.MapVnicsContext)5 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)5 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)5 VmNetworkStatistics (org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics)5 Nic (org.ovirt.engine.api.model.Nic)4 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)4 Collection (java.util.Collection)3