Search in sources :

Example 41 with DiskImage

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

the class CreateOvfVolumeForStorageDomainCommand method createDisk.

public DiskImage createDisk(Guid domainId) {
    DiskImage createdDiskImage = new DiskImage();
    createdDiskImage.setContentType(DiskContentType.OVF_STORE);
    createdDiskImage.setWipeAfterDelete(false);
    createdDiskImage.setDiskAlias(OvfInfoFileConstants.OvfStoreDescriptionLabel);
    createdDiskImage.setDiskDescription(OvfInfoFileConstants.OvfStoreDescriptionLabel);
    createdDiskImage.setShareable(shouldOvfStoreBeShareable());
    createdDiskImage.setStorageIds(new ArrayList<>(Collections.singletonList(domainId)));
    createdDiskImage.setSize(SizeConverter.BYTES_IN_MB * 128);
    createdDiskImage.setVolumeFormat(VolumeFormat.RAW);
    createdDiskImage.setVolumeType(VolumeType.Preallocated);
    createdDiskImage.setDescription("OVF store for domain " + domainId);
    Date creationDate = new Date();
    createdDiskImage.setCreationDate(creationDate);
    createdDiskImage.setLastModified(creationDate);
    return createdDiskImage;
}
Also used : DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date)

Example 42 with DiskImage

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

the class OvfHelper method readVmFromOvf.

/**
 * parses a given ovf to a vm, initialize all the extra data related to it such as images, interfaces, cluster,
 * LUNS, etc..
 *
 * @return FullEntityOvfData that represents the given ovf data
 */
public FullEntityOvfData readVmFromOvf(String ovf) throws OvfReaderException {
    VM vm = new VM();
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
    ovfManager.importVm(ovf, vm, fullEntityOvfData);
    // add images
    vm.setImages((ArrayList) fullEntityOvfData.getDiskImages());
    // add interfaces
    vm.setInterfaces(fullEntityOvfData.getInterfaces());
    // add disk map
    Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(fullEntityOvfData.getDiskImages());
    for (Map.Entry<Guid, List<DiskImage>> entry : images.entrySet()) {
        List<DiskImage> list = entry.getValue();
        vm.getDiskMap().put(entry.getKey(), list.get(list.size() - 1));
    }
    fullEntityOvfData.getLunDisks().forEach(lunDisk -> vm.getDiskMap().put(lunDisk.getId(), lunDisk));
    return fullEntityOvfData;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) HashMap(java.util.HashMap) Map(java.util.Map) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 43 with DiskImage

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

the class OvfUpdateProcessHelper method getVmImagesFromDb.

public ArrayList<DiskImage> getVmImagesFromDb(VM vm) {
    ArrayList<DiskImage> allVmImages = new ArrayList<>();
    List<DiskImage> filteredDisks = DisksFilter.filterImageDisks(vm.getDiskList(), ONLY_SNAPABLE, ONLY_ACTIVE);
    for (DiskImage diskImage : filteredDisks) {
        allVmImages.addAll(diskImageDao.getAllSnapshotsForLeaf(diskImage.getImageId()));
    }
    for (DiskImage disk : allVmImages) {
        DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(disk.getId(), vm.getId()));
        disk.setDiskVmElements(Collections.singletonList(dve));
    }
    return allVmImages;
}
Also used : ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 44 with DiskImage

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

the class ProcessOvfUpdateForStorageDomainCommand method populateStorageDomainOvfData.

private void populateStorageDomainOvfData() {
    List<StorageDomainOvfInfo> storageDomainOvfInfos = storageDomainOvfInfoDao.getAllForDomain(getStorageDomainId());
    ovfDiskCount = storageDomainOvfInfos.size();
    storageDomainOvfInfos.sort(OVF_INFO_COMPARATOR);
    for (StorageDomainOvfInfo storageDomainOvfInfo : storageDomainOvfInfos) {
        if (storageDomainOvfInfo.getStatus() != StorageDomainOvfInfoStatus.DISABLED) {
            DiskImage ovfDisk = (DiskImage) diskDao.get(storageDomainOvfInfo.getOvfDiskId());
            domainOvfStoresInfoForUpdate.add(new Pair<>(storageDomainOvfInfo, ovfDisk));
        }
    }
}
Also used : StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 45 with DiskImage

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

the class ProcessOvfUpdateForStoragePoolCommand method populateVmsMetadataForOvfUpdate.

/**
 * Create and returns map contains valid vms metadata
 */
protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> populateVmsMetadataForOvfUpdate(List<Guid> idsToProcess) {
    Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = new HashMap<>();
    List<VM> vms = vmDao.getVmsByIds(idsToProcess);
    for (VM vm : vms) {
        if (VMStatus.ImageLocked != vm.getStatus()) {
            updateVmDisksFromDb(vm);
            if (!verifyImagesStatus(vm.getDiskList())) {
                continue;
            }
            ArrayList<DiskImage> vmImages = ovfUpdateProcessHelper.getVmImagesFromDb(vm);
            if (!verifyImagesStatus(vmImages)) {
                continue;
            }
            vm.setSnapshots(snapshotDao.getAllWithConfiguration(vm.getId()));
            if (!verifySnapshotsStatus(vm.getSnapshots())) {
                continue;
            }
            ovfUpdateProcessHelper.loadVmData(vm);
            Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
            if (currentDbGeneration == null) {
                log.warn("currentDbGeneration of VM (name: '{}', id: '{}') is null, probably because the VM was deleted during the run of OvfDataUpdater.", vm.getName(), vm.getId());
                continue;
            }
            if (vm.getStaticData().getDbGeneration() == currentDbGeneration) {
                List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
                for (LunDisk lun : lunDisks) {
                    lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId())));
                }
                List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
                List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
                Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
                FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
                fullEntityOvfData.setDiskImages(vmImages);
                fullEntityOvfData.setLunDisks(lunDisks);
                fullEntityOvfData.setAffinityGroups(affinityGroups);
                fullEntityOvfData.setAffinityLabels(affinityLabels);
                fullEntityOvfData.setDbUsers(dbUsers);
                ovfHelper.populateUserToRoles(fullEntityOvfData, vm.getId());
                proccessedOvfConfigurationsInfo.add(ovfUpdateProcessHelper.buildMetadataDictionaryForVm(vm, vmsAndTemplateMetadata, fullEntityOvfData));
                proccessedIdsInfo.add(vm.getId());
                proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
                proccessDisksDomains(vm.getDiskList());
            }
        }
    }
    return vmsAndTemplateMetadata;
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) Label(org.ovirt.engine.core.common.businessentities.Label) Guid(org.ovirt.engine.core.compat.Guid) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Aggregations

DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)635 Guid (org.ovirt.engine.core.compat.Guid)212 ArrayList (java.util.ArrayList)167 Test (org.junit.Test)132 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)80 VM (org.ovirt.engine.core.common.businessentities.VM)77 HashMap (java.util.HashMap)64 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)62 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)62 List (java.util.List)56 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)48 Map (java.util.Map)39 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)38 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)35 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)34 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)31 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)31 EngineException (org.ovirt.engine.core.common.errors.EngineException)29 ActionType (org.ovirt.engine.core.common.action.ActionType)22 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)22