Search in sources :

Example 76 with VmNetworkInterface

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

the class FindActiveVmsUsingNetworkTest method createVM.

/**
 * Creates a VM instance with a given name, having an interface which uses a given network.
 *
 * @param vmName
 *            The VM name to be set
 * @param networkName
 *            The network name to be set for the VM interface
 * @param pluggedInterface
 *            whether the VM interface plugged or not
 * @return the VM instance with the appropriate data.
 */
private static VM createVM(String vmName, String networkName, boolean pluggedInterface) {
    VM vm = new VM();
    vm.setId(Guid.newGuid());
    vm.setName(vmName);
    VmNetworkInterface vmIface = createNewViewableInterface(pluggedInterface);
    vmIface.setVmId(vm.getId());
    vmIface.setNetworkName(networkName);
    vm.getInterfaces().add(vmIface);
    return vm;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 77 with VmNetworkInterface

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

the class AllocateReleaseMacWhenBeingReservedForSnapshotTest method createVnNetworkInterface.

private VmNetworkInterface createVnNetworkInterface(String name, Guid id) {
    VmNetworkInterface vmNetworkInterface = new VmNetworkInterface();
    vmNetworkInterface.setName(name);
    vmNetworkInterface.setId(id);
    return vmNetworkInterface;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

Example 78 with VmNetworkInterface

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

the class GetVmsAndNetworkInterfacesByNetworkIdQueryTest method expectAndTestForVmsThatAreInAState.

private void expectAndTestForVmsThatAreInAState(boolean running, VMStatus expectedStatus, VMStatus unexpectedStatus) {
    when(params.getRunningVms()).thenReturn(running);
    vm.setStatus(expectedStatus);
    VM downVm = new VM();
    downVm.setId(Guid.newGuid());
    downVm.setStatus(unexpectedStatus);
    VmNetworkInterface downVmInterface = new VmNetworkInterface();
    downVmInterface.setVmId(downVm.getId());
    setupVmDao(Arrays.asList(vm, downVm));
    setupVmNetworkInterfaceDao(Arrays.asList(vmNetworkInterface, downVmInterface));
    expectAndTestForVmAndInterface();
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 79 with VmNetworkInterface

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

the class MacsUsedAcrossWholeSystemTest method testGetMacsForMacPool.

@Test
public void testGetMacsForMacPool() {
    MacPool macPool = createMacPool();
    String mac1 = "mac1";
    String mac2 = "mac2";
    String mac31 = "mac31";
    String mac32 = "mac32";
    String mac41 = "mac41";
    String mac42 = "mac42";
    String mac51 = "mac51";
    String mac52 = "mac52";
    String mac61 = "mac61";
    String mac62 = "mac62";
    String mac7 = "mac7";
    String mac8 = "mac8";
    Cluster cluster1 = createCluster(macPool);
    VmNetworkInterface nic1 = createNic(mac1);
    VM vm1 = createVm(cluster1, nic1);
    Cluster cluster2 = createCluster(macPool);
    VmNetworkInterface nic2 = createNic(mac2);
    VmNetworkInterface nic2_fromSnapshot = createNic(mac2, nic2.getId());
    VM vm2 = createVm(cluster2, nic2);
    VM snapshot2 = createSnapshot(cluster2, vm2, nic2_fromSnapshot);
    Cluster cluster3 = createCluster(macPool);
    Guid nic3Id = Guid.newGuid();
    VmNetworkInterface nic3 = createNic(mac31, nic3Id);
    VM vm3 = createVm(cluster3, nic3);
    VmNetworkInterface nic3_fromSnapshot = createNic(mac32, nic3Id);
    VM snapshot3 = createSnapshot(cluster3, vm3, nic3_fromSnapshot);
    Cluster cluster4 = createCluster(macPool);
    VmNetworkInterface nic41 = createNic(mac42);
    VmNetworkInterface nic41_fromSnapshot = createNic(mac41);
    VmNetworkInterface nic42 = createNic(mac41);
    VM vm4 = createVm(cluster4, nic41, nic42);
    VM snapshot4 = createSnapshot(cluster4, vm4, nic41_fromSnapshot);
    Cluster cluster5 = createCluster(macPool);
    VmNetworkInterface nic5 = createNic(mac51);
    VmNetworkInterface nic5_fromSnapshot = createNic(mac52);
    VM notRunningVm = createVm(cluster5, Guid.newGuid(), false, true, nic5);
    VM snapshot5 = createSnapshot(cluster5, notRunningVm, nic5_fromSnapshot);
    VmNetworkInterface nic6 = createNic(mac61);
    VmNetworkInterface nic6_fromSnapshot = createNic(mac62);
    VM notStatelessVm = createVm(cluster5, Guid.newGuid(), true, false, nic6);
    VM snapshot6 = createSnapshot(cluster5, notStatelessVm, nic6_fromSnapshot);
    Cluster cluster6 = createCluster(macPool);
    VmNetworkInterface nic71 = createNic(mac7);
    VmNetworkInterface nic72 = createNic(mac7);
    VM vmWithDuplicates = createVm(cluster6, nic71, nic72);
    VmNetworkInterface nic81 = createNic(mac8);
    VmNetworkInterface nic82 = createNic(mac8);
    VmNetworkInterface nic83 = createNic(mac8);
    VM vmHavingSnapshotWithDuplicates = createVm(cluster6, nic83);
    VM snapshot7 = createSnapshot(cluster6, vmHavingSnapshotWithDuplicates, nic81, nic82);
    // mocking:
    when(clusterDao.getAllClustersByMacPoolId(macPool.getId())).thenReturn(Arrays.asList(cluster1, cluster2, cluster3, cluster4, cluster5, cluster6));
    mockClusterVms(cluster1, vm1);
    mockClusterVms(cluster2, vm2);
    mockClusterVms(cluster3, vm3);
    mockClusterVms(cluster4, vm4);
    mockClusterVms(cluster5, notRunningVm, notStatelessVm);
    mockClusterVms(cluster6, vmWithDuplicates, vmHavingSnapshotWithDuplicates);
    mockVmSnapshots(vm1, Optional.empty());
    mockVmSnapshots(vm2, Optional.of(snapshot2));
    mockVmSnapshots(vm3, Optional.of(snapshot3));
    mockVmSnapshots(vm4, Optional.of(snapshot4));
    mockVmSnapshots(notRunningVm, Optional.of(snapshot5));
    mockVmSnapshots(notStatelessVm, Optional.of(snapshot6));
    mockVmSnapshots(vmHavingSnapshotWithDuplicates, Optional.of(snapshot7));
    // verifying
    List<String> macsForMacPool = underTest.getMacsForMacPool(macPool.getId());
    assertThat(macsForMacPool, Matchers.containsInAnyOrder(mac1, mac2, mac31, mac32, mac41, mac42, mac51, mac61, mac7, mac7, mac8, mac8));
}
Also used : MacPool(org.ovirt.engine.core.common.businessentities.MacPool) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 80 with VmNetworkInterface

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

the class GetTemplateInterfacesByTemplateIdQueryTest method testExecuteQuery.

@Test
public void testExecuteQuery() {
    Guid templateID = Guid.newGuid();
    List<VmNetworkInterface> expectedResult = Collections.singletonList(new VmNetworkInterface());
    IdQueryParameters paramsMock = getQueryParameters();
    when(paramsMock.getId()).thenReturn(templateID);
    when(vmNetworkInterfaceDaoMock.getAllForTemplate(templateID, getUser().getId(), paramsMock.isFiltered())).thenReturn(expectedResult);
    getQuery().executeQueryCommand();
    List<VmNetworkInterface> result = getQuery().getQueryReturnValue().getReturnValue();
    assertEquals("Wrong interfaces returned", expectedResult, result);
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) AbstractUserQueryTest(org.ovirt.engine.core.bll.AbstractUserQueryTest) 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