use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class OvfUtils method createOvfEntityData.
private static OvfEntityData createOvfEntityData(Guid storageDomainId, String ovfData, VmEntityType vmEntityType, String entityName, ArchitectureType archType, Guid entityId) {
OvfEntityData ovfEntityData = new OvfEntityData();
ovfEntityData.setOvfData(ovfData);
ovfEntityData.setEntityType(vmEntityType);
ovfEntityData.setEntityName(entityName);
ovfEntityData.setStorageDomainId(storageDomainId);
ovfEntityData.setArchitecture(archType);
ovfEntityData.setEntityId(entityId);
return ovfEntityData;
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class OvfUtils method analyzeOvfFile.
private void analyzeOvfFile(List<UnregisteredDisk> unregisteredDisks, Guid storageDomainId, List<OvfEntityData> ovfEntityDataFromTar, Entry<String, ByteBuffer> fileEntry) {
String ovfData = new String(fileEntry.getValue().array());
VmEntityType vmType = getVmEntityType(ovfData);
ArchitectureType archType = null;
Guid entityId = getEntityId(fileEntry.getKey());
String vmName = getEntityName(ovfData);
try {
XmlDocument xmlDocument = new XmlDocument(ovfData);
archType = getOsSection(xmlDocument);
if (isExternalVM(xmlDocument)) {
log.warn("Retrieve an external OVF Entity from storage domain ID '{}' for entity ID '{}'," + " entity name '{}' and VM Type of '{}'." + " This OVF will be ignored since external VMs should not be restored.", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name());
return;
}
updateUnregisteredDisksWithVMs(unregisteredDisks, entityId, vmName, xmlDocument);
} catch (Exception e) {
log.error("Could not parse VM's disks or architecture, file name: {}, content size: {}, error: {}", fileEntry.getKey(), ovfData.length(), e.getMessage());
log.debug("Exception", e);
return;
}
// Creates an OVF entity data.
OvfEntityData ovfEntityData = createOvfEntityData(storageDomainId, ovfData, vmType, vmName, archType, entityId);
log.info("Retrieve OVF Entity from storage domain ID '{}' for entity ID '{}', entity name '{}' and VM Type of '{}'", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name());
ovfEntityDataFromTar.add(ovfEntityData);
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData 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;
});
}
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class ImportVMFromConfigurationCommandTest method getOvfEntityData.
private OvfEntityData getOvfEntityData() {
OvfEntityData ovfEntity = new OvfEntityData();
ovfEntity.setEntityId(vmId);
ovfEntity.setEntityName("Some VM");
ovfEntity.setOvfData(xmlOvfData);
return ovfEntity;
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class ImportVMFromConfigurationCommandTest method testImportVMFromConfigurationXMLCouldNotGetParsed.
@Test
public void testImportVMFromConfigurationXMLCouldNotGetParsed() {
OvfEntityData ovfEntity = getOvfEntityData();
ovfEntity.setOvfData("This is not a valid XML");
initCommand(ovfEntity);
List<OvfEntityData> ovfEntityDataList = new ArrayList<>();
ovfEntityDataList.add(ovfEntity);
doReturn(true).when(cmd).validateBeforeCloneVm(any());
doReturn(true).when(cmd).validateAfterCloneVm(any());
when(unregisteredOVFDataDao.getByEntityIdAndStorageDomain(vmId, storageDomainId)).thenReturn(ovfEntityDataList);
when(validator.validateUnregisteredEntity(any())).thenReturn(new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_OVF_CONFIGURATION_NOT_SUPPORTED));
ValidateTestUtils.runAndAssertValidateFailure(cmd, EngineMessage.ACTION_TYPE_FAILED_OVF_CONFIGURATION_NOT_SUPPORTED);
}
Aggregations