Search in sources :

Example 16 with ImageStorageDomainMap

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

the class StorageDomainDaoTest method testIsHostedEngineStorage.

@Test
public void testIsHostedEngineStorage() {
    // create hosted engine vm
    VmStatic vm = new VmStatic();
    vm.setId(Guid.newGuid());
    vm.setOrigin(OriginType.HOSTED_ENGINE);
    dbFacade.getVmStaticDao().save(vm);
    // create disk for HE
    DiskImage disk = new DiskImage();
    disk.setId(Guid.newGuid());
    disk.setImageId(Guid.newGuid());
    disk.setActive(true);
    disk.setVolumeType(VolumeType.Preallocated);
    disk.setVolumeFormat(VolumeFormat.RAW);
    dbFacade.getImageDao().save(disk.getImage());
    dbFacade.getBaseDiskDao().save(disk);
    ImageStorageDomainMap map = new ImageStorageDomainMap(disk.getImageId(), existingDomain.getId(), null, null);
    dbFacade.getImageStorageDomainMapDao().save(map);
    // attach disk
    VmDevice device = new VmDevice(new VmDeviceId(disk.getId(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.DISK.getName(), "", null, true, false, false, "", null, null, null);
    dbFacade.getVmDeviceDao().save(device);
    DiskVmElement diskVmElement = new DiskVmElement(device.getId());
    diskVmElement.setDiskInterface(DiskInterface.IDE);
    dbFacade.getDiskVmElementDao().save(diskVmElement);
    // run test
    StorageDomain domain = dao.get(existingDomain.getId());
    assertTrue(domain.isHostedEngineStorage());
    // change origin
    vm.setOrigin(OriginType.MANAGED_HOSTED_ENGINE);
    dbFacade.getVmStaticDao().update(vm);
    // run test again
    domain = dao.get(existingDomain.getId());
    assertTrue(domain.isHostedEngineStorage());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) 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) Test(org.junit.Test)

Example 17 with ImageStorageDomainMap

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap 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)

Aggregations

ImageStorageDomainMap (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap)17 Test (org.junit.Test)7 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 DiskImageDynamic (org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)4 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)3 ImageStorageDomainMapId (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId)3 Guid (org.ovirt.engine.core.compat.Guid)3 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)1 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)1 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)1