use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.
the class VmDevicesConverterTest method parseVolumeChainMoreItems.
@Test
public void parseVolumeChainMoreItems() throws Exception {
XmlDocument devices = new XmlDocument(DEVICES_XML);
List<Map<String, Object>> res = converter.parseVolumeChain(devices.selectSingleNode("//*/disk[2]"));
assertEquals(3, res.size());
assertEquals(res.get(0).get(VdsProperties.VolumeId), "cc5beaf2-3265-4b36-b7be-4f23dc3b07af");
assertEquals(res.get(1).get(VdsProperties.VolumeId), "fff3c995-e7c3-4a2c-96a3-f0ce569a57c2");
assertEquals(res.get(2).get(VdsProperties.VolumeId), "011046ce-312a-42e6-bcb7-764fd332da02");
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument 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.XmlDocument 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;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseControllers.
private List<Map<String, Object>> parseControllers(XmlDocument document, List<VmDevice> devices) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.CONTROLLER);
// devices with spec params to appear first
dbDevices.sort((d1, d2) -> d1.getSpecParams().isEmpty() && !d2.getSpecParams().isEmpty() ? 1 : 0);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : selectNodes(document, VmDeviceGeneralType.CONTROLLER)) {
String address = parseAddress(node);
String index = parseAttribute(node, INDEX);
String model = parseAttribute(node, MODEL);
Integer ioThreadId = parseIoThreadId(node);
String devType = "virtio-scsi".equals(model) ? model : parseAttribute(node, TYPE);
boolean devWithModelNone = model != null ? model.equals(UsbControllerModel.NONE.libvirtName) : false;
// which is a special case of a device without address that is still marked as plugged
if (address.isEmpty() && !devWithModelNone) {
continue;
}
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.CONTROLLER.getValue());
dev.put(VdsProperties.Device, devType);
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))).filter(d -> {
if (d.getSpecParams().isEmpty()) {
return true;
}
if (ioThreadId != null && Objects.equals(d.getSpecParams().get(IO_THREAD_ID), ioThreadId)) {
return true;
}
if (Objects.equals(d.getSpecParams().get(INDEX), index) && Objects.equals(d.getSpecParams().get(MODEL), model)) {
return true;
}
return false;
}).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<>();
if (index != null) {
specParams.put(INDEX, index);
}
if (model != null) {
specParams.put(MODEL, model);
}
if (ioThreadId != null) {
specParams.put(IO_THREAD_ID, ioThreadId);
}
dev.put(VdsProperties.SpecParams, specParams);
}
result.add(dev);
}
return result;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlDocument in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseRedirs.
private List<Map<String, Object>> parseRedirs(XmlDocument document, List<VmDevice> devices) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.REDIR);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : document.selectNodes("//*/redirdev")) {
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Type, VmDeviceGeneralType.REDIR.getValue());
dev.put(VdsProperties.Device, parseAttribute(node, TYPE));
dev.put(VdsProperties.Address, parseAddress(node));
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;
}
Aggregations