use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method createVideoDeviceByDisplayType.
public VmDevice createVideoDeviceByDisplayType(DisplayType displayType, Guid vmId) {
VmDevice vmDevice = new VmDevice();
vmDevice.setId(new VmDeviceId(Guid.newGuid(), vmId));
vmDevice.setType(VmDeviceGeneralType.VIDEO);
vmDevice.setDevice(displayType.getDefaultVmDeviceType().getName());
vmDevice.setPlugged(true);
vmDevice.setAddress("");
return vmDevice;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method createSysprepPayloadDevice.
public VmDevice createSysprepPayloadDevice(String sysPrepContent, VM vm) {
// We do not validate the size of the content being passed to the VM payload by VmPayload.isPayloadSizeLegal().
// The sysprep file size isn't being verified for 3.0 clusters and below, so we maintain the same behavior here.
VmPayload vmPayload = new VmPayload();
vmPayload.setDeviceType(VmDeviceType.FLOPPY);
vmPayload.getFiles().put(osRepository.getSysprepFileName(vm.getOs(), vm.getCompatibilityVersion()), new String(BASE_64.encode(sysPrepContent.getBytes()), StandardCharsets.UTF_8));
return new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.FLOPPY.getName(), "", vmPayload.getSpecParams(), true, true, true, "", null, null, null);
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class UpdateVmDiskCommand method performDiskUpdate.
protected void performDiskUpdate(final boolean unlockImage) {
if (shouldPerformMetadataUpdate()) {
updateMetaDataDescription((DiskImage) getNewDisk());
}
final Disk diskForUpdate = diskDao.get(getParameters().getDiskInfo().getId());
final DiskVmElement diskVmElementForUpdate = diskVmElementDao.get(new VmDeviceId(getOldDisk().getId(), getVmId()));
applyUserChanges(diskForUpdate, diskVmElementForUpdate);
TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() {
@Override
public Object runInTransaction() {
vmStaticDao.incrementDbGeneration(getVm().getId());
updateDeviceProperties();
baseDiskDao.update(diskForUpdate);
diskVmElementDao.update(diskVmElementForUpdate);
switch(diskForUpdate.getDiskStorageType()) {
case IMAGE:
DiskImage diskImage = (DiskImage) diskForUpdate;
diskImage.setQuotaId(getQuotaId());
if (unlockImage && diskImage.getImageStatus() == ImageStatus.LOCKED) {
diskImage.setImageStatus(ImageStatus.OK);
}
imageDao.update(diskImage.getImage());
updateQuota(diskImage);
updateDiskProfile();
break;
case CINDER:
CinderDisk cinderDisk = (CinderDisk) diskForUpdate;
cinderDisk.setQuotaId(getQuotaId());
setStorageDomainId(cinderDisk.getStorageIds().get(0));
getCinderBroker().updateDisk(cinderDisk);
if (unlockImage && cinderDisk.getImageStatus() == ImageStatus.LOCKED) {
cinderDisk.setImageStatus(ImageStatus.OK);
}
imageDao.update(cinderDisk.getImage());
updateQuota(cinderDisk);
break;
case LUN:
// No specific update for LUN disk
break;
}
reloadDisks();
setSucceeded(true);
// If necessary set the new Storage QoS values on running VMs asynchronously
liveUpdateDiskProfile();
return null;
}
private void updateDeviceProperties() {
if (updateReadOnlyRequested()) {
vmDeviceForVm.setReadOnly(getDiskVmElement().isReadOnly());
vmDeviceDao.update(vmDeviceForVm);
}
if ((getOldDiskVmElement().getDiskInterface() != getDiskVmElement().getDiskInterface()) || ((getOldDiskVmElement().isBoot() != getDiskVmElement().isBoot()) && (getDiskVmElement().getDiskInterface() == DiskInterface.IDE))) {
vmDeviceForVm.setAddress("");
vmDeviceDao.clearDeviceAddress(getOldDisk().getId());
}
}
});
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class AttachDiskToVmCommand method validate.
@Override
protected boolean validate() {
if (disk == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
}
DiskValidator oldDiskValidator = new DiskValidator(disk);
ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
if (!isHostedEngineDisk.isValid()) {
return validate(isHostedEngineDisk);
}
if (!checkOperationAllowedOnDiskContentType(disk)) {
return false;
}
if (isOperationPerformedOnDiskSnapshot() && (!validate(snapshotsValidator.snapshotExists(getSnapshot())) || !validate(snapshotsValidator.isRegularSnapshot(getSnapshot())))) {
return false;
}
boolean isImageDisk = disk.getDiskStorageType().isInternal();
if (isImageDisk) {
// TODO : this load and check of the active disk will be removed
// after inspecting upgrade
Disk activeDisk = diskHandler.loadActiveDisk(disk.getId());
if (((DiskImage) activeDisk).getImageStatus() == ImageStatus.ILLEGAL) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION);
}
if (((DiskImage) disk).getImageStatus() == ImageStatus.LOCKED) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_DISKS_LOCKED);
addValidationMessageVariable("diskAliases", disk.getDiskAlias());
return false;
}
}
if (!validate(new VmValidator(getVm()).isVmExists()) || !isVmInUpPausedDownStatus()) {
return false;
}
if (!validateDiskVmData()) {
return false;
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
updateDisksFromDb();
if (getDiskVmElement().isBoot() && !validate(getDiskValidator(disk).isVmNotContainsBootDisk(getVm()))) {
return false;
}
if (!isDiskPassPciAndIdeLimit()) {
return false;
}
if (vmDeviceDao.exists(new VmDeviceId(disk.getId(), getVmId()))) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED);
}
if (!isOperationPerformedOnDiskSnapshot() && !disk.isShareable() && disk.getNumberOfVms() > 0) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NOT_SHAREABLE_DISK_ALREADY_ATTACHED);
}
if (isImageDisk && storagePoolIsoMapDao.get(new StoragePoolIsoMapId(((DiskImage) disk).getStorageIds().get(0), getVm().getStoragePoolId())) == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
}
if (isImageDisk) {
StorageDomain storageDomain = storageDomainDao.getForStoragePool(((DiskImage) disk).getStorageIds().get(0), ((DiskImage) disk).getStoragePoolId());
StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomain);
if (!validate(storageDomainValidator.isDomainExistAndActive())) {
return false;
}
}
DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(disk, getDiskVmElement());
if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
return false;
}
if (!validate(diskVmElementValidator.isVirtIoScsiValid(getVm()))) {
return false;
}
if (!validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) {
return false;
}
Guid storageDomainId = disk.getDiskStorageType() == DiskStorageType.IMAGE ? ((DiskImage) disk).getStorageIds().get(0) : null;
if (!validate(diskVmElementValidator.isPassDiscardSupported(storageDomainId))) {
return false;
}
if (!isVmNotInPreviewSnapshot()) {
return false;
}
if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
return isDiskSupportedForPlugUnPlug(getDiskVmElement(), disk.getDiskAlias());
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class RemoveCinderDiskCommand method endSuccessfully.
@Override
protected void endSuccessfully() {
freeVmSnapshotsWithWait();
vmDeviceDao.remove(new VmDeviceId(getParameters().getRemovedVolume().getId(), null));
baseDiskDao.remove(getParameters().getRemovedVolume().getId());
if (getParameters().getShouldBeLogged()) {
auditLogDirector.log(this, AuditLogType.USER_FINISHED_REMOVE_DISK);
}
setSucceeded(true);
}
Aggregations