use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfUtils method isExternalVM.
public boolean isExternalVM(XmlDocument xmlDocument) {
XmlNode content = xmlDocument.selectSingleNode("//*/Content");
NodeList nodeList = content.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeName().equals(VM_ORIGIN) && node.getChildNodes().item(0) != null) {
Integer originType = Integer.valueOf(node.getChildNodes().item(0).getNodeValue());
return OriginType.EXTERNAL == OriginType.forValue(originType);
}
}
return false;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode 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;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseDev.
/**
* This method should be used for managed devices with one instance per VM
*/
private Map<String, Object> parseDev(VmDeviceGeneralType devType, XmlDocument document, List<VmDevice> devices) {
VmDevice dbDevice = filterDevice(devices, devType);
if (dbDevice == null) {
return Collections.emptyMap();
}
XmlNode node = selectSingleNode(document, devType);
if (node == null) {
return Collections.emptyMap();
}
Map<String, Object> result = new HashMap<>();
result.put(VdsProperties.Device, devType);
result.put(VdsProperties.DeviceId, dbDevice.getDeviceId().toString());
result.put(VdsProperties.Address, parseAddress(node));
result.put(VdsProperties.Alias, parseAlias(node));
result.put(VdsProperties.SpecParams, dbDevice.getSpecParams());
return result;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method convert.
public Map<String, Object> convert(Guid vmId, Guid hostId, String xml) throws Exception {
String devicesXml = xml.substring(xml.indexOf(DEVICES_START_ELEMENT), xml.indexOf(DEVICES_END_ELEMENT) + DEVICES_END_ELEMENT.length());
XmlDocument document = new XmlDocument(devicesXml);
XmlNode metadata = new XmlDocument(xml).selectSingleNode("domain/metadata");
Map<String, Object> result = new HashMap<>();
result.put(VdsProperties.vm_guid, vmId.toString());
result.put(VdsProperties.Devices, parseDevices(vmId, hostId, document));
result.put(VdsProperties.GuestDiskMapping, parseDiskMapping(metadata));
return result;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseVideos.
private List<Map<String, Object>> parseVideos(XmlDocument document, List<VmDevice> devices) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.VIDEO);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : selectNodes(document, VmDeviceGeneralType.VIDEO)) {
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.VIDEO.getValue());
dev.put(VdsProperties.Device, parseVideoType(node));
dev.put(VdsProperties.Address, parseAddress(node));
dev.put(VdsProperties.Alias, parseAlias(node));
// There is supposed to be one video device of each type (spice/vnc/..)
VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().filter(d -> d.getDevice().equals(device.get(VdsProperties.Device))).findFirst().orElse(null));
if (dbDev == null) {
log.warn("unmanaged video device with address '{}' is ignored", dev.get(VdsProperties.Address));
continue;
}
dbDevices.remove(dbDev);
dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
result.add(dev);
}
return result;
}
Aggregations