use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseDisks.
private List<Map<String, Object>> parseDisks(XmlDocument document, List<VmDevice> devices) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.DISK);
MemoizingSupplier<Map<Guid, String>> diskToLunSupplier = new MemoizingSupplier<>(() -> diskLunMapDao.getAll().stream().collect(Collectors.toMap(DiskLunMap::getDiskId, DiskLunMap::getLunId)));
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : selectNodes(document, VmDeviceGeneralType.DISK)) {
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.DISK.getValue());
String diskType = parseAttribute(node, DEVICE);
dev.put(VdsProperties.Device, diskType);
dev.put(VdsProperties.Address, parseAddress(node));
dev.put(VdsProperties.Alias, parseAlias(node));
String path = parseDiskPath(node);
VmDevice dbDev = correlate(dev, dbDevices, device -> findDiskDeviceInDbByPath(dbDevices, diskType, path, diskToLunSupplier));
if (dbDev == null) {
log.warn("unmanaged disk with path '{}' is ignored", path);
continue;
}
dbDevices.remove(dbDev);
dev.put(VdsProperties.ImageId, parseImageIdFromPath(path));
dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
List<Map<String, Object>> volumeChain = parseVolumeChain(node);
if (!volumeChain.isEmpty()) {
dev.put(VdsProperties.VolumeChain, volumeChain.toArray());
}
result.add(dev);
}
return result;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode 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;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseChannels.
private List<Map<String, Object>> parseChannels(XmlDocument document, List<VmDevice> devices) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.CHANNEL);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : selectNodes(document, VmDeviceGeneralType.CHANNEL)) {
String address = parseAddress(node);
// Ignore channel devices without address
if (address.isEmpty()) {
continue;
}
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.CHANNEL.getValue());
// shouldn't it be VdsProperties.DeviceType?
dev.put(VdsProperties.Device, parseAttribute(node, TYPE));
dev.put(VdsProperties.Address, address);
dev.put(VdsProperties.Alias, parseAlias(node));
VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().filter(d -> d.getDevice().equals(device.get(VdsProperties.Device))).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());
}
result.add(dev);
}
return result;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseAddress.
private String parseAddress(XmlNode node) {
String result = "";
XmlNode addressNode = node.selectSingleNode("address");
if (addressNode == null) {
return "";
}
XmlAttribute val = addressNode.attributes.get("type");
result += String.format("%s=%s", "type", val.getValue());
val = addressNode.attributes.get("slot");
if (val != null) {
result += String.format(", %s=%s", "slot", val.getValue());
}
val = addressNode.attributes.get("bus");
if (val != null) {
result += String.format(", %s=%s", "bus", val.getValue());
}
val = addressNode.attributes.get("domain");
if (val != null) {
result += String.format(", %s=%s", "domain", val.getValue());
}
val = addressNode.attributes.get("function");
if (val != null) {
result += String.format(", %s=%s", "function", val.getValue());
}
val = addressNode.attributes.get("controller");
if (val != null) {
result += String.format(", %s=%s", "controller", val.getValue());
}
val = addressNode.attributes.get("target");
if (val != null) {
result += String.format(", %s=%s", "target", val.getValue());
}
val = addressNode.attributes.get("unit");
if (val != null) {
result += String.format(", %s=%s", "unit", val.getValue());
}
val = addressNode.attributes.get("port");
if (val != null) {
result += String.format(", %s=%s", "port", val.getValue());
}
val = addressNode.attributes.get("multifunction");
if (val != null) {
result += String.format(", %s=%s", "multifunction", val.getValue());
}
val = addressNode.attributes.get("base");
if (val != null) {
result += String.format(", %s=%s", "base", val.getValue());
}
return result.isEmpty() ? result : String.format("{%s}", result);
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseDiskMapping.
@SuppressWarnings("unchecked")
private Map<String, Object> parseDiskMapping(XmlNode metadata) throws Exception {
if (metadata == null) {
return null;
}
XmlNamespaceManager xmlNS = new XmlNamespaceManager();
xmlNS.addNamespace(LibvirtVmXmlBuilder.OVIRT_VM_PREFIX, LibvirtVmXmlBuilder.OVIRT_VM_URI);
XmlNode vm = metadata.selectSingleNode("ovirt-vm:vm", xmlNS);
if (vm == null) {
return null;
}
Map<String, Object> result = new HashMap<>();
for (XmlNode node : vm.selectNodes("ovirt-vm:device", xmlNS)) {
if (!VmDeviceGeneralType.DISK.getValue().equals(parseAttribute(node, "devtype"))) {
continue;
}
XmlNode guestNameNode = node.selectSingleNode("ovirt-vm:guestName", xmlNS);
if (guestNameNode != null) {
// guest disk mapping is not available for LUNs at the moment
result.put(node.selectSingleNode("ovirt-vm:imageID", xmlNS).innerText, Collections.singletonMap(VdsProperties.Name, guestNameNode.innerText));
}
}
return result;
}
Aggregations