use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class AddDiskCommand method validate.
@Override
protected boolean validate() {
if (!isFloatingDisk() && (!validate(new VmValidator(getVm()).isVmExists()) || !validateDiskVmData())) {
return false;
}
Disk diskInfo = getParameters().getDiskInfo();
if (diskInfo.getDiskStorageType() == DiskStorageType.IMAGE || diskInfo.getDiskStorageType() == DiskStorageType.CINDER) {
getDiskImageInfo().setDiskSnapshot(false);
}
VM vm = getVm();
DiskValidator diskValidator = getDiskValidator(getParameters().getDiskInfo());
DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getParameters().getDiskInfo(), getDiskVmElement());
if (vm != null) {
if (!validateDiskVmData() || !canRunActionOnNonManagedVm()) {
return false;
}
updateDisksFromDb();
if (getDiskVmElement().isBoot() && !validate(diskValidator.isVmNotContainsBootDisk(vm))) {
return false;
}
if (!validatePassDiscardSupported(diskVmElementValidator)) {
return false;
}
// if user sent drive check that its not in use
if (!isDiskPassPciAndIdeLimit()) {
return false;
}
if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
return false;
}
} else if (Boolean.TRUE.equals(getParameters().getPlugDiskToVm())) {
return failValidation(EngineMessage.CANNOT_ADD_FLOATING_DISK_WITH_PLUG_VM_SET);
}
if (!validateQuota()) {
return false;
}
if (DiskStorageType.IMAGE == getParameters().getDiskInfo().getDiskStorageType()) {
if (!checkIfImageDiskCanBeAdded(vm, diskVmElementValidator)) {
return false;
}
return setAndValidateDiskProfiles();
}
if (DiskStorageType.LUN == getParameters().getDiskInfo().getDiskStorageType()) {
return checkIfLunDiskCanBeAdded(diskValidator);
}
if (DiskStorageType.CINDER == getParameters().getDiskInfo().getDiskStorageType()) {
CinderDisk cinderDisk = (CinderDisk) getParameters().getDiskInfo();
cinderDisk.setStorageIds(new ArrayList<>(Collections.singletonList(getStorageDomainId())));
StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisk);
return validate(storageDomainValidator.isDomainExistAndActive()) && validate(cinderDisksValidator.validateCinderDiskLimits()) && validate(cinderDisksValidator.validateCinderVolumeTypesExist());
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class CreateAllTemplateDisksCommand method addVmTemplateCinderDisks.
private boolean addVmTemplateCinderDisks(Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping) {
List<CinderDisk> cinderDisks = getCinderDisks();
if (cinderDisks.isEmpty()) {
return true;
}
// Create Cinder disk templates
Map<Guid, Guid> diskImageMap = new HashMap<>();
for (CinderDisk cinderDisk : cinderDisks) {
ImagesContainterParametersBase params = buildCloneCinderDiskCommandParameters(cinderDisk);
ActionReturnValue returnValue = runInternalAction(ActionType.CloneSingleCinderDisk, params, cloneContext().withoutExecutionContext().withoutLock());
if (!returnValue.getSucceeded()) {
log.error("Error cloning Cinder disk '{}'", cinderDisk.getDiskAlias());
getReturnValue().setFault(returnValue.getFault());
return false;
}
Guid imageId = returnValue.getActionReturnValue();
diskImageMap.put(cinderDisk.getId(), imageId);
}
srcDeviceIdToTargetDeviceIdMapping.putAll(diskImageMap);
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class AbstractDiskVmCommand method performPlugCommand.
protected void performPlugCommand(VDSCommandType commandType, Disk disk, VmDevice vmDevice) {
if (disk.getDiskStorageType() == DiskStorageType.LUN) {
LunDisk lunDisk = (LunDisk) disk;
if (commandType == VDSCommandType.HotPlugDisk) {
LUNs lun = lunDisk.getLun();
updateLUNConnectionsInfo(lun);
lun.getLunConnections().stream().map(StorageServerConnections::getStorageType).distinct().forEach(t -> {
if (!getStorageHelper(t).connectStorageToLunByVdsId(null, getVm().getRunOnVds(), lun, getVm().getStoragePoolId())) {
throw new EngineException(EngineError.StorageServerConnectionError);
}
});
}
} else if (disk.getDiskStorageType() == DiskStorageType.CINDER) {
CinderDisk cinderDisk = (CinderDisk) disk;
setStorageDomainId(cinderDisk.getStorageIds().get(0));
getCinderBroker().updateConnectionInfoForDisk(cinderDisk);
}
Map<String, String> diskAddressMap = getDiskAddressMap(vmDevice, getDiskVmElement().getDiskInterface());
runVdsCommand(commandType, new HotPlugDiskVDSParameters(getVm().getRunOnVds(), getVm(), disk, vmDevice, diskAddressMap, getDiskVmElement().getDiskInterface(), getDiskVmElement().isPassDiscard()));
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class CinderBroker method volumeToCinderDisk.
public static CinderDisk volumeToCinderDisk(Volume volume, Guid storageDomainId) {
CinderDisk cinderDisk = new CinderDisk();
cinderDisk.setId(Guid.createGuidFromString(volume.getId()));
cinderDisk.setImageId(Guid.createGuidFromString(volume.getId()));
cinderDisk.setDiskAlias(volume.getName());
cinderDisk.setDescription(volume.getDescription());
cinderDisk.setSizeInGigabytes(volume.getSize());
cinderDisk.setCinderVolumeType(volume.getVolumeType());
cinderDisk.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));
cinderDisk.setActive(true);
cinderDisk.setImageStatus(ImageStatus.OK);
cinderDisk.setVolumeFormat(VolumeFormat.RAW);
try {
cinderDisk.setCreationDate(new SimpleDateFormat(DATE_FORMAT).parse(volume.getCreatedAt()));
} catch (ParseException e) {
cinderDisk.setCreationDate(null);
log.error("Invalid disk creation date format, id: '{}' (info: {})", volume.getId(), e.getMessage());
}
return cinderDisk;
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class CloneSingleCinderDiskCommandCallback method childCommandsExecutionEnded.
@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
BaseImagesCommand<ImagesContainterParametersBase> cloneCinderDiskCommand = (BaseImagesCommand<ImagesContainterParametersBase>) command;
ImagesContainterParametersBase parameters = cloneCinderDiskCommand.getParameters();
ImageStatus imageStatus = cloneCinderDiskCommand.getCinderBroker().getDiskStatus(parameters.getDestinationImageId());
DiskImage disk = (CinderDisk) diskDao.get(parameters.getContainerId());
if (imageStatus != null && imageStatus != disk.getImageStatus()) {
switch(imageStatus) {
case OK:
setCommandEndStatus(command, false, status, childCmdIds);
break;
case ILLEGAL:
setCommandEndStatus(command, true, status, childCmdIds);
break;
}
}
}
Aggregations