Search in sources :

Example 6 with XmlDocument

use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.

the class OvfManager method importVm.

public void importVm(String ovfstring, VM vm, FullEntityOvfData fullEntityOvfData) throws OvfReaderException {
    OvfReader ovf = null;
    try {
        ovf = new OvfVmReader(new XmlDocument(ovfstring), vm, fullEntityOvfData, osRepository);
        ovf.build();
        initIcons(vm.getStaticData());
    } catch (Exception ex) {
        String message = generateOvfReaderErrorMessage(ovf, ex);
        logOvfLoadError(message, ovfstring);
        throw new OvfReaderException(message);
    }
    Guid id = vm.getStaticData().getId();
    fullEntityOvfData.getInterfaces().forEach(iface -> iface.setVmId(id));
}
Also used : XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Guid(org.ovirt.engine.core.compat.Guid)

Example 7 with XmlDocument

use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.

the class ScanStorageForUnregisteredDisksCommand method setVmsForUnregisteredDisks.

protected void setVmsForUnregisteredDisks(List<OvfEntityData> allEntities) {
    for (OvfEntityData ovfEntity : allEntities) {
        try {
            XmlDocument xmlDocument = new XmlDocument(ovfEntity.getOvfData());
            ovfUtils.updateUnregisteredDisksWithVMs(unregisteredDisks, ovfEntity.getEntityId(), ovfEntity.getEntityName(), xmlDocument);
        } catch (Exception e) {
            log.warn("Could not parse OVF data of VM");
            continue;
        }
    }
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument)

Example 8 with XmlDocument

use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument 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 9 with XmlDocument

use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.

the class OvfUtilsTest method testUpdateUnregisteredDisksWithVMsWithEmptyUnregDisks.

@Test
public void testUpdateUnregisteredDisksWithVMsWithEmptyUnregDisks() throws Exception {
    XmlDocument xmlDocument = new XmlDocument(getXmlOvfData());
    List<UnregisteredDisk> unregDisks = new ArrayList<>();
    ovfUtils.updateUnregisteredDisksWithVMs(unregDisks, Guid.newGuid(), "TestVM", xmlDocument);
    assertTrue("The list of disks should not be empty", unregDisks.isEmpty());
}
Also used : UnregisteredDisk(org.ovirt.engine.core.common.businessentities.storage.UnregisteredDisk) ArrayList(java.util.ArrayList) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Test(org.junit.Test)

Example 10 with XmlDocument

use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.

the class OvfUtilsTest method testMemoryDisks.

@Test
public void testMemoryDisks() throws Exception {
    XmlDocument xmlDocument = new XmlDocument(getXmlOvfData());
    Set<Guid> memoryDisks = ovfUtils.fetchMemoryDisks(xmlDocument);
    assertFalse("The list of memory disks for snapshot should not be empty", memoryDisks.isEmpty());
}
Also used : XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Aggregations

XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)21 Guid (org.ovirt.engine.core.compat.Guid)14 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)10 HashMap (java.util.HashMap)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 Arrays (java.util.Arrays)8 Collections (java.util.Collections)8 Comparator (java.util.Comparator)8 List (java.util.List)8 Objects (java.util.Objects)8 Optional (java.util.Optional)8 Function (java.util.function.Function)8 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 Singleton (javax.inject.Singleton)8 StringUtils (org.apache.commons.lang.StringUtils)8 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)8 UsbControllerModel (org.ovirt.engine.core.common.businessentities.UsbControllerModel)8