Search in sources :

Example 11 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmHandler method getVmInitWithoutPasswordByIds.

public List<VmInit> getVmInitWithoutPasswordByIds(List<Guid> ids) {
    List<VmInit> all = vmInitDao.getVmInitByIds(ids);
    for (VmInit vmInit : all) {
        vmInit.setPasswordAlreadyStored(!StringUtils.isEmpty(vmInit.getRootPassword()));
        vmInit.setRootPassword(null);
    }
    return all;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Example 12 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit 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)

Example 13 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class BackendTemplatesResource method mapCollection.

protected Templates mapCollection(List<VmTemplate> entities) {
    Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
    boolean includeData = details.contains(DetailHelper.MAIN);
    boolean includeSize = details.contains("size");
    if (includeData) {
        // Fill VmInit for entities - the search query no join the VmInit to Templates
        IdsQueryParameters params = new IdsQueryParameters();
        List<Guid> ids = entities.stream().map(VmTemplate::getId).collect(Collectors.toList());
        params.setId(ids);
        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 (VmTemplate template : entities) {
                template.setVmInit(initMap.get(template.getId()));
            }
        }
    }
    Templates collection = new Templates();
    if (includeData) {
        for (VmTemplate entity : entities) {
            Template template = map(entity);
            collection.getTemplates().add(addLinks(populate(template, entity)));
            DisplayHelper.adjustDisplayData(this, template);
        }
    }
    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) Templates(org.ovirt.engine.api.model.Templates) Guid(org.ovirt.engine.core.compat.Guid) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 14 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method testGetWithInvalidId.

/**
 * Ensures that get requires a valid id.
 */
@Test
public void testGetWithInvalidId() {
    VmInit result = vmInitDao.get(Guid.newGuid());
    assertNull(result);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Test(org.junit.Test)

Example 15 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    vmInitDao = dbFacade.getVmInitDao();
    vmInit = new VmInit();
    vmInit.setId(EXISTING_VM);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Aggregations

VmInit (org.ovirt.engine.core.common.businessentities.VmInit)34 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)14 Pair (org.ovirt.engine.core.common.utils.Pair)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 Guid (org.ovirt.engine.core.compat.Guid)3 List (java.util.List)2 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)2 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Before (org.junit.Before)1