use of org.ovirt.engine.core.common.businessentities.storage.DiskImageBase in project ovirt-engine by oVirt.
the class ImportVmCommand method buildMoveOrCopyImageGroupParametersForDisk.
private MoveOrCopyImageGroupParameters buildMoveOrCopyImageGroupParametersForDisk(DiskImage disk, Guid containerID) {
Guid originalDiskId = newDiskIdForDisk.get(disk.getId()).getId();
Guid destinationDomain = imageToDestinationDomainMap.get(originalDiskId);
MoveOrCopyImageGroupParameters params = new MoveOrCopyImageGroupParameters(containerID, originalDiskId, newDiskIdForDisk.get(disk.getId()).getImageId(), disk.getId(), disk.getImageId(), destinationDomain, ImageOperation.Copy);
params.setParentCommand(getActionType());
params.setUseCopyCollapse(isCopyCollapseOrNoSnapshots());
params.setCopyVolumeType(CopyVolumeType.LeafVol);
params.setForceOverride(getParameters().getForceOverride());
params.setSourceDomainId(getParameters().getSourceDomainId());
params.setStoragePoolId(getParameters().getStoragePoolId());
params.setImportEntity(true);
params.setEntityInfo(new EntityInfo(VdcObjectType.VM, getVm().getId()));
params.setRevertDbOperationScope(ImageDbOperationScope.IMAGE);
params.setQuotaId(disk.getQuotaId() != null ? disk.getQuotaId() : getParameters().getQuotaId());
params.setDiskProfileId(disk.getDiskProfileId());
if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(originalDiskId)) {
DiskImageBase diskImageBase = (DiskImageBase) getParameters().getVm().getDiskMap().get(originalDiskId);
params.setVolumeType(diskImageBase.getVolumeType());
params.setVolumeFormat(diskImageBase.getVolumeFormat());
}
params.setParentParameters(getParameters());
return params;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImageBase in project ovirt-engine by oVirt.
the class ImportVmCommand method addVmImagesAndSnapshots.
protected void addVmImagesAndSnapshots() {
Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(getImages());
if (isCopyCollapseOrNoSnapshots()) {
Guid snapshotId = Guid.newGuid();
int aliasCounter = 0;
for (List<DiskImage> diskList : images.values()) {
DiskImage disk = getActiveVolumeDisk(diskList);
disk.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
disk.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
disk.setVmSnapshotId(snapshotId);
disk.setActive(true);
if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(disk.getId())) {
DiskImageBase diskImageBase = (DiskImageBase) getParameters().getVm().getDiskMap().get(disk.getId());
disk.setVolumeFormat(diskImageBase.getVolumeFormat());
disk.setVolumeType(diskImageBase.getVolumeType());
}
setDiskStorageDomainInfo(disk);
if (getParameters().isImportAsNewEntity()) {
generateNewDiskId(diskList, disk);
updateManagedDeviceMap(disk, getVm().getStaticData().getManagedDeviceMap());
} else {
newDiskIdForDisk.put(disk.getId(), disk);
}
disk.setCreationDate(new Date());
saveImage(disk);
ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
saveBaseDisk(disk);
saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
saveDiskImageDynamic(disk);
}
Snapshot snapshot = addActiveSnapshot(snapshotId);
getVm().setSnapshots(Arrays.asList(snapshot));
} else {
Guid snapshotId = null;
for (DiskImage disk : getImages()) {
disk.setActive(false);
setDiskStorageDomainInfo(disk);
saveImage(disk);
snapshotId = disk.getVmSnapshotId();
saveSnapshotIfNotExists(snapshotId, disk);
saveDiskImageDynamic(disk);
}
int aliasCounter = 0;
for (List<DiskImage> diskList : images.values()) {
DiskImage disk = getActiveVolumeDisk(diskList);
newDiskIdForDisk.put(disk.getId(), disk);
snapshotId = disk.getVmSnapshotId();
disk.setActive(true);
ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
updateImage(disk);
saveBaseDisk(disk);
saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
}
// Update active snapshot's data, since it was inserted as a regular snapshot.
updateActiveSnapshot(snapshotId);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImageBase in project ovirt-engine by oVirt.
the class ImportVmCommand method validateAfterCloneVm.
protected boolean validateAfterCloneVm(Map<Guid, StorageDomain> domainsMap) {
VM vmFromParams = getParameters().getVm();
// check that the imported vm guid is not in engine
if (!validateNoDuplicateVm()) {
return false;
}
if (!validateNoDuplicateDiskImages(imageList)) {
return false;
}
setVmTemplateId(getVm().getVmtGuid());
if (!templateExists() || !checkTemplateInStorageDomain() || !checkImagesGUIDsLegal() || !validateUniqueVmName()) {
return false;
}
if (!VmTemplateHandler.BLANK_VM_TEMPLATE_ID.equals(getVm().getVmtGuid()) && getVmTemplate() != null && getVmTemplate().getStatus() == VmTemplateStatus.Locked) {
return failValidation(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
}
if (!validateLunDisksForVm(vmFromParams)) {
return false;
}
if (getParameters().getCopyCollapse() && vmFromParams.getDiskMap() != null) {
for (Disk disk : vmFromParams.getDiskMap().values()) {
if (disk.getDiskStorageType() == DiskStorageType.IMAGE) {
DiskImage key = (DiskImage) getVm().getDiskMap().get(disk.getId());
if (key != null) {
if (!ImagesHandler.checkImageConfiguration(domainsMap.get(imageToDestinationDomainMap.get(key.getId())).getStorageStaticData(), (DiskImageBase) disk, getReturnValue().getValidationMessages())) {
return false;
}
}
}
}
}
// (backup) domain
if (getParameters().getCopyCollapse() && !isTemplateExistsOnExportDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMPORTED_TEMPLATE_IS_MISSING, String.format("$DomainName %1$s", storageDomainStaticDao.get(getParameters().getSourceDomainId()).getStorageName()));
}
if (!validateVmArchitecture()) {
return false;
}
if (!validateVdsCluster()) {
return false;
}
if (!isImagesAlreadyOnTarget()) {
if (!handleDestStorageDomains()) {
return false;
}
}
if (!validateGraphicsAndDisplay()) {
return false;
}
if (!getParameters().isImportAsNewEntity()) {
List<VmNetworkInterface> vmNetworkInterfaces = getVm().getInterfaces();
if (!validate(vmNicMacsUtils.validateThereIsEnoughOfFreeMacs(vmNetworkInterfaces, getMacPool(), getVnicRequiresNewMacPredicate()))) {
return false;
}
if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
return false;
}
}
if (!setAndValidateDiskProfiles()) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImageBase in project ovirt-engine by oVirt.
the class AddVmFromTemplateCommand method buildDiskCreationParameters.
@Override
protected CreateCloneOfTemplateParameters buildDiskCreationParameters(DiskImage disk) {
DiskImageBase diskInfo = getParameters().getDiskInfoDestinationMap().get(disk.getId());
CreateCloneOfTemplateParameters params = new CreateCloneOfTemplateParameters(disk.getImageId(), getParameters().getVmStaticData().getId(), diskInfo);
params.setStorageDomainId(diskInfoSourceMap.get(disk.getId()));
params.setDestStorageDomainId(retrieveDestinationDomainForDisk(disk.getId()));
params.setDiskAlias(diskInfoDestinationMap.get(disk.getId()).getDiskAlias());
params.setVmSnapshotId(getVmSnapshotId());
params.setParentCommand(ActionType.AddVmFromTemplate);
params.setParentParameters(getParameters());
params.setEntityInfo(getParameters().getEntityInfo());
params.setQuotaId(diskInfoDestinationMap.get(disk.getId()).getQuotaId() != null ? diskInfoDestinationMap.get(disk.getId()).getQuotaId() : null);
params.setDiskProfileId(diskInfoDestinationMap.get(disk.getId()).getDiskProfileId());
return params;
}
Aggregations