use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmDevicesMonitoring method buildNewVmDevice.
/**
* Builds a new device structure for the device recognized by libvirt.
*/
private VmDevice buildNewVmDevice(Guid vmId, Map device, String logicalName) {
String typeName = (String) device.get(VdsProperties.Type);
String deviceName = (String) device.get(VdsProperties.Device);
// do not allow null or empty device or type values
if (StringUtils.isEmpty(typeName) || StringUtils.isEmpty(deviceName)) {
log.error("Empty or NULL values were passed for a VM '{}' device, Device is skipped", vmId);
return null;
}
String address = device.get(VdsProperties.Address).toString();
String alias = StringUtils.defaultString((String) device.get(VdsProperties.Alias));
Map<String, Object> specParams = (Map<String, Object>) device.get(VdsProperties.SpecParams);
specParams = specParams != null ? specParams : new HashMap<>();
Guid newDeviceId = Guid.newGuid();
VmDeviceId id = new VmDeviceId(newDeviceId, vmId);
Object deviceReadonlyValue = device.get(VdsProperties.ReadOnly);
boolean isReadOnly = deviceReadonlyValue != null && Boolean.getBoolean(deviceReadonlyValue.toString());
VmDevice newDevice = new VmDevice(id, VmDeviceGeneralType.forValue(typeName), deviceName, address, specParams, false, true, isReadOnly, alias, null, null, logicalName);
if (VmDeviceCommonUtils.isMemory(newDevice)) {
fixMemorySpecParamsTypes(newDevice);
}
log.debug("New device was marked for adding to VM '{}' Device : '{}'", vmId, newDevice);
return newDevice;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseBalloon.
private Map<String, Object> parseBalloon(XmlDocument document, List<VmDevice> devices) {
VmDevice dbDevice = filterDevice(devices, VmDeviceGeneralType.BALLOON);
if (dbDevice == null) {
return Collections.emptyMap();
}
XmlNode node = document.selectSingleNode("//*/memballoon");
if (node == null) {
return Collections.emptyMap();
}
Map<String, Object> result = new HashMap<>();
result.put(VdsProperties.Device, "memballoon");
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.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseInterfaces.
private List<Map<String, Object>> parseInterfaces(XmlDocument document, List<VmDevice> devices, Guid vmId, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.INTERFACE);
Map<Guid, VmDevice> devIdToDbDev = dbDevices.stream().collect(Collectors.toMap(device -> device.getDeviceId(), device -> device));
List<VmNetworkInterface> dbInterfaces = vmNetworkInterfaceDao.getAllForVm(vmId);
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : selectNodes(document, VmDeviceGeneralType.INTERFACE)) {
String type = parseAttribute(node, TYPE);
Map<String, Object> dev = new HashMap<>();
if (VmDeviceType.HOST_DEVICE.getName().equals(type)) {
dev.put(VdsProperties.HostDev, getHostDeviceName(node, addressToHostDeviceSupplier));
}
dev.put(VdsProperties.Type, VmDeviceGeneralType.INTERFACE.getValue());
dev.put(VdsProperties.Device, type);
dev.put(VdsProperties.Address, parseAddress(node));
dev.put(VdsProperties.Alias, parseAlias(node));
String macAddress = parseMacAddress(node);
// MAC address is a unique identifier of network interface devices
VmDevice dbDev = correlate(dev, dbDevices, device -> {
VmNetworkInterface dbInterface = dbInterfaces.stream().filter(iface -> iface.getMacAddress().equalsIgnoreCase(macAddress)).findFirst().orElse(null);
return dbInterface != null ? devIdToDbDev.get(dbInterface.getId()) : null;
});
if (dbDev == null) {
log.warn("unmanaged network interface with mac address '{}' is ignored", macAddress);
continue;
}
dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
result.add(dev);
}
return result;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmDevicesConverter method parseManagedHostDevices.
/**
* This method processes managed host devices (those that are set by the engine).
* That means that the device should already exist in the database and can be correlated
* with one of the devices of the host. Host devices that were designed to be added as
* unmanaged devices, like mdev devices, are handled separately.
*/
private List<Map<String, Object>> parseManagedHostDevices(XmlDocument document, List<VmDevice> devices, Guid hostId, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.HOSTDEV);
if (dbDevices.isEmpty()) {
return Collections.emptyList();
}
List<Map<String, Object>> result = new ArrayList<>();
for (XmlNode node : document.selectNodes("//*/hostdev")) {
Map<String, String> hostAddress = parseHostAddress(node);
if (hostAddress == null) {
continue;
}
HostDevice hostDevice = addressToHostDeviceSupplier.get().get(hostAddress);
if (hostDevice == null) {
// unmanaged
continue;
}
Map<String, Object> dev = new HashMap<>();
dev.put(VdsProperties.Address, parseAddress(node));
dev.put(VdsProperties.Type, VmDeviceGeneralType.HOSTDEV.getValue());
dev.put(VdsProperties.Alias, parseAlias(node));
dev.put(VdsProperties.Device, hostDevice.getDeviceName());
VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().filter(d -> d.getDevice().equals(hostDevice.getDeviceName())).findFirst().orElse(null));
if (dbDev == null) {
log.warn("VM host device '{}' does not exist in the database, thus ignored", hostDevice.getDeviceName());
continue;
}
dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
result.add(dev);
}
return result;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method updateGraphics.
protected void updateGraphics(Guid id) {
Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(id), new AsyncQuery<QueryReturnValue>(returnValue -> {
List<VmDevice> graphicsVmDevs = returnValue.getReturnValue();
List<GraphicsType> graphicsTypes = new ArrayList<>();
for (VmDevice graphicsVmDev : graphicsVmDevs) {
graphicsTypes.add(GraphicsType.fromString(graphicsVmDev.getDevice()));
}
boolean hasSpiceAndVnc = graphicsTypes.size() == 2 && graphicsTypes.containsAll(Arrays.asList(GraphicsType.SPICE, GraphicsType.VNC));
boolean canBeSelected = getModel().getGraphicsType().getItems().contains(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
if (hasSpiceAndVnc && canBeSelected) {
getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
} else if (graphicsVmDevs.size() == 1) {
GraphicsType type = GraphicsType.fromString(graphicsVmDevs.get(0).getDevice());
getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.fromGraphicsType(type));
}
}));
}
Aggregations