use of org.ovirt.engine.core.utils.ovf.OvfReaderException in project ovirt-engine by oVirt.
the class ImportVmFromConfigurationCommand method initUnregisteredVM.
private void initUnregisteredVM() {
List<OvfEntityData> ovfEntityDataList = unregisteredOVFDataDao.getByEntityIdAndStorageDomain(getParameters().getContainerId(), getParameters().getStorageDomainId());
if (!ovfEntityDataList.isEmpty()) {
try {
// We should get only one entity, since we fetched the entity with a specific Storage Domain
ovfEntityData = ovfEntityDataList.get(0);
FullEntityOvfData fullEntityOvfData = ovfHelper.readVmFromOvf(ovfEntityData.getOvfData());
VM vmFromConfiguration = fullEntityOvfData.getVm();
if (Guid.isNullOrEmpty(getParameters().getClusterId())) {
Cluster cluster = drMappingHelper.getMappedCluster(fullEntityOvfData.getClusterName(), vmFromConfiguration.getId(), getParameters().getClusterMap());
if (cluster != null) {
getParameters().setClusterId(cluster.getId());
}
}
vmFromConfiguration.setClusterId(getParameters().getClusterId());
getParameters().setVm(vmFromConfiguration);
getParameters().setDestDomainId(ovfEntityData.getStorageDomainId());
getParameters().setSourceDomainId(ovfEntityData.getStorageDomainId());
getParameters().setUserToRoles(fullEntityOvfData.getUserToRoles());
// For quota, update disks when required
if (getParameters().getDiskMap() != null) {
vmFromConfiguration.setDiskMap(getParameters().getDiskMap());
vmFromConfiguration.setImages(getDiskImageListFromDiskMap(getParameters().getDiskMap()));
}
// Note: The VM's OVF does not preserve the username and password for the LUN's connection.
// Therefore to achieve a simple VM registration the iSCSI storage server should not use
// credentials, although if the user will use the mapping attribute, one can set the credentials through
// there.
drMappingHelper.mapExternalLunDisks(DisksFilter.filterLunDisks(vmFromConfiguration.getDiskMap().values()), getParameters().getExternalLunMap());
mapEntities(fullEntityOvfData);
} catch (OvfReaderException e) {
log.error("Failed to parse a given ovf configuration: {}:\n{}", e.getMessage(), ovfEntityData.getOvfData());
log.debug("Exception", e);
}
}
}
use of org.ovirt.engine.core.utils.ovf.OvfReaderException in project ovirt-engine by oVirt.
the class ImportVmTemplateFromConfigurationCommand method initVmTemplate.
private void initVmTemplate() {
List<OvfEntityData> ovfEntityList = unregisteredOVFDataDao.getByEntityIdAndStorageDomain(getParameters().getContainerId(), getParameters().getStorageDomainId());
if (!ovfEntityList.isEmpty()) {
try {
// We should get only one entity, since we fetched the entity with a specific Storage Domain
ovfEntityData = ovfEntityList.get(0);
FullEntityOvfData fullEntityOvfData = ovfHelper.readVmTemplateFromOvf(ovfEntityData.getOvfData());
vmTemplateFromConfiguration = fullEntityOvfData.getVmTemplate();
if (Guid.isNullOrEmpty(getParameters().getClusterId())) {
mapCluster(fullEntityOvfData);
}
vmTemplateFromConfiguration.setClusterId(getParameters().getClusterId());
setVmTemplate(vmTemplateFromConfiguration);
setEffectiveCompatibilityVersion(CompatibilityVersionUtils.getEffective(getVmTemplate(), this::getCluster));
vmHandler.updateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion());
getParameters().setVmTemplate(vmTemplateFromConfiguration);
getParameters().setDestDomainId(ovfEntityData.getStorageDomainId());
getParameters().setSourceDomainId(ovfEntityData.getStorageDomainId());
getParameters().setUserToRoles(fullEntityOvfData.getUserToRoles());
// For quota, update disks when required
if (getParameters().getDiskTemplateMap() != null) {
ArrayList imageList = new ArrayList<>(getParameters().getDiskTemplateMap().values());
vmTemplateFromConfiguration.setDiskList(imageList);
ensureDomainMap(imageList, getParameters().getDestDomainId());
}
if (getParameters().getDomainMap() != null) {
getParameters().setDbUsers(drMappingHelper.mapDbUsers(fullEntityOvfData.getDbUsers(), getParameters().getDomainMap()));
} else {
getParameters().setDbUsers(fullEntityOvfData.getDbUsers());
}
if (getParameters().getRoleMap() != null) {
getParameters().setUserToRoles(drMappingHelper.mapRoles(getParameters().getRoleMap(), getParameters().getUserToRoles()));
} else {
getParameters().setUserToRoles(fullEntityOvfData.getUserToRoles());
}
} catch (OvfReaderException e) {
log.error("Failed to parse a given ovf configuration: {}:\n{}", e.getMessage(), ovfEntityData.getOvfData());
log.debug("Exception", e);
}
}
setClusterId(getParameters().getClusterId());
if (getCluster() != null) {
setStoragePoolId(getCluster().getStoragePoolId());
}
}
use of org.ovirt.engine.core.utils.ovf.OvfReaderException in project ovirt-engine by oVirt.
the class ImagesHandler method prepareSnapshotConfigWithAlternateImage.
/**
* Prepare a single {@link org.ovirt.engine.core.common.businessentities.Snapshot} object representing a snapshot of a given VM without the given disk,
* substituting a new disk in its place if a new disk is provided to the method.
*/
public Snapshot prepareSnapshotConfigWithAlternateImage(Snapshot snapshot, Guid oldImageId, DiskImage newImage, OvfManager ovfManager) {
if (snapshot == null) {
return null;
}
try {
String snapConfig = snapshot.getVmConfiguration();
if (snapshot.isVmConfigurationAvailable() && snapConfig != null) {
VM vmSnapshot = new VM();
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vmSnapshot);
ovfManager.importVm(snapConfig, vmSnapshot, fullEntityOvfData);
// Remove the image from the disk list
Iterator<DiskImage> diskIter = fullEntityOvfData.getDiskImages().iterator();
while (diskIter.hasNext()) {
DiskImage imageInList = diskIter.next();
if (imageInList.getImageId().equals(oldImageId)) {
log.debug("Recreating vmSnapshot '{}' without the image '{}'", snapshot.getId(), oldImageId);
diskIter.remove();
break;
}
}
if (newImage != null) {
log.debug("Adding image '{}' to vmSnapshot '{}'", newImage.getImageId(), snapshot.getId());
newImage.setDiskVmElements(Collections.singletonList(diskVmElementDao.get(new VmDeviceId(newImage.getId(), vmSnapshot.getId()))));
fullEntityOvfData.getDiskImages().add(newImage);
}
final Version compatibilityVersion = Optional.ofNullable(vmSnapshot.getStaticData().getClusterCompatibilityVersionOrigin()).orElse(Version.getLowest());
FullEntityOvfData fullEntityOvfDataForExport = new FullEntityOvfData(vmSnapshot);
fullEntityOvfDataForExport.setDiskImages(fullEntityOvfData.getDiskImages());
String newOvf = ovfManager.exportVm(vmSnapshot, fullEntityOvfDataForExport, compatibilityVersion);
snapshot.setVmConfiguration(newOvf);
}
} catch (OvfReaderException e) {
log.error("Can't remove image '{}' from snapshot '{}'", oldImageId, snapshot.getId());
}
return snapshot;
}
use of org.ovirt.engine.core.utils.ovf.OvfReaderException in project ovirt-engine by oVirt.
the class SnapshotsManager method updateVmFromConfiguration.
/**
* Update the given VM with the (static) data that is contained in the configuration. The {@link VM#getImages()}
* will contain the images that were read from the configuration.
*
* @param vm
* The VM to update.
* @param configuration
* The configuration to update from.
* @return In case of a problem reading the configuration, <code>false</code>. Otherwise, <code>true</code>.
*/
public boolean updateVmFromConfiguration(VM vm, String configuration) {
try {
VmStatic oldVmStatic = vm.getStaticData();
VM tempVM = new VM();
if (vm.getDynamicData() != null) {
tempVM.setDynamicData(vm.getDynamicData());
}
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(tempVM);
ovfManager.importVm(configuration, tempVM, fullEntityOvfData);
for (DiskImage diskImage : fullEntityOvfData.getDiskImages()) {
DiskImage dbImage = diskImageDao.getSnapshotById(diskImage.getImageId());
if (dbImage != null) {
diskImage.setStorageIds(dbImage.getStorageIds());
}
}
new VMStaticOvfLogHandler(tempVM.getStaticData()).resetDefaults(oldVmStatic);
vm.setStaticData(tempVM.getStaticData());
IconUtils.preserveIcons(vm.getStaticData(), oldVmStatic);
vm.setImages((ArrayList<DiskImage>) fullEntityOvfData.getDiskImages());
vm.setInterfaces(fullEntityOvfData.getInterfaces());
// These fields are not saved in the OVF, so get them from the current VM.
vm.setIsoPath(oldVmStatic.getIsoPath());
vm.setCpuProfileId(oldVmStatic.getCpuProfileId());
vm.setClusterId(oldVmStatic.getClusterId());
// The VM configuration does not hold the vds group Id.
// It is necessary to fetch the vm static from the Db, in order to get this information
VmStatic vmStaticFromDb = vmStaticDao.get(vm.getId());
if (vmStaticFromDb != null) {
Cluster cluster = clusterDao.get(vmStaticFromDb.getClusterId());
if (cluster != null) {
vm.setStoragePoolId(cluster.getStoragePoolId());
vm.setClusterCompatibilityVersion(cluster.getCompatibilityVersion());
vm.setClusterName(cluster.getName());
vm.setClusterCpuName(cluster.getCpuName());
}
}
// if the required dedicated host is invalid -> use current VM dedicated host
if (!vmHandler.validateDedicatedVdsExistOnSameCluster(vm.getStaticData()).isValid()) {
vm.setDedicatedVmForVdsList(oldVmStatic.getDedicatedVmForVdsList());
}
vmHandler.updateMaxMemorySize(vm.getStaticData(), vm.getCompatibilityVersion());
vmHandler.autoSelectResumeBehavior(vm.getStaticData(), vm.getCompatibilityVersion());
validateQuota(vm);
return true;
} catch (OvfReaderException e) {
log.error("Failed to update VM from the configuration '{}': {}", configuration, e.getMessage());
log.debug("Exception", e);
return false;
}
}
use of org.ovirt.engine.core.utils.ovf.OvfReaderException in project ovirt-engine by oVirt.
the class SnapshotsManager method canRestoreVmConfigurationFromSnapshot.
public boolean canRestoreVmConfigurationFromSnapshot(VM vm, Snapshot snapshot, VmInterfaceManager vmInterfaceManager) {
if (snapshot.getVmConfiguration() == null) {
return false;
}
VM tempVM = new VM();
if (vm.getDynamicData() != null) {
tempVM.setDynamicData(vm.getDynamicData());
}
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(tempVM);
try {
ovfManager.importVm(snapshot.getVmConfiguration(), tempVM, fullEntityOvfData);
} catch (OvfReaderException e) {
log.error("Failed to import VM from the configuration '{}': {}", snapshot.getVmConfiguration(), e.getMessage());
log.debug("Exception", e);
return false;
}
boolean macsInSnapshotAreExpectedToBeAlreadyAllocated = SnapshotType.STATELESS.equals(snapshot.getType());
return canSynchronizeNics(vm, vmInterfaceManager, fullEntityOvfData.getInterfaces(), macsInSnapshotAreExpectedToBeAlreadyAllocated);
}
Aggregations