Search in sources :

Example 11 with OvfEntityData

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;
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData)

Example 12 with 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);
}
Also used : ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Guid(org.ovirt.engine.core.compat.Guid) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IOException(java.io.IOException)

Example 13 with 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;
        });
    }
}
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 14 with OvfEntityData

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;
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData)

Example 15 with OvfEntityData

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);
}
Also used : ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)21 ArrayList (java.util.ArrayList)10 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)4 Guid (org.ovirt.engine.core.compat.Guid)4 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Pair (org.ovirt.engine.core.common.utils.Pair)2 XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1