Search in sources :

Example 76 with Host

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

the class BackendAffinityLabelHostsResource method add.

@Override
public Response add(Host model) {
    validateParameters(model, "id");
    Label label = BackendAffinityLabelHelper.getLabel(this, labelId);
    VDS entity = new VDS();
    entity.setId(GuidUtils.asGuid(model.getId()));
    Label updatedLabel = new LabelBuilder(label).entity(entity).build();
    // The command used to add the host to the label returns the label, but we need to return the virtual machine,
    // so we ignore the result and return a link to the added host:
    LabelActionParameters updateParams = new LabelActionParameters(updatedLabel);
    try {
        doAction(ActionType.UpdateLabel, updateParams);
    } catch (BackendFailureException exception) {
        handleError(exception, false);
    }
    Host result = BackendAffinityLabelHelper.makeHostLink(entity.getId());
    return Response.ok(Response.Status.CREATED).entity(result).build();
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Host(org.ovirt.engine.api.model.Host)

Example 77 with Host

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

the class AbstractBaseHostNicLabelsResource method addParents.

@Override
protected NetworkLabel addParents(NetworkLabel model) {
    model.setHostNic(new HostNic());
    model.getHostNic().setId(nicId.toString());
    model.getHostNic().setHost(new Host());
    model.getHostNic().getHost().setId(hostId);
    return model;
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) Host(org.ovirt.engine.api.model.Host)

Example 78 with Host

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

the class V3VmPlacementPolicyOutAdapter method adapt.

@Override
public V3VmPlacementPolicy adapt(VmPlacementPolicy from) {
    V3VmPlacementPolicy to = new V3VmPlacementPolicy();
    if (from.isSetAffinity()) {
        to.setAffinity(from.getAffinity().value());
    }
    if (from.isSetHosts()) {
        to.setHosts(new V3Hosts());
        to.getHosts().getHosts().addAll(adaptOut(from.getHosts().getHosts()));
        // V3 allowed specifying only one host, using the "host" element instead of "hosts":
        List<Host> hosts = from.getHosts().getHosts();
        if (hosts.size() == 1) {
            V3Host host = adaptOut(hosts.get(0));
            to.setHost(host);
        }
    }
    return to;
}
Also used : V3Host(org.ovirt.engine.api.v3.types.V3Host) V3Hosts(org.ovirt.engine.api.v3.types.V3Hosts) V3VmPlacementPolicy(org.ovirt.engine.api.v3.types.V3VmPlacementPolicy) V3Host(org.ovirt.engine.api.v3.types.V3Host) Host(org.ovirt.engine.api.model.Host)

Example 79 with Host

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

the class VmBaseMapper method mapCommonModelToEntity.

/**
 * Common for VM, template and instance type
 */
protected static void mapCommonModelToEntity(org.ovirt.engine.core.common.businessentities.VmBase entity, VmBase model) {
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetMemory()) {
        entity.setMemSizeMb((int) (model.getMemory() / BYTES_PER_MB));
    }
    if (model.isSetIo() && model.getIo().isSetThreads()) {
        entity.setNumOfIoThreads(model.getIo().getThreads());
    }
    if (model.isSetDescription()) {
        entity.setDescription(model.getDescription());
    }
    if (model.isSetCpu() && model.getCpu().isSetTopology()) {
        if (model.getCpu().getTopology().getCores() != null) {
            entity.setCpuPerSocket(model.getCpu().getTopology().getCores());
        }
        if (model.getCpu().getTopology().getSockets() != null) {
            entity.setNumOfSockets(model.getCpu().getTopology().getSockets());
        }
        if (model.getCpu().getTopology().getThreads() != null) {
            entity.setThreadsPerCpu(model.getCpu().getTopology().getThreads());
        }
    }
    if (model.isSetHighAvailability()) {
        if (model.getHighAvailability().isSetEnabled()) {
            entity.setAutoStartup(model.getHighAvailability().isEnabled());
        }
        if (model.getHighAvailability().isSetPriority()) {
            entity.setPriority(model.getHighAvailability().getPriority());
        }
    }
    if (model.isSetDisplay()) {
        if (model.getDisplay().isSetType()) {
            // let backend decide which video device to use
            entity.setDefaultDisplayType(null);
        }
        if (model.getDisplay().isSetMonitors()) {
            entity.setNumOfMonitors(model.getDisplay().getMonitors());
        }
        if (model.getDisplay().isSetSingleQxlPci()) {
            entity.setSingleQxlPci(model.getDisplay().isSingleQxlPci());
        }
        if (model.getDisplay().isSetSmartcardEnabled()) {
            entity.setSmartcardEnabled(model.getDisplay().isSmartcardEnabled());
        }
    }
    if (model.isSetMigrationDowntime()) {
        entity.setMigrationDowntime(mapMinusOneToNull(model.getMigrationDowntime()));
    }
    if (model.isSetMigration()) {
        MigrationOptionsMapper.copyMigrationOptions(model.getMigration(), entity);
    }
    if (model.isSetCustomCpuModel()) {
        entity.setCustomCpuName(model.getCustomCpuModel());
    }
    if (model.isSetCustomEmulatedMachine()) {
        entity.setCustomEmulatedMachine(model.getCustomEmulatedMachine());
    }
    if (model.isSetMemoryPolicy() && model.getMemoryPolicy().isSetGuaranteed()) {
        Long memGuaranteed = model.getMemoryPolicy().getGuaranteed() / BYTES_PER_MB;
        entity.setMinAllocatedMem(memGuaranteed.intValue());
    }
    if (model.isSetMemoryPolicy() && model.getMemoryPolicy().isSetMax()) {
        Long maxMemory = model.getMemoryPolicy().getMax() / BYTES_PER_MB;
        entity.setMaxMemorySizeMb(maxMemory.intValue());
    }
    if (model.isSetOs()) {
        Boot boot = model.getOs().getBoot();
        if (boot != null && boot.isSetDevices() && boot.getDevices().isSetDevices()) {
            entity.setDefaultBootSequence(VmMapper.map(model.getOs().getBoot(), null));
        }
    }
    if (model.isSetCustomCompatibilityVersion()) {
        Version entityMappedVersion = VersionMapper.map(model.getCustomCompatibilityVersion());
        entity.setCustomCompatibilityVersion(entityMappedVersion.isNotValid() ? null : entityMappedVersion);
    }
    if (model.isSetLease()) {
        entity.setLeaseStorageDomainId(StorageDomainLeaseMapper.map(model.getLease()));
    }
    if (model.isSetPlacementPolicy()) {
        if (model.getPlacementPolicy().isSetAffinity()) {
            // read migration policy
            entity.setMigrationSupport(map(model.getPlacementPolicy().getAffinity(), null));
        }
        // reset previous dedicated host or hosts
        Set<Guid> hostGuidsSet = new HashSet<>();
        // read multiple hosts if there are few
        if (model.getPlacementPolicy().isSetHosts() && model.getPlacementPolicy().getHosts().getHosts().size() > 0) {
            for (Host currHost : model.getPlacementPolicy().getHosts().getHosts()) {
                Guid hostGuid;
                if (currHost.isSetId()) {
                    hostGuid = Guid.createGuidFromString(currHost.getId());
                } else {
                    continue;
                }
                hostGuidsSet.add(hostGuid);
            }
        }
        entity.setDedicatedVmForVdsList(new LinkedList<>(hostGuidsSet));
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) Boot(org.ovirt.engine.api.model.Boot) HashSet(java.util.HashSet)

Example 80 with Host

use of org.ovirt.engine.api.model.Host 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)

Aggregations

Host (org.ovirt.engine.api.model.Host)114 Test (org.junit.Test)58 Vm (org.ovirt.engine.api.model.Vm)21 Response (javax.ws.rs.core.Response)15 Hosts (org.ovirt.engine.api.model.Hosts)15 StorageDomain (org.ovirt.engine.api.model.StorageDomain)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 VDS (org.ovirt.engine.core.common.businessentities.VDS)12 VmPlacementPolicy (org.ovirt.engine.api.model.VmPlacementPolicy)11 Guid (org.ovirt.engine.core.compat.Guid)10 Cluster (org.ovirt.engine.api.model.Cluster)7 HostNic (org.ovirt.engine.api.model.HostNic)6 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)5 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 AffinityGroup (org.ovirt.engine.api.model.AffinityGroup)3 HostStorage (org.ovirt.engine.api.model.HostStorage)3 HostType (org.ovirt.engine.api.model.HostType)3 Spm (org.ovirt.engine.api.model.Spm)3