Search in sources :

Example 6 with Ip

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);
}
Also used : IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip) Test(org.junit.Test)

Example 7 with Ip

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;
}
Also used : ReportedDeviceType(org.ovirt.engine.api.model.ReportedDeviceType) IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip)

Example 8 with Ip

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);
}
Also used : IpVersion(org.ovirt.engine.api.model.IpVersion) Ip(org.ovirt.engine.api.model.Ip) Test(org.junit.Test)

Example 9 with Ip

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.
        }
    }
}
Also used : ReportedDevice(org.ovirt.engine.api.model.ReportedDevice) WebApplicationException(javax.ws.rs.WebApplicationException) Ip(org.ovirt.engine.api.model.Ip) ArrayList(java.util.ArrayList) Nic(org.ovirt.engine.api.model.Nic) ReportedDevices(org.ovirt.engine.api.model.ReportedDevices) Ips(org.ovirt.engine.api.model.Ips) Nics(org.ovirt.engine.api.model.Nics) VmResource(org.ovirt.engine.api.resource.VmResource) VmNicsResource(org.ovirt.engine.api.resource.VmNicsResource) VmsResource(org.ovirt.engine.api.resource.VmsResource) SystemResource(org.ovirt.engine.api.resource.SystemResource) V3GuestInfo(org.ovirt.engine.api.v3.types.V3GuestInfo) V3IPs(org.ovirt.engine.api.v3.types.V3IPs)

Example 10 with Ip

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);
    }
}
Also used : Ip(org.ovirt.engine.api.model.Ip) Ipv6BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol) BootProtocol(org.ovirt.engine.api.model.BootProtocol) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)

Aggregations

Ip (org.ovirt.engine.api.model.Ip)16 IpVersion (org.ovirt.engine.api.model.IpVersion)6 Test (org.junit.Test)5 BootProtocol (org.ovirt.engine.api.model.BootProtocol)4 IpAddressAssignment (org.ovirt.engine.api.model.IpAddressAssignment)4 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)4 Ipv6BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol)4 ArrayList (java.util.ArrayList)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 Domain (org.ovirt.engine.api.model.Domain)1 Ips (org.ovirt.engine.api.model.Ips)1 Nic (org.ovirt.engine.api.model.Nic)1 Nics (org.ovirt.engine.api.model.Nics)1 ReportedDevice (org.ovirt.engine.api.model.ReportedDevice)1 ReportedDeviceType (org.ovirt.engine.api.model.ReportedDeviceType)1 ReportedDevices (org.ovirt.engine.api.model.ReportedDevices)1 Session (org.ovirt.engine.api.model.Session)1 User (org.ovirt.engine.api.model.User)1 SystemResource (org.ovirt.engine.api.resource.SystemResource)1 VmNicsResource (org.ovirt.engine.api.resource.VmNicsResource)1