Search in sources :

Example 81 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.

the class ImportVmFromConfigurationCommand method attemptToAttachDisksToImportedVm.

private AuditLogType attemptToAttachDisksToImportedVm(Collection<Disk> disks) {
    List<String> failedDisks = new LinkedList<>();
    for (Disk disk : disks) {
        DiskVmElement dve = disk.getDiskVmElements().iterator().next();
        AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve, dve.isPlugged());
        ActionReturnValue returnVal = runInternalAction(ActionType.AttachDiskToVm, params, cloneContextAndDetachFromParent());
        if (!returnVal.getSucceeded()) {
            failedDisks.add(disk.getDiskAlias());
        }
    }
    if (!failedDisks.isEmpty()) {
        this.addCustomValue("DiskAliases", StringUtils.join(failedDisks, ","));
        return AuditLogType.VM_IMPORT_FROM_CONFIGURATION_ATTACH_DISKS_FAILED;
    }
    return AuditLogType.VM_IMPORT_FROM_CONFIGURATION_EXECUTED_SUCCESSFULLY;
}
Also used : AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LinkedList(java.util.LinkedList)

Example 82 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.

the class ImportVmTemplateCommand method addVmTemplateToDb.

protected void addVmTemplateToDb() {
    getVmTemplate().setClusterId(getParameters().getClusterId());
    // if "run on host" field points to a non existent vds (in the current cluster) -> remove field and continue
    if (!vmHandler.validateDedicatedVdsExistOnSameCluster(getVmTemplate()).isValid()) {
        getVmTemplate().setDedicatedVmForVdsList(Collections.emptyList());
    }
    getVmTemplate().setStatus(VmTemplateStatus.Locked);
    getVmTemplate().setQuotaId(getParameters().getQuotaId());
    vmHandler.autoSelectResumeBehavior(getVmTemplate(), getCluster());
    vmTemplateDao.save(getVmTemplate());
    getCompensationContext().snapshotNewEntity(getVmTemplate());
    int count = 1;
    for (DiskImage image : getImages()) {
        image.setActive(true);
        ImageStorageDomainMap map = imagesHandler.saveImage(image);
        getCompensationContext().snapshotNewEntity(image.getImage());
        getCompensationContext().snapshotNewEntity(map);
        if (!baseDiskDao.exists(image.getId())) {
            image.setDiskAlias(ImagesHandler.getSuggestedDiskAlias(image, getVmTemplateName(), count));
            count++;
            baseDiskDao.save(image);
            getCompensationContext().snapshotNewEntity(image);
        }
        DiskImageDynamic diskDynamic = new DiskImageDynamic();
        diskDynamic.setId(image.getImageId());
        diskDynamic.setActualSize(image.getActualSizeInBytes());
        diskImageDynamicDao.save(diskDynamic);
        DiskVmElement dve = DiskVmElement.copyOf(image.getDiskVmElementForVm(sourceTemplateId), image.getId(), getVmTemplateId());
        diskVmElementDao.save(dve);
        getCompensationContext().snapshotNewEntity(diskDynamic);
    }
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)

Example 83 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.

the class AddVmCommand method createAndSaveNewDiskVmElement.

private void createAndSaveNewDiskVmElement(Guid newDiskImageId, Guid newVmId, DiskVmElement oldDve) {
    DiskVmElement newDve = DiskVmElement.copyOf(oldDve, newDiskImageId, newVmId);
    diskVmElementDao.save(newDve);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 84 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method isPassDiscardSupportedForImagesDestSds.

protected ValidationResult isPassDiscardSupportedForImagesDestSds() {
    Map<Disk, DiskVmElement> diskToDiskVmElement = diskHandler.getDiskToDiskVmElementMap(getVm().getId(), diskInfoDestinationMap);
    Map<Guid, Guid> diskIdToDestSdId = diskInfoDestinationMap.values().stream().collect(Collectors.toMap(DiskImage::getId, diskImage -> diskImage.getStorageIds().get(0)));
    MultipleDiskVmElementValidator multipleDiskVmElementValidator = createMultipleDiskVmElementValidator(diskToDiskVmElement);
    return multipleDiskVmElementValidator.isPassDiscardSupportedForDestSds(diskIdToDestSdId);
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CommandExecutionStatus(org.ovirt.engine.core.compat.backendcompat.CommandExecutionStatus) EngineException(org.ovirt.engine.core.common.errors.EngineException) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) VmNicDao(org.ovirt.engine.core.dao.network.VmNicDao) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) MultipleDiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.MultipleDiskVmElementValidator) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) Map(java.util.Map) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Instance(javax.enterprise.inject.Instance) CreateEntity(org.ovirt.engine.core.common.validation.group.CreateEntity) VmWatchdogValidator(org.ovirt.engine.core.bll.validator.VmWatchdogValidator) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Set(java.util.Set) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) Stream(java.util.stream.Stream) CreateAllTemplateDisksParameters(org.ovirt.engine.core.common.action.CreateAllTemplateDisksParameters) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) QuotaSanityParameter(org.ovirt.engine.core.bll.quota.QuotaSanityParameter) QuotaStorageDependent(org.ovirt.engine.core.bll.quota.QuotaStorageDependent) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) DiskProfileHelper(org.ovirt.engine.core.bll.profiles.DiskProfileHelper) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) Permission(org.ovirt.engine.core.common.businessentities.Permission) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Pair(org.ovirt.engine.core.common.utils.Pair) CompatibilityVersionUtils(org.ovirt.engine.core.common.utils.CompatibilityVersionUtils) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) EndProcedure(org.ovirt.engine.core.common.action.ActionParametersBase.EndProcedure) SealVmTemplateParameters(org.ovirt.engine.core.common.action.SealVmTemplateParameters) Scope(org.ovirt.engine.core.common.action.LockProperties.Scope) CpuProfileHelper(org.ovirt.engine.core.bll.profiles.CpuProfileHelper) SnapshotsValidator(org.ovirt.engine.core.bll.snapshots.SnapshotsValidator) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) EngineError(org.ovirt.engine.core.common.errors.EngineError) VM(org.ovirt.engine.core.common.businessentities.VM) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) IconValidator(org.ovirt.engine.core.bll.validator.IconValidator) UpdateAllTemplateDisksParameters(org.ovirt.engine.core.common.action.UpdateAllTemplateDisksParameters) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) ScheduledFuture(java.util.concurrent.ScheduledFuture) Date(java.util.Date) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) Version(org.ovirt.engine.core.compat.Version) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IconUtils(org.ovirt.engine.core.bll.utils.IconUtils) CopyVolumeType(org.ovirt.engine.core.common.businessentities.storage.CopyVolumeType) DiskVmElementDao(org.ovirt.engine.core.dao.DiskVmElementDao) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) DiskHandler(org.ovirt.engine.core.bll.storage.disk.DiskHandler) List(java.util.List) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) QuotaVdsDependent(org.ovirt.engine.core.bll.quota.QuotaVdsDependent) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) LockProperties(org.ovirt.engine.core.common.action.LockProperties) HashMap(java.util.HashMap) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) ThreadPools(org.ovirt.engine.core.utils.threadpool.ThreadPools) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) Function(java.util.function.Function) Phase(org.ovirt.engine.core.common.action.AddVmTemplateParameters.Phase) UpdateVmVersionParameters(org.ovirt.engine.core.common.action.UpdateVmVersionParameters) CommandCoordinatorUtil(org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ExecutionHandler(org.ovirt.engine.core.bll.job.ExecutionHandler) StorageDomainStaticDao(org.ovirt.engine.core.dao.StorageDomainStaticDao) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VmTemplateStatus(org.ovirt.engine.core.common.businessentities.VmTemplateStatus) Typed(javax.enterprise.inject.Typed) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) GraphicsParameters(org.ovirt.engine.core.common.action.GraphicsParameters) TimeUnit(java.util.concurrent.TimeUnit) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) MultipleDiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.MultipleDiskVmElementValidator) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 85 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method addTemplateDiskVmElement.

private void addTemplateDiskVmElement(Guid newDiskId, Guid oldDiskId) {
    DiskVmElement oldDve = diskVmElementDao.get(new VmDeviceId(oldDiskId, getVmId()));
    DiskVmElement newDve = DiskVmElement.copyOf(oldDve);
    newDve.setId(new VmDeviceId(newDiskId, getVmTemplateId()));
    diskVmElementDao.save(newDve);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)91 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Test (org.junit.Test)26 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)23 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)22 Guid (org.ovirt.engine.core.compat.Guid)17 ArrayList (java.util.ArrayList)16 VM (org.ovirt.engine.core.common.businessentities.VM)12 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)11 HashMap (java.util.HashMap)8 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)8 Map (java.util.Map)7 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)7 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)7 ActionType (org.ovirt.engine.core.common.action.ActionType)6 AttachDetachVmDiskParameters (org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 VmDiskOperationParameterBase (org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)5 Collection (java.util.Collection)4