use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class BackendVmResourceTest method testCloneVm.
@Test
public void testCloneVm() throws Exception {
org.ovirt.engine.core.common.businessentities.VM mockedVm = mock(org.ovirt.engine.core.common.businessentities.VM.class);
VmStatic vmStatic = mock(VmStatic.class);
when(mockedVm.getStaticData()).thenReturn(vmStatic);
setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, mockedVm);
setUriInfo(setUpActionExpectations(ActionType.CloneVm, CloneVmParameters.class, new String[] { "VmStaticData", "NewName" }, new Object[] { vmStatic, "someNewName" }));
Action action = new Action();
Vm vm = new Vm();
vm.setName("someNewName");
action.setVm(vm);
Response response = resource.doClone(action);
verifyActionResponse(response);
Action actionResponse = (Action) response.getEntity();
assertTrue(actionResponse.isSetStatus());
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class VdsEventListener method vdsUpEvent.
@Override
public boolean vdsUpEvent(final VDS vds) {
HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(vds);
CommandContext commandContext = new CommandContext(new EngineContext()).withoutExecutionContext();
commandContext.getExecutionContext().setJobRequired(true);
boolean isSucceeded = backend.runInternalAction(ActionType.InitVdsOnUp, params, commandContext).getSucceeded();
if (isSucceeded) {
ThreadPoolUtil.execute(() -> {
try {
// migrate vms that its their default vds and failback
// is on
List<VmStatic> vmsToMigrate = vmStaticDao.getAllWithFailbackByVds(vds.getId());
if (!vmsToMigrate.isEmpty()) {
CommandContext ctx = new CommandContext(new EngineContext());
ctx.getExecutionContext().setMonitored(true);
backend.runInternalMultipleActions(ActionType.MigrateVmToServer, new ArrayList<>(createMigrateVmToServerParametersList(vmsToMigrate, vds, null)), ctx);
}
} catch (RuntimeException e) {
log.error("Failed to initialize Vds on up: {}", e.getMessage());
log.error("Exception", e);
}
});
}
return isSucceeded;
}
use of org.ovirt.engine.core.common.businessentities.VmStatic 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.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class BackendVmPoolsResource method mapToVM.
protected VM mapToVM(VmPool model, VmTemplate template, Cluster cluster) {
// apply template
VmStatic fromTemplate = getMapper(VmTemplate.class, VmStatic.class).map(template, null);
VmStatic fromInstanceType = null;
if (model.isSetInstanceType()) {
org.ovirt.engine.core.common.businessentities.InstanceType instanceType = loadInstanceType(model);
fromTemplate.setInstanceTypeId(instanceType.getId());
fromInstanceType = VmMapper.map(instanceType, fromTemplate, cluster.getCompatibilityVersion());
fromInstanceType.setInstanceTypeId(instanceType.getId());
}
// override with client-provided data
VM vm = new VM(getMapper(VmPool.class, VmStatic.class).map(model, fromInstanceType != null ? fromInstanceType : fromTemplate), new VmDynamic(), new VmStatistics());
return vm;
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class BackendTemplatesResource method add.
@Override
public Response add(Template template) {
validateParameters(template, "name", "vm.id|name");
validateIconParameters(template);
Guid clusterId = null;
Cluster cluster = null;
if (namedCluster(template)) {
clusterId = getClusterId(template);
cluster = lookupCluster(clusterId);
}
if (template.getVersion() != null) {
validateParameters(template.getVersion(), "baseTemplate");
}
VmStatic originalVm = getVm(cluster, template);
VmStatic staticVm = getMapper(Template.class, VmStatic.class).map(template, originalVm);
if (namedCluster(template)) {
staticVm.setClusterId(clusterId);
}
// REVISIT: powershell has a IsVmTemlateWithSameNameExist safety check
AddVmTemplateParameters params = new AddVmTemplateParameters(staticVm, template.getName(), template.getDescription());
if (template.getVersion() != null) {
params.setBaseTemplateId(Guid.createGuidFromString(template.getVersion().getBaseTemplate().getId()));
params.setTemplateVersionName(template.getVersion().getVersionName());
}
params.setConsoleEnabled(template.getConsole() != null && template.getConsole().isSetEnabled() ? template.getConsole().isEnabled() : !getConsoleDevicesForEntity(originalVm.getId()).isEmpty());
params.setVirtioScsiEnabled(template.isSetVirtioScsi() && template.getVirtioScsi().isSetEnabled() ? template.getVirtioScsi().isEnabled() : null);
if (template.isSetSoundcardEnabled()) {
params.setSoundDeviceEnabled(template.isSoundcardEnabled());
} else {
params.setSoundDeviceEnabled(!VmHelper.getSoundDevicesForEntity(this, originalVm.getId()).isEmpty());
}
if (template.isSetRngDevice()) {
params.setUpdateRngDevice(true);
params.setRngDevice(RngDeviceMapper.map(template.getRngDevice(), null));
}
DisplayHelper.setGraphicsToParams(template.getDisplay(), params);
boolean isDomainSet = false;
if (template.isSetStorageDomain() && template.getStorageDomain().isSetId()) {
params.setDestinationStorageDomainId(asGuid(template.getStorageDomain().getId()));
isDomainSet = true;
}
params.setDiskInfoDestinationMap(getDestinationTemplateDiskMap(template.getVm(), originalVm.getId(), params.getDestinationStorageDomainId(), isDomainSet));
setupOptionalParameters(params);
IconHelper.setIconToParams(template, params);
Response response = performCreate(ActionType.AddVmTemplate, params, new QueryIdResolver<Guid>(QueryType.GetVmTemplate, GetVmTemplateParameters.class));
Template result = (Template) response.getEntity();
if (result != null) {
DisplayHelper.adjustDisplayData(this, result);
}
return response;
}
Aggregations