use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseUnmanagedHostDevices.
private List<Map<String, Object>> parseUnmanagedHostDevices(XmlDocument document, List<VmDevice> devices, Guid hostId, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.HOSTDEV);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : document.selectNodes("//*/hostdev")) {
Map<String, String> hostAddress = parseHostAddress(node);
if (hostAddress == null) {
continue;
}
if (addressToHostDeviceSupplier.get().containsKey(hostAddress)) {
// managed
continue;
}
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.HOSTDEV.getValue());
dev.put(VdsProperties.Address, parseAddress(node));
dev.put(VdsProperties.Alias, parseAlias(node));
String deviceType = parseAttribute(node, TYPE);
dev.put(VdsProperties.Device, deviceType);
dev.put(VdsProperties.SpecParams, hostAddress);
VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().filter(d -> d.getDevice().equals(deviceType) && Objects.equals(d.getSpecParams(), hostAddress)).findFirst().orElse(null));
dev.put(VdsProperties.DeviceId, dbDev != null ? dbDev.getDeviceId().toString() : Guid.newGuid().toString());
result.add(dev);
}
return result;
}
Aggregations