use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmResourceTest method testUpdateVmPolicySingleHostId.
@Test
public void testUpdateVmPolicySingleHostId() throws Exception {
setUpUdpateVm();
setUriInfo(setUpActionExpectations(ActionType.UpdateVm, VmManagementParametersBase.class, new String[] {}, new Object[] {}, true, true));
Vm model = getModel(0);
model.setPlacementPolicy(new VmPlacementPolicy());
model.getPlacementPolicy().setHosts(new Hosts());
model.getPlacementPolicy().getHosts().getHosts().add(new Host());
model.getPlacementPolicy().getHosts().getHosts().get(0).setId(GUIDS[1].toString());
verifyModel(resource.update(model), 0);
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmResourceTest method getModelClearingPayloads.
static Vm getModelClearingPayloads() {
Vm model = getModel(0);
model.setPayloads(new Payloads());
return model;
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmResourceTest method testUpdateMovingCluster.
@Test
public void testUpdateMovingCluster() throws Exception {
setUpGetEntityExpectations(3);
setUpGetPayloadExpectations(0, 2);
setUpGetBallooningExpectations();
setUpGetBallooningExpectations();
setUpGetConsoleExpectations(0);
setUpGetVmOvfExpectations(0);
setUpGetVirtioScsiExpectations(0);
setUpGetSoundcardExpectations(0);
setUpGetRngDeviceExpectations(0);
setUpGetGraphicsExpectations(2);
setUriInfo(setUpActionExpectations(ActionType.ChangeVMCluster, ChangeVMClusterParameters.class, new String[] { "ClusterId", "VmId" }, new Object[] { GUIDS[1], GUIDS[0] }, true, true, false));
setUpActionExpectations(ActionType.UpdateVm, VmManagementParametersBase.class, new String[] {}, new Object[] {}, true, true);
Vm model = getModel(0);
model.setId(GUIDS[0].toString());
model.setCluster(new org.ovirt.engine.api.model.Cluster());
model.getCluster().setId(GUIDS[1].toString());
verifyModelOnNewCluster(resource.update(model), 0);
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmsResource method add.
@Override
public Response add(Vm vm) {
validateParameters(vm, "cluster.id|name");
validateIconParameters(vm);
Response response = null;
if (vm.isSetInitialization() && vm.getInitialization().isSetConfiguration()) {
validateParameters(vm, "initialization.configuration.type", "initialization.configuration.data");
response = importVmFromConfiguration(vm);
} else {
validateParameters(vm, "name");
if (isCreateFromSnapshot(vm)) {
validateSnapshotExistence(vm);
response = createVmFromSnapshot(vm);
} else {
validateParameters(vm, "template.id|name");
Cluster cluster = getCluster(vm);
VmTemplate template = lookupTemplate(vm.getTemplate(), cluster.getStoragePoolId());
VmStatic builtFromTemplate = VmMapper.map(template, null, cluster.getCompatibilityVersion());
// since the template cpu_profile doesn't match cluster.
if (!vm.isSetCpuProfile() && vm.isSetCluster() && !Objects.equals(Objects.toString(template.getClusterId(), null), vm.getCluster().getId())) {
builtFromTemplate.setCpuProfileId(null);
}
VmStatic builtFromInstanceType = null;
InstanceType instanceTypeEntity = null;
if (vm.isSetInstanceType() && (vm.getInstanceType().isSetId() || vm.getInstanceType().isSetName())) {
instanceTypeEntity = lookupInstance(vm.getInstanceType());
builtFromInstanceType = VmMapper.map(instanceTypeEntity, builtFromTemplate, cluster.getCompatibilityVersion());
builtFromInstanceType.setInstanceTypeId(instanceTypeEntity.getId());
}
VmStatic staticVm = getMapper(Vm.class, VmStatic.class).map(vm, builtFromInstanceType != null ? builtFromInstanceType : builtFromTemplate);
if (namedCluster(vm)) {
staticVm.setClusterId(cluster.getId());
}
updateMaxMemoryIfUnspecified(vm, staticVm);
if (Guid.Empty.equals(template.getId()) && !vm.isSetOs()) {
staticVm.setOsId(OsRepository.AUTO_SELECT_OS);
}
staticVm.setUsbPolicy(VmMapper.getUsbPolicyOnCreate(vm.getUsb()));
if (!isFiltered() && vm.isSetPlacementPolicy()) {
Set<Guid> hostGuidsSet = validateAndUpdateHostsInPlacementPolicy(vm.getPlacementPolicy());
staticVm.setDedicatedVmForVdsList(new LinkedList<>(hostGuidsSet));
} else {
vm.setPlacementPolicy(null);
}
// migration support (disabling it in architectures that do not support this feature)
if (!vm.isSetPlacementPolicy() && template.getId().equals(Guid.Empty)) {
staticVm.setMigrationSupport(null);
}
Guid storageDomainId = (vm.isSetStorageDomain() && vm.getStorageDomain().isSetId()) ? asGuid(vm.getStorageDomain().getId()) : Guid.Empty;
boolean clone = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, CLONE, true, false);
if (clone) {
response = cloneVmFromTemplate(staticVm, vm, template, instanceTypeEntity, cluster);
} else if (Guid.Empty.equals(template.getId())) {
response = addVmFromScratch(staticVm, vm, instanceTypeEntity, cluster);
} else {
response = addVm(staticVm, vm, storageDomainId, template, instanceTypeEntity, cluster);
}
}
}
Vm result = (Vm) response.getEntity();
if (result != null) {
DisplayHelper.adjustDisplayData(this, result, false);
removeRestrictedInfo(result);
}
return response;
}
use of org.ovirt.engine.api.model.Vm 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