Search in sources :

Example 1 with DiskImageBase

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

the class ImportVmCommand method buildMoveOrCopyImageGroupParametersForDisk.

private MoveOrCopyImageGroupParameters buildMoveOrCopyImageGroupParametersForDisk(DiskImage disk, Guid containerID) {
    Guid originalDiskId = newDiskIdForDisk.get(disk.getId()).getId();
    Guid destinationDomain = imageToDestinationDomainMap.get(originalDiskId);
    MoveOrCopyImageGroupParameters params = new MoveOrCopyImageGroupParameters(containerID, originalDiskId, newDiskIdForDisk.get(disk.getId()).getImageId(), disk.getId(), disk.getImageId(), destinationDomain, ImageOperation.Copy);
    params.setParentCommand(getActionType());
    params.setUseCopyCollapse(isCopyCollapseOrNoSnapshots());
    params.setCopyVolumeType(CopyVolumeType.LeafVol);
    params.setForceOverride(getParameters().getForceOverride());
    params.setSourceDomainId(getParameters().getSourceDomainId());
    params.setStoragePoolId(getParameters().getStoragePoolId());
    params.setImportEntity(true);
    params.setEntityInfo(new EntityInfo(VdcObjectType.VM, getVm().getId()));
    params.setRevertDbOperationScope(ImageDbOperationScope.IMAGE);
    params.setQuotaId(disk.getQuotaId() != null ? disk.getQuotaId() : getParameters().getQuotaId());
    params.setDiskProfileId(disk.getDiskProfileId());
    if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(originalDiskId)) {
        DiskImageBase diskImageBase = (DiskImageBase) getParameters().getVm().getDiskMap().get(originalDiskId);
        params.setVolumeType(diskImageBase.getVolumeType());
        params.setVolumeFormat(diskImageBase.getVolumeFormat());
    }
    params.setParentParameters(getParameters());
    return params;
}
Also used : MoveOrCopyImageGroupParameters(org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters) DiskImageBase(org.ovirt.engine.core.common.businessentities.storage.DiskImageBase) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with DiskImageBase

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

the class ImportVmCommand method addVmImagesAndSnapshots.

protected void addVmImagesAndSnapshots() {
    Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(getImages());
    if (isCopyCollapseOrNoSnapshots()) {
        Guid snapshotId = Guid.newGuid();
        int aliasCounter = 0;
        for (List<DiskImage> diskList : images.values()) {
            DiskImage disk = getActiveVolumeDisk(diskList);
            disk.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
            disk.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
            disk.setVmSnapshotId(snapshotId);
            disk.setActive(true);
            if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(disk.getId())) {
                DiskImageBase diskImageBase = (DiskImageBase) getParameters().getVm().getDiskMap().get(disk.getId());
                disk.setVolumeFormat(diskImageBase.getVolumeFormat());
                disk.setVolumeType(diskImageBase.getVolumeType());
            }
            setDiskStorageDomainInfo(disk);
            if (getParameters().isImportAsNewEntity()) {
                generateNewDiskId(diskList, disk);
                updateManagedDeviceMap(disk, getVm().getStaticData().getManagedDeviceMap());
            } else {
                newDiskIdForDisk.put(disk.getId(), disk);
            }
            disk.setCreationDate(new Date());
            saveImage(disk);
            ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
            saveBaseDisk(disk);
            saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
            saveDiskImageDynamic(disk);
        }
        Snapshot snapshot = addActiveSnapshot(snapshotId);
        getVm().setSnapshots(Arrays.asList(snapshot));
    } else {
        Guid snapshotId = null;
        for (DiskImage disk : getImages()) {
            disk.setActive(false);
            setDiskStorageDomainInfo(disk);
            saveImage(disk);
            snapshotId = disk.getVmSnapshotId();
            saveSnapshotIfNotExists(snapshotId, disk);
            saveDiskImageDynamic(disk);
        }
        int aliasCounter = 0;
        for (List<DiskImage> diskList : images.values()) {
            DiskImage disk = getActiveVolumeDisk(diskList);
            newDiskIdForDisk.put(disk.getId(), disk);
            snapshotId = disk.getVmSnapshotId();
            disk.setActive(true);
            ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
            updateImage(disk);
            saveBaseDisk(disk);
            saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
        }
        // Update active snapshot's data, since it was inserted as a regular snapshot.
        updateActiveSnapshot(snapshotId);
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) DiskImageBase(org.ovirt.engine.core.common.businessentities.storage.DiskImageBase) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date)

Example 3 with DiskImageBase

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

the class ImportVmCommand method validateAfterCloneVm.

protected boolean validateAfterCloneVm(Map<Guid, StorageDomain> domainsMap) {
    VM vmFromParams = getParameters().getVm();
    // check that the imported vm guid is not in engine
    if (!validateNoDuplicateVm()) {
        return false;
    }
    if (!validateNoDuplicateDiskImages(imageList)) {
        return false;
    }
    setVmTemplateId(getVm().getVmtGuid());
    if (!templateExists() || !checkTemplateInStorageDomain() || !checkImagesGUIDsLegal() || !validateUniqueVmName()) {
        return false;
    }
    if (!VmTemplateHandler.BLANK_VM_TEMPLATE_ID.equals(getVm().getVmtGuid()) && getVmTemplate() != null && getVmTemplate().getStatus() == VmTemplateStatus.Locked) {
        return failValidation(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
    }
    if (!validateLunDisksForVm(vmFromParams)) {
        return false;
    }
    if (getParameters().getCopyCollapse() && vmFromParams.getDiskMap() != null) {
        for (Disk disk : vmFromParams.getDiskMap().values()) {
            if (disk.getDiskStorageType() == DiskStorageType.IMAGE) {
                DiskImage key = (DiskImage) getVm().getDiskMap().get(disk.getId());
                if (key != null) {
                    if (!ImagesHandler.checkImageConfiguration(domainsMap.get(imageToDestinationDomainMap.get(key.getId())).getStorageStaticData(), (DiskImageBase) disk, getReturnValue().getValidationMessages())) {
                        return false;
                    }
                }
            }
        }
    }
    // (backup) domain
    if (getParameters().getCopyCollapse() && !isTemplateExistsOnExportDomain()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMPORTED_TEMPLATE_IS_MISSING, String.format("$DomainName %1$s", storageDomainStaticDao.get(getParameters().getSourceDomainId()).getStorageName()));
    }
    if (!validateVmArchitecture()) {
        return false;
    }
    if (!validateVdsCluster()) {
        return false;
    }
    if (!isImagesAlreadyOnTarget()) {
        if (!handleDestStorageDomains()) {
            return false;
        }
    }
    if (!validateGraphicsAndDisplay()) {
        return false;
    }
    if (!getParameters().isImportAsNewEntity()) {
        List<VmNetworkInterface> vmNetworkInterfaces = getVm().getInterfaces();
        if (!validate(vmNicMacsUtils.validateThereIsEnoughOfFreeMacs(vmNetworkInterfaces, getMacPool(), getVnicRequiresNewMacPredicate()))) {
            return false;
        }
        if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
            return false;
        }
    }
    if (!setAndValidateDiskProfiles()) {
        return false;
    }
    if (!setAndValidateCpuProfile()) {
        return false;
    }
    return true;
}
Also used : DiskImageBase(org.ovirt.engine.core.common.businessentities.storage.DiskImageBase) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 4 with DiskImageBase

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

the class AddVmFromTemplateCommand method buildDiskCreationParameters.

@Override
protected CreateCloneOfTemplateParameters buildDiskCreationParameters(DiskImage disk) {
    DiskImageBase diskInfo = getParameters().getDiskInfoDestinationMap().get(disk.getId());
    CreateCloneOfTemplateParameters params = new CreateCloneOfTemplateParameters(disk.getImageId(), getParameters().getVmStaticData().getId(), diskInfo);
    params.setStorageDomainId(diskInfoSourceMap.get(disk.getId()));
    params.setDestStorageDomainId(retrieveDestinationDomainForDisk(disk.getId()));
    params.setDiskAlias(diskInfoDestinationMap.get(disk.getId()).getDiskAlias());
    params.setVmSnapshotId(getVmSnapshotId());
    params.setParentCommand(ActionType.AddVmFromTemplate);
    params.setParentParameters(getParameters());
    params.setEntityInfo(getParameters().getEntityInfo());
    params.setQuotaId(diskInfoDestinationMap.get(disk.getId()).getQuotaId() != null ? diskInfoDestinationMap.get(disk.getId()).getQuotaId() : null);
    params.setDiskProfileId(diskInfoDestinationMap.get(disk.getId()).getDiskProfileId());
    return params;
}
Also used : DiskImageBase(org.ovirt.engine.core.common.businessentities.storage.DiskImageBase) CreateCloneOfTemplateParameters(org.ovirt.engine.core.common.action.CreateCloneOfTemplateParameters)

Aggregations

DiskImageBase (org.ovirt.engine.core.common.businessentities.storage.DiskImageBase)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CreateCloneOfTemplateParameters (org.ovirt.engine.core.common.action.CreateCloneOfTemplateParameters)1 MoveOrCopyImageGroupParameters (org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters)1 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)1 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)1