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