Search in sources :

Example 11 with XmlDocument

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

the class OvfUtilsTest method testUpdateUnregisteredDisksWithVMsWithInitializedUnregDisks.

@Test
public void testUpdateUnregisteredDisksWithVMsWithInitializedUnregDisks() throws Exception {
    XmlDocument xmlDocument = new XmlDocument(getXmlOvfData());
    List<UnregisteredDisk> unregDisks = new ArrayList<>();
    DiskImage diskImage = new DiskImage();
    diskImage.setId(Guid.createGuidFromString("8c634412-1e8b-4ef3-bc40-b67a456e9d2f"));
    diskImage.setStorageIds(new ArrayList<>(Collections.singletonList(Guid.createGuidFromString("7e2a7eac-3b76-4d45-a7dd-caae8fe0f588"))));
    UnregisteredDisk unregDisk = new UnregisteredDisk(diskImage);
    unregDisks.add(unregDisk);
    ovfUtils.updateUnregisteredDisksWithVMs(unregDisks, Guid.newGuid(), "TestVM", xmlDocument);
    assertTrue("The list of disks should not be empty", !unregDisks.isEmpty());
    assertTrue("The VMs id is set in the unregisteterd disks", !unregDisks.get(0).getVms().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) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 12 with XmlDocument

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

the class OvfUtilsTest method testIsExternalVM.

@Test
public void testIsExternalVM() throws Exception {
    XmlDocument xmlDocument = new XmlDocument(getXmlOvfData());
    assertFalse("VM should not be external VM", ovfUtils.isExternalVM(xmlDocument));
}
Also used : XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Test(org.junit.Test)

Example 13 with XmlDocument

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

the class OvfManager method importVmFromOva.

public void importVmFromOva(String ovfstring, VM vm, FullEntityOvfData fullEntityOvfData) throws OvfReaderException {
    OvfReader ovf = null;
    try {
        ovf = new OvfOvaReader(new XmlDocument(ovfstring), fullEntityOvfData, vm, osRepository);
        ovf.build();
    } 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 14 with XmlDocument

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

the class OvfUtils method fetchLeaseDomainId.

public static Guid fetchLeaseDomainId(String ovfData) {
    Guid leaseDomainId = null;
    try {
        XmlDocument xmlDocument = new XmlDocument(ovfData);
        XmlNode xmlNode = xmlDocument.selectSingleNode("//*/Content").selectSingleNode("LeaseDomainId");
        if (xmlNode != null) {
            leaseDomainId = Guid.createGuidFromString(xmlNode.innerText);
        }
    } catch (Exception e) {
        log.debug("failed to parse a given ovf configuration: \n" + ovfData, e);
    }
    return leaseDomainId;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Guid(org.ovirt.engine.core.compat.Guid) IOException(java.io.IOException)

Example 15 with XmlDocument

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

the class VmDevicesConverterTest method parseVolumeChainNoItem.

@Test
public void parseVolumeChainNoItem() throws Exception {
    XmlDocument devices = new XmlDocument(DEVICES_XML);
    List<Map<String, Object>> res = converter.parseVolumeChain(devices.selectSingleNode("//*/disk[1]"));
    assertEquals(0, res.size());
}
Also used : XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Map(java.util.Map) 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