Search in sources :

Example 1 with ReportedDevice

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

the class BackendNicHelper method getDevices.

private static List<ReportedDevice> getDevices(BackendResource resource, Guid vmId, String mac) {
    List<ReportedDevice> devices = new ArrayList<>();
    for (VmGuestAgentInterface iface : getDevicesCollection(resource, vmId)) {
        if (StringUtils.equals(iface.getMacAddress(), mac)) {
            ReportedDevice device = LinkHelper.addLinks(ReportedDeviceMapper.map(iface, new ReportedDevice()));
            devices.add(device);
        }
    }
    return devices;
}
Also used : ReportedDevice(org.ovirt.engine.api.model.ReportedDevice) VmGuestAgentInterface(org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface) ArrayList(java.util.ArrayList)

Example 2 with ReportedDevice

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

the class BackendNicHelper method addReportedDevices.

public static void addReportedDevices(BackendResource resource, Nic model, VmNetworkInterface entity) {
    List<ReportedDevice> devices = getDevices(resource, entity.getVmId(), entity.getMacAddress());
    if (!devices.isEmpty()) {
        ReportedDevices reportedDevices = new ReportedDevices();
        reportedDevices.getReportedDevices().addAll(devices);
        model.setReportedDevices(reportedDevices);
    }
}
Also used : ReportedDevice(org.ovirt.engine.api.model.ReportedDevice) ReportedDevices(org.ovirt.engine.api.model.ReportedDevices)

Example 3 with ReportedDevice

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

the class V3ReportedDeviceInAdapter method adapt.

@Override
public ReportedDevice adapt(V3ReportedDevice from) {
    ReportedDevice to = new ReportedDevice();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetIps()) {
        to.setIps(new Ips());
        to.getIps().getIps().addAll(adaptIn(from.getIps().getIPs()));
    }
    if (from.isSetMac()) {
        to.setMac(adaptIn(from.getMac()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetType()) {
        to.setType(ReportedDeviceType.fromValue(from.getType()));
    }
    if (from.isSetVm()) {
        to.setVm(adaptIn(from.getVm()));
    }
    return to;
}
Also used : ReportedDevice(org.ovirt.engine.api.model.ReportedDevice) V3ReportedDevice(org.ovirt.engine.api.v3.types.V3ReportedDevice) Ips(org.ovirt.engine.api.model.Ips)

Example 4 with ReportedDevice

use of org.ovirt.engine.api.model.ReportedDevice 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 5 with ReportedDevice

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

the class BackendVmReportedDeviceResourceTest method testGet.

@Test
public void testGet() throws Exception {
    resource.getParent().setUriInfo(setUpBasicUriExpectations());
    setUpEntityQueryExpectations(1);
    ReportedDevice device = resource.get();
    assertEquals(DEVICE_ID.toString(), device.getId());
    verifyLinks(device);
}
Also used : ReportedDevice(org.ovirt.engine.api.model.ReportedDevice) Test(org.junit.Test)

Aggregations

ReportedDevice (org.ovirt.engine.api.model.ReportedDevice)5 ArrayList (java.util.ArrayList)2 Ips (org.ovirt.engine.api.model.Ips)2 ReportedDevices (org.ovirt.engine.api.model.ReportedDevices)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.Test)1 Ip (org.ovirt.engine.api.model.Ip)1 Nic (org.ovirt.engine.api.model.Nic)1 Nics (org.ovirt.engine.api.model.Nics)1 SystemResource (org.ovirt.engine.api.resource.SystemResource)1 VmNicsResource (org.ovirt.engine.api.resource.VmNicsResource)1 VmResource (org.ovirt.engine.api.resource.VmResource)1 VmsResource (org.ovirt.engine.api.resource.VmsResource)1 V3GuestInfo (org.ovirt.engine.api.v3.types.V3GuestInfo)1 V3IPs (org.ovirt.engine.api.v3.types.V3IPs)1 V3ReportedDevice (org.ovirt.engine.api.v3.types.V3ReportedDevice)1 VmGuestAgentInterface (org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface)1