Search in sources :

Example 21 with Nic

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

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

the class NicMapper method map.

@Mapping(from = VmNetworkInterface.class, to = Nic.class)
public static Nic map(VmNetworkInterface entity, Nic template) {
    Nic model = template != null ? template : new Nic();
    if (entity.getVmId() != null) {
        model.setVm(new Vm());
        model.getVm().setId(entity.getVmId().toString());
    }
    if (entity.getId() != null) {
        model.setId(entity.getId().toString());
    }
    if (entity.getName() != null) {
        model.setName(entity.getName());
    }
    if (entity.getMacAddress() != null) {
        model.setMac(new Mac());
        model.getMac().setAddress(entity.getMacAddress());
    }
    model.setLinked(entity.isLinked());
    model.setInterface(map(entity.getType()));
    model.setPlugged(entity.isPlugged());
    if (entity.getVnicProfileId() != null) {
        model.setVnicProfile(new VnicProfile());
        model.getVnicProfile().setId(entity.getVnicProfileId().toString());
    }
    return model;
}
Also used : Vm(org.ovirt.engine.api.model.Vm) VnicProfile(org.ovirt.engine.api.model.VnicProfile) Nic(org.ovirt.engine.api.model.Nic) Mac(org.ovirt.engine.api.model.Mac)

Example 23 with Nic

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

the class BackendVmNicFilterParametersResource method addParents.

@Override
public NetworkFilterParameter addParents(NetworkFilterParameter parameter) {
    Vm vm = new Vm();
    vm.setId(vmId.toString());
    Nic nic = new Nic();
    nic.setId(nicId.toString());
    nic.setVm(vm);
    parameter.setNic(nic);
    return parameter;
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Nic(org.ovirt.engine.api.model.Nic)

Example 24 with Nic

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

the class BackendVmNicResource method activate.

@Override
public Response activate(Action action) {
    Nic nic = get();
    nic.setPlugged(true);
    update(nic);
    return actionSuccess(action);
}
Also used : Nic(org.ovirt.engine.api.model.Nic)

Example 25 with Nic

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

the class BackendVmNicsResource method list.

@Override
public Nics list() {
    Nics nics = new Nics();
    List<VmNetworkInterface> entities = getBackendCollection(QueryType.GetVmInterfacesByVmId, new IdQueryParameters(vmId));
    for (VmNetworkInterface entity : entities) {
        Nic nic = populate(map(entity), entity);
        nics.getNics().add(addLinks(nic));
    }
    return nics;
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Nic(org.ovirt.engine.api.model.Nic) Nics(org.ovirt.engine.api.model.Nics)

Aggregations

Nic (org.ovirt.engine.api.model.Nic)33 Test (org.junit.Test)11 WebApplicationException (javax.ws.rs.WebApplicationException)8 Vm (org.ovirt.engine.api.model.Vm)6 Nics (org.ovirt.engine.api.model.Nics)5 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 Response (javax.ws.rs.core.Response)3 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)3 ArrayList (java.util.ArrayList)2 Mac (org.ovirt.engine.api.model.Mac)2 Network (org.ovirt.engine.api.model.Network)2 ReportedDevices (org.ovirt.engine.api.model.ReportedDevices)2 VnicProfile (org.ovirt.engine.api.model.VnicProfile)2 SystemResource (org.ovirt.engine.api.resource.SystemResource)2 VmResource (org.ovirt.engine.api.resource.VmResource)2 VmsResource (org.ovirt.engine.api.resource.VmsResource)2 AddVmInterfaceParameters (org.ovirt.engine.core.common.action.AddVmInterfaceParameters)2 AddVmTemplateInterfaceParameters (org.ovirt.engine.core.common.action.AddVmTemplateInterfaceParameters)2 Comparator.comparing (java.util.Comparator.comparing)1 Objects (java.util.Objects)1