Search in sources :

Example 56 with VmTemplate

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

the class SnapshotsManager method generateVmConfiguration.

/**
 * Generate a string containing the given VM's configuration.
 *
 * @param vm
 *            The VM to generate configuration from.
 * @return A String containing the VM configuration.
 */
protected String generateVmConfiguration(VM vm, List<DiskImage> disks, Map<Guid, VmDevice> vmDevices) {
    if (vm.getInterfaces() == null || vm.getInterfaces().isEmpty()) {
        vm.setInterfaces(vmNetworkInterfaceDao.getAllForVm(vm.getId()));
    }
    if (StringUtils.isEmpty(vm.getVmtName())) {
        VmTemplate t = vmTemplateDao.get(vm.getVmtGuid());
        vm.setVmtName(t.getName());
    }
    if (vmDevices == null) {
        vmDeviceUtils.setVmDevices(vm.getStaticData());
    } else {
        vm.getStaticData().setManagedDeviceMap(vmDevices);
    }
    if (disks == null) {
        disks = DisksFilter.filterImageDisks(diskDao.getAllForVm(vm.getId()), ONLY_SNAPABLE, ONLY_ACTIVE);
        disks.addAll(imagesHandler.getCinderLeafImages(diskDao.getAllForVm(vm.getId())));
    }
    populateDisksWithVmData(disks, vm.getId());
    disks.forEach(image -> image.setStorageIds(null));
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
    fullEntityOvfData.setDiskImages(disks);
    return ovfManager.exportVm(vm, fullEntityOvfData, clusterUtils.getCompatibilityVersion(vm));
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)

Example 57 with VmTemplate

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

the class StorageHandlingCommandBase method removeEntitiesFromStorageDomain.

/**
 * Remove all related entities of the Storage Domain from the DB.
 */
private void removeEntitiesFromStorageDomain(final List<VM> vmsForStorageDomain, final List<VmTemplate> vmTemplatesForStorageDomain, final List<DiskImage> disksForStorageDomain, final Guid storageDomainId) {
    if (!vmsForStorageDomain.isEmpty() || !vmTemplatesForStorageDomain.isEmpty() || !disksForStorageDomain.isEmpty()) {
        TransactionSupport.executeInNewTransaction(() -> {
            for (VM vm : vmsForStorageDomain) {
                removeEntityLeftOver(vm.getId(), vm.getName(), storageDomainId);
                unregisteredOVFDataDao.saveOVFData(new OvfEntityData(vm.getId(), vm.getName(), VmEntityType.VM, vm.getClusterArch(), vm.getCompatibilityVersion(), storageDomainId, null, null));
            }
            for (VmTemplate vmTemplate : vmTemplatesForStorageDomain) {
                removeEntityLeftOver(vmTemplate.getId(), vmTemplate.getName(), storageDomainId);
                unregisteredOVFDataDao.saveOVFData(new OvfEntityData(vmTemplate.getId(), vmTemplate.getName(), VmEntityType.TEMPLATE, vmTemplate.getClusterArch(), clusterDao.get(vmTemplate.getClusterId()).getCompatibilityVersion(), storageDomainId, null, null));
            }
            storageDomainDao.removeEntitesFromStorageDomain(storageDomainId);
            return null;
        });
    }
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData)

Example 58 with VmTemplate

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

the class VmTemplateHandlerTest method testUpdateFieldsQuotaEnforcementType.

@Test
public void testUpdateFieldsQuotaEnforcementType() {
    VmTemplate src = new VmTemplate();
    src.setQuotaEnforcementType(QuotaEnforcementTypeEnum.DISABLED);
    VmTemplate dest = new VmTemplate();
    dest.setQuotaEnforcementType(QuotaEnforcementTypeEnum.HARD_ENFORCEMENT);
    assertTrue("Update should be valid for different quota enforcement types", vmTemplateHandler.isUpdateValid(src, dest));
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Example 59 with VmTemplate

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

the class VmTemplateHandlerTest method testUpdateFieldsIsQuotaDefault.

@Test
public void testUpdateFieldsIsQuotaDefault() {
    VmTemplate src = new VmTemplate();
    src.setQuotaDefault(true);
    VmTemplate dest = new VmTemplate();
    dest.setQuotaDefault(false);
    assertTrue("Update should be valid for different quota default statuses", vmTemplateHandler.isUpdateValid(src, dest));
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Example 60 with VmTemplate

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

the class ImportVmTemplateCommandTest method createParameters.

protected ImportVmTemplateParameters createParameters() {
    VmTemplate t = new VmTemplate();
    t.setName("testTemplate");
    return new ImportVmTemplateParameters(Guid.newGuid(), Guid.newGuid(), Guid.newGuid(), Guid.newGuid(), t);
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters)

Aggregations

VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)149 ArrayList (java.util.ArrayList)42 Guid (org.ovirt.engine.core.compat.Guid)40 Test (org.junit.Test)30 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)23 HashMap (java.util.HashMap)22 List (java.util.List)20 VM (org.ovirt.engine.core.common.businessentities.VM)19 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)16 Map (java.util.Map)13 QueryType (org.ovirt.engine.core.common.queries.QueryType)13 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)12 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)11 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)11 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)11 Frontend (org.ovirt.engine.ui.frontend.Frontend)10 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)9 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)9 Collection (java.util.Collection)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)8