Search in sources :

Example 1 with ImportVmParameters

use of org.ovirt.engine.core.common.action.ImportVmParameters in project ovirt-engine by oVirt.

the class ImportValidatorTest method createParameters.

protected ImportVmParameters createParameters() {
    final VM v = createVM();
    v.setName("testVm");
    return new ImportVmParameters(v, Guid.newGuid(), Guid.newGuid(), Guid.newGuid(), Guid.newGuid());
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) ImportVmParameters(org.ovirt.engine.core.common.action.ImportVmParameters)

Example 2 with ImportVmParameters

use of org.ovirt.engine.core.common.action.ImportVmParameters in project ovirt-engine by oVirt.

the class ImportVmFromExportDomainModel method buildImportVmParameters.

private List<ActionParametersBase> buildImportVmParameters() {
    List<ActionParametersBase> prms = new ArrayList<>();
    for (Object item : getItems()) {
        VM vm = ((ImportVmData) item).getVm();
        ImportVmParameters prm = new ImportVmParameters(vm, (Guid) getEntity(), Guid.Empty, getStoragePool().getId(), getCluster().getSelectedItem().getId());
        if (getClusterQuota().getSelectedItem() != null && getClusterQuota().getIsAvailable()) {
            prm.setQuotaId(getClusterQuota().getSelectedItem().getId());
        }
        CpuProfile cpuProfile = getCpuProfiles().getSelectedItem();
        if (cpuProfile != null) {
            prm.setCpuProfileId(cpuProfile.getId());
        }
        prm.setForceOverride(true);
        prm.setCopyCollapse(((ImportVmData) item).getCollapseSnapshots().getEntity());
        Map<Guid, Guid> map = new HashMap<>();
        for (Map.Entry<Guid, Disk> entry : vm.getDiskMap().entrySet()) {
            DiskImage disk = (DiskImage) entry.getValue();
            map.put(disk.getId(), getDiskImportData(disk.getId()).getSelectedStorageDomain().getId());
            disk.setVolumeFormat(AsyncDataProvider.getInstance().getDiskVolumeFormat(getDiskImportData(disk.getId()).getSelectedVolumeType(), getDiskImportData(disk.getId()).getSelectedStorageDomain().getStorageType()));
            disk.setVolumeType(getDiskImportData(disk.getId()).getSelectedVolumeType());
            if (getDiskImportData(disk.getId()).getSelectedQuota() != null) {
                disk.setQuotaId(getDiskImportData(disk.getId()).getSelectedQuota().getId());
            }
        }
        prm.setImageToDestinationDomainMap(map);
        if (((ImportVmData) item).isExistsInSystem() || ((ImportVmData) item).getClone().getEntity()) {
            prm.setImportAsNewEntity(true);
            prm.setCopyCollapse(true);
        }
        prms.add(prm);
    }
    return prms;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) VM(org.ovirt.engine.core.common.businessentities.VM) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) ImportVmParameters(org.ovirt.engine.core.common.action.ImportVmParameters) HashMap(java.util.HashMap) Map(java.util.Map) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 3 with ImportVmParameters

use of org.ovirt.engine.core.common.action.ImportVmParameters in project ovirt-engine by oVirt.

the class BackendStorageDomainVmResource method doImport.

@Override
public Response doImport(Action action) {
    validateParameters(action, "storageDomain.id|name");
    Guid destStorageDomainId = getDestStorageDomainId(action);
    Guid clusterId = null;
    if (action.isSetCluster()) {
        clusterId = getClusterId(action);
    }
    ImportVmParameters params = new ImportVmParameters(getEntity(), parent.getStorageDomainId(), destStorageDomainId, parent.getDataCenterId(destStorageDomainId), clusterId);
    params.setImageToDestinationDomainMap(getDiskToDestinationMap(action));
    params.setForceOverride(action.isSetExclusive() ? action.isExclusive() : false);
    boolean collapseSnapshots = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, COLLAPSE_SNAPSHOTS, true, false);
    if (collapseSnapshots) {
        params.setCopyCollapse(collapseSnapshots);
    }
    setVolumesTypeFormat(action);
    if (action.isSetClone()) {
        params.setImportAsNewEntity(action.isClone());
        if (action.isSetVm() && action.getVm().isSetName()) {
            params.getVm().setName(action.getVm().getName());
        }
    }
    return doAction(ActionType.ImportVm, params, action);
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) ImportVmParameters(org.ovirt.engine.core.common.action.ImportVmParameters)

Example 4 with ImportVmParameters

use of org.ovirt.engine.core.common.action.ImportVmParameters in project ovirt-engine by oVirt.

the class HostedEngineImporter method createImportParams.

private ImportVmParameters createImportParams(VM vm, StorageDomain sd) {
    ImportVmParameters parameters = new ImportVmParameters(vm, sd.getId(), sd.getId(), sd.getStoragePoolId(), vm.getClusterId());
    // assumption is that there's only 1 profile for hosted engine domain. its an unmanged domain.
    Guid sdProfileId = diskProfileDao.getAllForStorageDomain(sd.getId()).get(0).getId();
    for (DiskImage image : vm.getImages()) {
        image.setDiskProfileId(sdProfileId);
        image.setStorageIds(Collections.singletonList(sd.getId()));
        image.setVmSnapshotId(Guid.newGuid());
        image.setImageStatus(ImageStatus.OK);
    }
    // disks are there already(the vm is running)
    parameters.setImagesExistOnTargetStorageDomain(true);
    // distinguish from "regular" he vm.
    vm.setOrigin(OriginType.MANAGED_HOSTED_ENGINE);
    // architecture is a missing attribute from vdsm structure. relying on the cluster is perfectly reliable.
    Cluster cluster = clusterDAO.get(vm.getClusterId());
    vm.setClusterArch(cluster.getArchitecture());
    vm.setVmCreationDate(new Date());
    vm.setMigrationSupport(MigrationSupport.IMPLICITLY_NON_MIGRATABLE);
    osRepository.getLinuxOss().stream().sorted().findFirst().ifPresent(vm::setVmOs);
    vm.setPriority(1);
    vmHandler.updateDefaultTimeZone(vm.getStaticData());
    return parameters;
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) ImportVmParameters(org.ovirt.engine.core.common.action.ImportVmParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date)

Example 5 with ImportVmParameters

use of org.ovirt.engine.core.common.action.ImportVmParameters in project ovirt-engine by oVirt.

the class ImportValidatorTest method lowThresholdStorageSpace.

@Test
public void lowThresholdStorageSpace() {
    ImportVmParameters parameters = createParameters();
    ImportValidator validator = setupDiskSpaceTest(parameters);
    doReturn(new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN)).when(multipleSdValidator).allDomainsWithinThresholds();
    assertThat(validator.validateSpaceRequirements(Collections.emptyList()), failsWith(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN));
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) ImportVmParameters(org.ovirt.engine.core.common.action.ImportVmParameters) Test(org.junit.Test)

Aggregations

ImportVmParameters (org.ovirt.engine.core.common.action.ImportVmParameters)7 Guid (org.ovirt.engine.core.compat.Guid)4 VM (org.ovirt.engine.core.common.businessentities.VM)3 Test (org.junit.Test)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 CpuProfile (org.ovirt.engine.core.common.businessentities.profiles.CpuProfile)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1