use of org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_NODE in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseMemories.
private List<Map<String, Object>> parseMemories(XmlDocument document, List<VmDevice> devices) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.MEMORY);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : selectNodes(document, VmDeviceGeneralType.MEMORY)) {
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.MEMORY.getValue());
dev.put(VdsProperties.Device, VmDeviceGeneralType.MEMORY.getValue());
dev.put(VdsProperties.Address, parseAddress(node));
dev.put(VdsProperties.Alias, parseAlias(node));
XmlNode target = node.selectSingleNode("target");
if (target == null) {
continue;
}
String devNode = target.selectSingleNode(NODE).innerText;
String devSize = kiloBytesToMegaBytes(target.selectSingleNode(SIZE).innerText);
VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().sorted(// try to match managed devices first
Comparator.comparing(VmDevice::isManaged).reversed()).filter(d -> d.getDevice().equals(device.get(VdsProperties.Device))).filter(d -> Objects.equals(d.getSpecParams().get(SPEC_PARAM_NODE).toString(), devNode)).filter(d -> Objects.equals(d.getSpecParams().get(SPEC_PARAM_SIZE).toString(), devSize)).findFirst().orElse(null));
if (dbDev != null) {
dbDevices.remove(dbDev);
dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
} else {
dev.put(VdsProperties.DeviceId, Guid.newGuid().toString());
Map<String, Object> specParams = new HashMap<>();
specParams.put(SPEC_PARAM_NODE, devNode);
specParams.put(SPEC_PARAM_SIZE, devSize);
dev.put(VdsProperties.SpecParams, specParams);
}
result.add(dev);
}
return result;
}
Aggregations