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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations