Search in sources :

Example 1 with MacRange

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

the class MacPoolMapper method mapRanges.

private static void mapRanges(org.ovirt.engine.api.model.MacPool model, MacPool entity) {
    final List<MacRange> ranges = new ArrayList<>();
    for (org.ovirt.engine.api.model.Range range : model.getRanges().getRanges()) {
        ranges.add(mapRange(range));
    }
    entity.setRanges(ranges);
}
Also used : MacRange(org.ovirt.engine.core.common.businessentities.MacRange) ArrayList(java.util.ArrayList) Range(org.ovirt.engine.api.model.Range)

Example 2 with MacRange

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

the class MacPoolMapper method mapRange.

private static Range mapRange(MacRange range) {
    final Range model = new Range();
    model.setFrom(range.getMacFrom());
    model.setTo(range.getMacTo());
    return model;
}
Also used : MacRange(org.ovirt.engine.core.common.businessentities.MacRange) Range(org.ovirt.engine.api.model.Range)

Example 3 with MacRange

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

the class MacPoolPerClusterTest method testModifyOfExistingMacPool.

@Test
public void testModifyOfExistingMacPool() throws Exception {
    final String macAddress1 = "00:00:00:00:00:01";
    final String macAddress2 = "00:00:00:00:00:02";
    MacPool macPool = createMacPool(macAddress1, macAddress1);
    Cluster cluster = createCluster(macPool);
    mockCluster(cluster);
    mockGettingAllMacPools(macPool);
    macPoolPerCluster.initialize();
    assertThat(getMacPool(cluster.getId()).addMac(MAC_FROM), is(true));
    assertThat(getMacPool(cluster.getId()).addMac(MAC_FROM), is(false));
    final String allocatedMac = allocateMac(cluster);
    /*needed due to implementation of modifyPool;
        modify assumes, that all allocated macs is used for vmNics. If allocatedMac succeeded it's expected that all
        vmNics were also successfully persisted to db or all allocated macs were returned to the pool. So after
        allocation we need to mock db, otherwise re-init in modifyPool would return improper results.*/
    mockUsedMacsInSystem(getMacPool(cluster.getId()).getId(), allocatedMac, MAC_FROM);
    assertThat(allocatedMac, is(macAddress1));
    try {
        allocateMac(cluster);
        fail("this allocation should not succeed, MAC should be full.");
    } catch (EngineException e) {
    // ok, this exception should occur.
    }
    macPool.setAllowDuplicateMacAddresses(true);
    final MacRange macRange = new MacRange();
    macRange.setMacFrom(macAddress1);
    macRange.setMacTo(macAddress2);
    macPool.setRanges(Collections.singletonList(macRange));
    macPoolPerCluster.modifyPool(macPool);
    assertThat(getMacPool(cluster.getId()).addMac(MAC_FROM), is(true));
    assertThat(allocateMac(cluster), is(macAddress2));
}
Also used : MacPool(org.ovirt.engine.core.common.businessentities.MacPool) MacRange(org.ovirt.engine.core.common.businessentities.MacRange) EngineException(org.ovirt.engine.core.common.errors.EngineException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Test(org.junit.Test)

Example 4 with MacRange

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

the class MacPoolPerClusterTest method createMacPool.

private MacPool createMacPool(String macFrom, String macTo) {
    final MacRange macRange = new MacRange();
    macRange.setMacFrom(macFrom);
    macRange.setMacTo(macTo);
    final MacPool macPool = new MacPool();
    macPool.setId(Guid.newGuid());
    macPool.setRanges(Collections.singletonList(macRange));
    return macPool;
}
Also used : MacPool(org.ovirt.engine.core.common.businessentities.MacPool) MacRange(org.ovirt.engine.core.common.businessentities.MacRange)

Example 5 with MacRange

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

the class MacPoolDaoImpl method save.

@Override
public void save(MacPool entity) {
    super.save(entity);
    for (MacRange macRange : entity.getRanges()) {
        macRange.setMacPoolId(entity.getId());
        saveRange(macRange);
    }
}
Also used : MacRange(org.ovirt.engine.core.common.businessentities.MacRange)

Aggregations

MacRange (org.ovirt.engine.core.common.businessentities.MacRange)9 MacPool (org.ovirt.engine.core.common.businessentities.MacPool)4 ArrayList (java.util.ArrayList)2 Range (org.ovirt.engine.api.model.Range)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Test (org.junit.Test)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)1 ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)1