use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method createDiskDummiesForSpaceValidations.
/**
* Space Validations are done using data extracted from the disks. The disks in question in this command
* don't have all the needed data, and in order not to contaminate the command's data structures, an alter
* one is created specifically for this validation - hence dummy.
*/
private List<DiskImage> createDiskDummiesForSpaceValidations(Collection<DiskImage> disksList) {
List<DiskImage> dummies = new ArrayList<>(disksList.size());
for (DiskImage image : disksList) {
Guid targetSdId = diskInfoDestinationMap.get(image.getId()).getStorageIds().get(0);
DiskImage dummy = imagesHandler.createDiskImageWithExcessData(image, targetSdId);
dummies.add(dummy);
}
return dummies;
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method getPermissionCheckSubjects.
/**
* in case of non-existing cluster the backend query will return a null
*/
@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
if (permissionCheckSubject == null) {
permissionCheckSubject = new ArrayList<>();
if (getParameters().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
Guid storagePoolId = getCluster() == null ? null : getCluster().getStoragePoolId();
permissionCheckSubject.add(new PermissionSubject(storagePoolId, VdcObjectType.StoragePool, getActionType().getActionGroup()));
// host-specific parameters can be changed by administration role only
if (!new HashSet<>(getParameters().getMasterVm().getDedicatedVmForVdsList()).equals(new HashSet<>(getVm().getDedicatedVmForVdsList())) || !StringUtils.isEmpty(getParameters().getMasterVm().getCpuPinning())) {
permissionCheckSubject.add(new PermissionSubject(storagePoolId, VdcObjectType.StoragePool, ActionGroup.EDIT_ADMIN_TEMPLATE_PROPERTIES));
}
} else {
permissionCheckSubject.add(new PermissionSubject(Guid.SYSTEM, VdcObjectType.System, getActionType().getActionGroup()));
}
}
return permissionCheckSubject;
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method executeCommand.
@Override
protected void executeCommand() {
// relevant only if template created from vm
if (isVmInDb) {
VmDynamic vmDynamic = vmDynamicDao.get(getVmId());
if (!isVmStatusValid(vmDynamic.getStatus())) {
throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
}
vmHandler.lockVm(vmDynamic, getCompensationContext());
}
setActionReturnValue(Guid.Empty);
// set template id as base for new templates
if (!isTemplateVersion()) {
getParameters().setBaseTemplateId(getVmTemplateId());
if (StringUtils.isEmpty(getParameters().getTemplateVersionName())) {
getParameters().setTemplateVersionName(BASE_TEMPLATE_VERSION_NAME);
}
} else {
// template version name should be the same as the base template name
setVmTemplateName(getBaseTemplate().getName());
String jobId = updateVmsJobHashMap.remove(getParameters().getBaseTemplateId());
if (!StringUtils.isEmpty(jobId)) {
log.info("Cancelling current running update for vms for base template id '{}'", getParameters().getBaseTemplateId());
try {
updateVmsJobMap.remove(getParameters().getBaseTemplateId()).cancel(true);
} catch (Exception e) {
log.warn("Failed deleting job '{}' at cancelRecoveryJob", jobId);
}
}
}
TransactionSupport.executeInNewTransaction(() -> {
addVmTemplateToDb();
getCompensationContext().stateChanged();
return null;
});
final Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping = addAllTemplateDisks();
srcDeviceIdToTargetDeviceIdMapping.forEach((oldImageId, newImageId) -> addTemplateDiskVmElement(newImageId, oldImageId));
TransactionSupport.executeInNewTransaction(() -> {
addPermission();
addVmInterfaces(srcDeviceIdToTargetDeviceIdMapping);
Set<GraphicsType> graphicsToSkip = getParameters().getGraphicsDevices().keySet();
if (isVmInDb) {
getVmDeviceUtils().copyVmDevices(getVmId(), getVmTemplateId(), srcDeviceIdToTargetDeviceIdMapping, getParameters().isSoundDeviceEnabled(), getParameters().isConsoleEnabled(), getParameters().isVirtioScsiEnabled(), getVmDeviceUtils().hasMemoryBalloon(getVmId()), graphicsToSkip, false, getEffectiveCompatibilityVersion());
} else {
// for instance type and new template without a VM
getVmDeviceUtils().copyVmDevices(VmTemplateHandler.BLANK_VM_TEMPLATE_ID, getVmTemplateId(), srcDeviceIdToTargetDeviceIdMapping, getParameters().isSoundDeviceEnabled(), getParameters().isConsoleEnabled(), getParameters().isVirtioScsiEnabled(), Boolean.TRUE.equals(getParameters().isBalloonEnabled()), graphicsToSkip, false, getEffectiveCompatibilityVersion());
}
updateWatchdog(getVmTemplateId());
updateRngDevice(getVmTemplateId());
addGraphicsDevice();
setSucceeded(true);
return null;
});
if (getParameters().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
vmHandler.warnMemorySizeLegal(getVmTemplate(), getVm().getCompatibilityVersion());
}
// means that there are no asynchronous tasks to execute and that we can
// end the command synchronously
pendingAsyncTasks = !getReturnValue().getVdsmTaskIdList().isEmpty() || !commandCoordinatorUtil.getChildCommandIds(getCommandId()).isEmpty();
if (!pendingAsyncTasks) {
endSuccessfullySynchronous();
}
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ImportVmCommandBase method createDiskDummiesForSpaceValidations.
/**
* Space Validations are done using data extracted from the disks. The disks in question in this command
* don't have all the needed data, and in order not to contaminate the command's data structures, an alter
* one is created specifically fo this validation - hence dummy.
*/
protected List<DiskImage> createDiskDummiesForSpaceValidations(List<DiskImage> disksList) {
List<DiskImage> dummies = new ArrayList<>(disksList.size());
for (DiskImage image : disksList) {
Guid targetSdId = imageToDestinationDomainMap.get(image.getId());
DiskImage dummy = imagesHandler.createDiskImageWithExcessData(image, targetSdId);
dummies.add(dummy);
}
return dummies;
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ImportVmCommandBase method generateNewDiskId.
/**
* Cloning a new disk with a new generated id, with the same parameters as <code>disk</code>. Also
* adding the disk to <code>newDiskGuidForDisk</code> map, so we will be able to link between the new cloned disk
* and the old disk id.
*
* @param disk
* - The disk which is about to be cloned
*/
protected Guid generateNewDiskId(DiskImage disk) {
Guid newGuidForDisk = Guid.newGuid();
// Copy the disk so it will preserve the old disk id and image id.
newDiskIdForDisk.put(newGuidForDisk, DiskImage.copyOf(disk));
disk.setId(newGuidForDisk);
disk.setImageId(Guid.newGuid());
return newGuidForDisk;
}
Aggregations