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();
}
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;
}
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;
}
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));
}
}
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);
}
}
Aggregations