Search in sources :

Example 1 with IpVersion

use of org.ovirt.engine.api.model.IpVersion in project ovirt-engine by oVirt.

the class ReportedDeviceMapper method map.

@Mapping(from = ReportedDevice.class, to = VmGuestAgentInterface.class)
public static VmGuestAgentInterface map(ReportedDevice model, VmGuestAgentInterface template) {
    VmGuestAgentInterface entity = template != null ? template : new VmGuestAgentInterface();
    if (model.isSetVm() && model.getVm().isSetId()) {
        entity.setVmId(GuidUtils.asGuid(model.getVm().getId()));
    }
    if (model.isSetName()) {
        entity.setInterfaceName(model.getName());
    }
    if (model.isSetMac() && model.getMac().isSetAddress()) {
        entity.setMacAddress(model.getMac().getAddress());
    }
    if (model.isSetIps() && model.getIps().isSetIps()) {
        List<String> ipv4 = new ArrayList<>();
        List<String> ipv6 = new ArrayList<>();
        for (Ip ip : model.getIps().getIps()) {
            IpVersion version = IpHelper.getVersion(ip);
            if (version != null) {
                switch(version) {
                    case V4:
                        ipv4.add(ip.getAddress());
                        break;
                    case V6:
                        ipv6.add(ip.getAddress());
                        break;
                }
            }
        }
        entity.setIpv4Addresses(ipv4);
        entity.setIpv6Addresses(ipv6);
    }
    return entity;
}
Also used : VmGuestAgentInterface(org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface) IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip) ArrayList(java.util.ArrayList)

Example 2 with IpVersion

use of org.ovirt.engine.api.model.IpVersion in project ovirt-engine by oVirt.

the class IpHelperTest method testIgnoreAddressWhenV6ExplicitlyGiven.

/**
 * Checks that when explicitly given IPv6 it ignores the address.
 */
@Test
public void testIgnoreAddressWhenV6ExplicitlyGiven() {
    Ip ip = new Ip();
    ip.setAddress("127.0.0.1");
    ip.setVersion(IpVersion.V6);
    IpVersion version = IpHelper.getVersion(ip);
    assertEquals(IpVersion.V6, version);
}
Also used : IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip) Test(org.junit.Test)

Example 3 with IpVersion

use of org.ovirt.engine.api.model.IpVersion in project ovirt-engine by oVirt.

the class IpHelperTest method testReturnNullWhenGivenNullIp.

/**
 * Checks that when given a {@code null} IP configuration object it returns {@code null}.
 */
@Test
public void testReturnNullWhenGivenNullIp() {
    IpVersion version = IpHelper.getVersion(null);
    assertEquals(null, version);
}
Also used : IpVersion(org.ovirt.engine.api.model.IpVersion) Test(org.junit.Test)

Example 4 with IpVersion

use of org.ovirt.engine.api.model.IpVersion in project ovirt-engine by oVirt.

the class IpHelperTest method testIgnoreAddressWhenV4ExplicitlyGiven.

/**
 * Checks that when explicitly given IPv4 it ignores the address.
 */
@Test
public void testIgnoreAddressWhenV4ExplicitlyGiven() {
    Ip ip = new Ip();
    ip.setAddress("::1");
    ip.setVersion(IpVersion.V4);
    IpVersion version = IpHelper.getVersion(ip);
    assertEquals(IpVersion.V4, version);
}
Also used : IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip) Test(org.junit.Test)

Example 5 with IpVersion

use of org.ovirt.engine.api.model.IpVersion in project ovirt-engine by oVirt.

the class IpHelperTest method testReturnsV4WhenGivenValidV4Address.

/**
 * Checks that when the version isn't given explicitly, and the address is a valid IPv4 address, the returned
 * version is IPv4.
 */
@Test
public void testReturnsV4WhenGivenValidV4Address() {
    Ip ip = new Ip();
    ip.setAddress("127.0.0.1");
    IpVersion version = IpHelper.getVersion(ip);
    assertEquals(IpVersion.V4, version);
}
Also used : IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip) Test(org.junit.Test)

Aggregations

IpVersion (org.ovirt.engine.api.model.IpVersion)6 Test (org.junit.Test)5 Ip (org.ovirt.engine.api.model.Ip)5 ArrayList (java.util.ArrayList)1 VmGuestAgentInterface (org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface)1