use of org.ovirt.engine.api.model.Ip 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.Ip in project ovirt-engine by oVirt.
the class ReportedDeviceMapperTest method postPopulate.
@Override
protected ReportedDevice postPopulate(ReportedDevice model) {
model.setType(MappingTestHelper.shuffle(ReportedDeviceType.class));
for (Ip ip : model.getIps().getIps()) {
ip.setVersion(MappingTestHelper.shuffle(IpVersion.class));
ip.setGateway(null);
ip.setNetmask(null);
}
return model;
}
use of org.ovirt.engine.api.model.Ip 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.Ip in project ovirt-engine by oVirt.
the class V3VmHelper method addGuestIp.
/**
* If the V4 virtual machine has IP addresses reported, then add them to the V3 {@code guest_info} element.
*/
public static void addGuestIp(V3VM vm) {
String vmId = vm.getId();
if (vmId != null) {
SystemResource systemResource = BackendApiResource.getInstance();
VmsResource vmsResource = systemResource.getVmsResource();
VmResource vmResource = vmsResource.getVmResource(vmId);
VmNicsResource nicsResource = vmResource.getNicsResource();
try {
Nics fromNics = nicsResource.list();
List<Ip> fromIps = new ArrayList<>();
for (Nic fromNic : fromNics.getNics()) {
ReportedDevices fromDevices = fromNic.getReportedDevices();
if (fromDevices != null) {
for (ReportedDevice fromDevice : fromDevices.getReportedDevices()) {
Ips deviceIps = fromDevice.getIps();
if (deviceIps != null) {
fromIps.addAll(deviceIps.getIps());
}
}
}
}
if (!fromIps.isEmpty()) {
V3GuestInfo guestInfo = vm.getGuestInfo();
if (guestInfo == null) {
guestInfo = new V3GuestInfo();
vm.setGuestInfo(guestInfo);
}
V3IPs ips = guestInfo.getIps();
if (ips == null) {
ips = new V3IPs();
guestInfo.setIps(ips);
}
ips.getIPs().addAll(adaptOut(fromIps));
}
} catch (WebApplicationException exception) {
// If an application exception is generated while retrieving the details of the NICs is safe to ignore
// it, as it may be that the user just doesn't have permission to see the NICs, but she may still have
// permissions to see the other details of the virtual machine.
}
}
}
use of org.ovirt.engine.api.model.Ip in project ovirt-engine by oVirt.
the class HostNicMapper method mapIpv4ToModel.
private static void mapIpv4ToModel(VdsNetworkInterface entity, HostNic model) {
BootProtocol ipv4BootProtocol = Ipv4BootProtocolMapper.map(entity.getIpv4BootProtocol());
if (ipv4BootProtocol != null) {
model.setBootProtocol(ipv4BootProtocol);
}
if (entity.getIpv4Address() != null || entity.getIpv4Gateway() != null || entity.getIpv4Subnet() != null) {
final Ip ipv4 = new Ip();
ipv4.setVersion(IpVersion.V4);
if (entity.getIpv4Address() != null) {
ipv4.setAddress(entity.getIpv4Address());
}
if (entity.getIpv4Gateway() != null) {
ipv4.setGateway(entity.getIpv4Gateway());
}
if (entity.getIpv4Subnet() != null) {
ipv4.setNetmask(entity.getIpv4Subnet());
}
model.setIp(ipv4);
}
}
Aggregations