Search in sources :

Example 1 with Vms

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

the class BackendAffinityLabelVmsResource method list.

@Override
public Vms list() {
    Vms vms = new Vms();
    List<Vm> list = vms.getVms();
    Label label = BackendAffinityLabelHelper.getLabel(this, labelId);
    label.getVms().stream().map(BackendAffinityLabelHelper::makeVmLink).forEach(list::add);
    return vms;
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Label(org.ovirt.engine.core.common.businessentities.Label) Vms(org.ovirt.engine.api.model.Vms)

Example 2 with Vms

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

the class BackendDiskResource method doPopulate.

@Override
protected Disk doPopulate(Disk model, org.ovirt.engine.core.common.businessentities.storage.Disk entity) {
    // Populate the references to the VMs that are using this disk:
    List<org.ovirt.engine.core.common.businessentities.VM> vms = new ArrayList<>(1);
    QueryReturnValue result = runQuery(QueryType.GetVmsByDiskGuid, new IdQueryParameters(entity.getId()));
    if (result.getSucceeded()) {
        Map<Boolean, List<org.ovirt.engine.core.common.businessentities.VM>> map = result.getReturnValue();
        if (MapUtils.isNotEmpty(map)) {
            for (List<org.ovirt.engine.core.common.businessentities.VM> list : map.values()) {
                vms.addAll(list);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(vms)) {
        Vms modelVms = new Vms();
        for (org.ovirt.engine.core.common.businessentities.VM vm : vms) {
            Vm modelVm = new Vm();
            modelVm.setId(vm.getId().toString());
            modelVms.getVms().add(modelVm);
        }
        model.setVms(modelVms);
    }
    return model;
}
Also used : ArrayList(java.util.ArrayList) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Vm(org.ovirt.engine.api.model.Vm) ArrayList(java.util.ArrayList) List(java.util.List) Vms(org.ovirt.engine.api.model.Vms)

Example 3 with Vms

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

the class BackendStorageDomainVmsResource method list.

@Override
public Vms list() {
    Vms vms = new Vms();
    boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED_CONSTRAINT_PARAMETER, true, false);
    if (unregistered) {
        List<org.ovirt.engine.core.common.businessentities.VM> unregisteredVms = getBackendCollection(QueryType.GetUnregisteredVms, new IdQueryParameters(storageDomainId));
        List<Vm> collection = new ArrayList<>();
        for (org.ovirt.engine.core.common.businessentities.VM entity : unregisteredVms) {
            Vm vm = map(entity);
            collection.add(addLinks(populate(vm, entity)));
        }
        vms.getVms().addAll(collection);
    } else {
        vms.getVms().addAll(getCollection());
    }
    return vms;
}
Also used : ArrayList(java.util.ArrayList) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Vm(org.ovirt.engine.api.model.Vm) Vms(org.ovirt.engine.api.model.Vms)

Example 4 with Vms

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

the class V3NICInAdapter method adapt.

@Override
public Nic adapt(V3NIC from) {
    Nic to = new Nic();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetBootProtocol()) {
        to.setBootProtocol(BootProtocol.fromValue(from.getBootProtocol()));
    }
    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.isSetInstanceType()) {
        to.setInstanceType(adaptIn(from.getInstanceType()));
    }
    if (from.isSetInterface()) {
        to.setInterface(NicInterface.fromValue(from.getInterface()));
    }
    if (from.isSetLinked()) {
        to.setLinked(from.isLinked());
    }
    if (from.isSetMac()) {
        to.setMac(adaptIn(from.getMac()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetNetwork()) {
        to.setNetwork(adaptIn(from.getNetwork()));
    }
    if (from.isSetOnBoot()) {
        to.setOnBoot(from.isOnBoot());
    }
    if (from.isSetPlugged()) {
        to.setPlugged(from.isPlugged());
    }
    if (from.isSetReportedDevices()) {
        to.setReportedDevices(new ReportedDevices());
        to.getReportedDevices().getReportedDevices().addAll(adaptIn(from.getReportedDevices().getReportedDevices()));
    }
    if (from.isSetStatistics()) {
        to.setStatistics(new Statistics());
        to.getStatistics().getStatistics().addAll(adaptIn(from.getStatistics().getStatistics()));
    }
    if (from.isSetTemplate()) {
        to.setTemplate(adaptIn(from.getTemplate()));
    }
    if (from.isSetVm()) {
        to.setVm(adaptIn(from.getVm()));
    }
    if (from.isSetVms()) {
        to.setVms(new Vms());
        to.getVms().getVms().addAll(adaptIn(from.getVms().getVMs()));
    }
    if (from.isSetVnicProfile()) {
        to.setVnicProfile(adaptIn(from.getVnicProfile()));
    }
    // In V3 the "active" property used to be a synonym of "plugged":
    if (from.isSetActive() && to.isSetPlugged()) {
        to.setPlugged(from.isActive());
    }
    return to;
}
Also used : Nic(org.ovirt.engine.api.model.Nic) ReportedDevices(org.ovirt.engine.api.model.ReportedDevices) Statistics(org.ovirt.engine.api.model.Statistics) Vms(org.ovirt.engine.api.model.Vms)

Example 5 with Vms

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

the class BackendVmsResource method mapCollection.

protected Vms mapCollection(List<org.ovirt.engine.core.common.businessentities.VM> entities) {
    Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
    boolean includeData = details.contains(DetailHelper.MAIN);
    boolean includeSize = details.contains("size");
    List<Guid> vmIds = entities.stream().map(VM::getId).collect(Collectors.toList());
    if (includeData) {
        // Fill VmInit for entities - the search query no join the VmInit to Vm
        IdsQueryParameters params = new IdsQueryParameters();
        params.setId(vmIds);
        QueryReturnValue queryReturnValue = runQuery(QueryType.GetVmsInit, params);
        if (queryReturnValue.getSucceeded() && queryReturnValue.getReturnValue() != null) {
            List<VmInit> vmInits = queryReturnValue.getReturnValue();
            Map<Guid, VmInit> initMap = Entities.businessEntitiesById(vmInits);
            for (org.ovirt.engine.core.common.businessentities.VM vm : entities) {
                vm.setVmInit(initMap.get(vm.getId()));
            }
        }
    }
    Vms collection = new Vms();
    if (includeData) {
        // optimization of DB access: retrieve GraphicsDevices for all VMs at once
        Map<Guid, List<GraphicsDevice>> vmsGraphicsDevices = DisplayHelper.getGraphicsDevicesForMultipleEntities(this, vmIds);
        for (org.ovirt.engine.core.common.businessentities.VM entity : entities) {
            Vm vm = map(entity);
            DisplayHelper.adjustDisplayData(this, vm, vmsGraphicsDevices, false);
            removeRestrictedInfo(vm);
            collection.getVms().add(addLinks(populate(vm, entity)));
        }
    }
    if (includeSize) {
        collection.setSize((long) entities.size());
    }
    return collection;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) IdsQueryParameters(org.ovirt.engine.core.common.queries.IdsQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) Vm(org.ovirt.engine.api.model.Vm) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Vms(org.ovirt.engine.api.model.Vms)

Aggregations

Vms (org.ovirt.engine.api.model.Vms)17 Vm (org.ovirt.engine.api.model.Vm)8 ArrayList (java.util.ArrayList)4 Guid (org.ovirt.engine.core.compat.Guid)4 List (java.util.List)3 Test (org.junit.Test)3 AffinityGroup (org.ovirt.engine.api.model.AffinityGroup)3 Statistics (org.ovirt.engine.api.model.Statistics)3 StorageDomains (org.ovirt.engine.api.model.StorageDomains)2 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 AffinityRule (org.ovirt.engine.api.model.AffinityRule)1 Cdrom (org.ovirt.engine.api.model.Cdrom)1 Cluster (org.ovirt.engine.api.model.Cluster)1 Disk (org.ovirt.engine.api.model.Disk)1 DiskSnapshot (org.ovirt.engine.api.model.DiskSnapshot)1 Disks (org.ovirt.engine.api.model.Disks)1 Floppy (org.ovirt.engine.api.model.Floppy)1