Search in sources :

Example 1 with MemoryPolicy

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

the class VmBaseMapper method mapCommonEntityToModel.

/**
 * Common for VM, template and instance type
 */
protected static void mapCommonEntityToModel(VmBase model, org.ovirt.engine.core.common.businessentities.VmBase entity) {
    model.setId(entity.getId().toString());
    model.setName(entity.getName());
    model.setDescription(entity.getDescription());
    model.setMemory((long) entity.getMemSizeMb() * BYTES_PER_MB);
    Io io = model.getIo();
    if (io == null) {
        io = new Io();
        model.setIo(io);
    }
    io.setThreads(entity.getNumOfIoThreads());
    if (entity.getCreationDate() != null) {
        model.setCreationTime(DateMapper.map(entity.getCreationDate(), null));
    }
    if (entity.getUsbPolicy() != null) {
        Usb usb = new Usb();
        usb.setEnabled(UsbMapperUtils.getIsUsbEnabled(entity.getUsbPolicy()));
        UsbType usbType = UsbMapperUtils.getUsbType(entity.getUsbPolicy());
        if (usbType != null) {
            usb.setType(usbType);
        }
        model.setUsb(usb);
    }
    CpuTopology topology = new CpuTopology();
    topology.setSockets(entity.getNumOfSockets());
    topology.setCores(entity.getCpuPerSocket());
    topology.setThreads(entity.getThreadsPerCpu());
    model.setCpu(new Cpu());
    model.getCpu().setTopology(topology);
    model.setHighAvailability(new HighAvailability());
    model.getHighAvailability().setEnabled(entity.isAutoStartup());
    model.getHighAvailability().setPriority(entity.getPriority());
    model.setMigrationDowntime(mapNullToMinusOne(entity.getMigrationDowntime()));
    model.setMigration(MigrationOptionsMapper.map(entity, null));
    if (entity.getCustomEmulatedMachine() != null) {
        model.setCustomEmulatedMachine(entity.getCustomEmulatedMachine());
    }
    if (entity.getCustomCpuName() != null) {
        model.setCustomCpuModel(entity.getCustomCpuName());
    }
    MemoryPolicy policy = new MemoryPolicy();
    policy.setGuaranteed((long) entity.getMinAllocatedMem() * (long) BYTES_PER_MB);
    policy.setMax((long) entity.getMaxMemorySizeMb() * (long) BYTES_PER_MB);
    model.setMemoryPolicy(policy);
    if (entity.getCustomCompatibilityVersion() != null) {
        model.setCustomCompatibilityVersion(VersionMapper.map(entity.getCustomCompatibilityVersion()));
    }
    model.setLease(StorageDomainLeaseMapper.map(entity.getLeaseStorageDomainId()));
    if (model.getPlacementPolicy() == null) {
        model.setPlacementPolicy(new VmPlacementPolicy());
    }
    VmAffinity vmAffinity = map(entity.getMigrationSupport(), null);
    if (vmAffinity != null) {
        model.getPlacementPolicy().setAffinity(vmAffinity);
    }
    if (!entity.getDedicatedVmForVdsList().isEmpty()) {
        Hosts hostsList = new Hosts();
        for (Guid hostGuid : entity.getDedicatedVmForVdsList()) {
            Host newHost = new Host();
            newHost.setId(hostGuid.toString());
            hostsList.getHosts().add(newHost);
        }
        model.getPlacementPolicy().setHosts(hostsList);
    }
}
Also used : CpuTopology(org.ovirt.engine.api.model.CpuTopology) Hosts(org.ovirt.engine.api.model.Hosts) Usb(org.ovirt.engine.api.model.Usb) UsbType(org.ovirt.engine.api.model.UsbType) Io(org.ovirt.engine.api.model.Io) MemoryPolicy(org.ovirt.engine.api.model.MemoryPolicy) Cpu(org.ovirt.engine.api.model.Cpu) HighAvailability(org.ovirt.engine.api.model.HighAvailability) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy) VmAffinity(org.ovirt.engine.api.model.VmAffinity)

Example 2 with MemoryPolicy

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

the class MemoryPolicyHelper method setupMemoryBalloon.

public static void setupMemoryBalloon(VmBase vmBase, BackendResource parentResource) {
    Boolean balloonEnabled = parentResource.getEntity(Boolean.class, QueryType.IsBalloonEnabled, new IdQueryParameters(new Guid(vmBase.getId())), null, true);
    if (!vmBase.isSetMemoryPolicy()) {
        vmBase.setMemoryPolicy(new MemoryPolicy());
    }
    vmBase.getMemoryPolicy().setBallooning(balloonEnabled);
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) MemoryPolicy(org.ovirt.engine.api.model.MemoryPolicy) Guid(org.ovirt.engine.core.compat.Guid)

Example 3 with MemoryPolicy

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

the class ClusterMapper method map.

@Mapping(from = Cluster.class, to = MemoryPolicy.class)
public static MemoryPolicy map(Cluster entity, MemoryPolicy template) {
    MemoryPolicy model = template != null ? template : new MemoryPolicy();
    model.setOverCommit(new MemoryOverCommit());
    model.getOverCommit().setPercent(entity.getMaxVdsMemoryOverCommit());
    model.setTransparentHugepages(new TransparentHugePages());
    model.getTransparentHugepages().setEnabled(entity.getTransparentHugepages());
    return model;
}
Also used : MemoryOverCommit(org.ovirt.engine.api.model.MemoryOverCommit) MemoryPolicy(org.ovirt.engine.api.model.MemoryPolicy) TransparentHugePages(org.ovirt.engine.api.model.TransparentHugePages)

Aggregations

MemoryPolicy (org.ovirt.engine.api.model.MemoryPolicy)3 Guid (org.ovirt.engine.core.compat.Guid)2 Cpu (org.ovirt.engine.api.model.Cpu)1 CpuTopology (org.ovirt.engine.api.model.CpuTopology)1 HighAvailability (org.ovirt.engine.api.model.HighAvailability)1 Host (org.ovirt.engine.api.model.Host)1 Hosts (org.ovirt.engine.api.model.Hosts)1 Io (org.ovirt.engine.api.model.Io)1 MemoryOverCommit (org.ovirt.engine.api.model.MemoryOverCommit)1 TransparentHugePages (org.ovirt.engine.api.model.TransparentHugePages)1 Usb (org.ovirt.engine.api.model.Usb)1 UsbType (org.ovirt.engine.api.model.UsbType)1 VmAffinity (org.ovirt.engine.api.model.VmAffinity)1 VmPlacementPolicy (org.ovirt.engine.api.model.VmPlacementPolicy)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1