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());
}
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);
}
}
Aggregations