use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class LibvirtVmXmlBuilder method writeCdRom.
private void writeCdRom(List<VmDevice> devices) {
// <disk type='file' device='cdrom' snapshot='no'>
// <driver name='qemu' type='raw' error_policy='report' />
// <source file='<path>' startupPolicy='optional'/>
// <target dev='hdc' bus='ide'/>
// <readonly/>
// <address type='drive' controller='0' bus='1' target='0' unit='0'/>
// </disk>
devices.stream().filter(d -> VmPayload.isPayload(d.getSpecParams())).forEach(device -> {
writer.writeStartElement("disk");
writer.writeAttributeString("type", "file");
writer.writeAttributeString("device", "cdrom");
writer.writeAttributeString("snapshot", "no");
writer.writeStartElement("driver");
writer.writeAttributeString("name", "qemu");
writer.writeAttributeString("type", "raw");
writer.writeAttributeString("error_policy", "report");
writer.writeEndElement();
writer.writeStartElement("source");
writer.writeAttributeString("file", "PAYLOAD:");
writer.writeAttributeString("startupPolicy", "optional");
writer.writeEndElement();
payloadIndex = VmDeviceCommonUtils.getCdPayloadDeviceIndex(cdInterface);
writer.writeStartElement("target");
String name = vmInfoBuildUtils.makeDiskName(cdInterface, payloadIndex);
writer.writeAttributeString("dev", name);
writer.writeAttributeString("bus", cdInterface);
writer.writeEndElement();
writer.writeElement("readonly");
writeAlias(device);
if ("scsi".equals(cdInterface)) {
int index = VmDeviceCommonUtils.getCdPayloadDeviceIndex(cdInterface);
writeAddress(vmInfoBuildUtils.createAddressForScsiDisk(0, index));
}
payloadMetadata = new Pair<>(name, new VmPayload(device));
writer.writeEndElement();
});
// add a device that points to vm.getCdPath()
String cdPath = vm.getCdPath();
VmDevice nonPayload = devices.stream().filter(d -> !VmPayload.isPayload(d.getSpecParams())).findAny().orElse(null);
if (nonPayload != null || (vm.isRunOnce() && !StringUtils.isEmpty(cdPath))) {
cdRomIndex = VmDeviceCommonUtils.getCdDeviceIndex(cdInterface);
String dev = vmInfoBuildUtils.makeDiskName(cdInterface, cdRomIndex);
boolean isoOnBlockDomain = vmInfoBuildUtils.isBlockDomainPath(cdPath);
if (isoOnBlockDomain) {
diskMetadata.put(dev, vmInfoBuildUtils.createDiskUuidsMap(vm, cdPath));
}
writer.writeStartElement("disk");
writer.writeAttributeString("type", isoOnBlockDomain ? "block" : "file");
writer.writeAttributeString("device", "cdrom");
writer.writeAttributeString("snapshot", "no");
writer.writeStartElement("driver");
writer.writeAttributeString("name", "qemu");
writer.writeAttributeString("type", "raw");
writer.writeAttributeString("error_policy", "report");
writer.writeEndElement();
writer.writeStartElement("source");
writer.writeAttributeString(isoOnBlockDomain ? "dev" : "file", cdPath);
writer.writeAttributeString("startupPolicy", "optional");
writer.writeEndElement();
writer.writeStartElement("target");
writer.writeAttributeString("dev", dev);
writer.writeAttributeString("bus", cdInterface);
writer.writeEndElement();
writer.writeElement("readonly");
if (nonPayload != null) {
writeAlias(nonPayload);
if ("scsi".equals(cdInterface)) {
writeAddress(vmInfoBuildUtils.createAddressForScsiDisk(0, cdRomIndex));
} else {
writeAddress(nonPayload);
}
writeBootOrder(nonPayload.getBootOrder());
}
writer.writeEndElement();
}
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class LibvirtVmXmlBuilder method overrideDevicesForRunOnce.
private List<VmDevice> overrideDevicesForRunOnce(List<VmDevice> devices) {
if (!vm.isRunOnce()) {
return devices;
}
// video device handling
DisplayType displayType = vm.getDefaultDisplayType();
if (displayType != null) {
// remove existing video device
devices = devices.stream().filter(dev -> dev.getType() != VmDeviceGeneralType.VIDEO).collect(Collectors.toList());
// add new video device
if (displayType != DisplayType.none) {
devices.add(vmInfoBuildUtils.createVideoDeviceByDisplayType(displayType, vm.getId()));
}
}
// graphics device handling
if (displayType == DisplayType.none || (vm.getGraphicsInfos() != null && !vm.getGraphicsInfos().isEmpty())) {
// remove existing graphics devices
devices = devices.stream().filter(dev -> dev.getType() != VmDeviceGeneralType.GRAPHICS).collect(Collectors.toList());
if (displayType != DisplayType.none) {
// add new graphics devices
Map<GraphicsType, GraphicsInfo> infos = vm.getGraphicsInfos();
Map<String, Object> specParamsFromVm = new HashMap<>();
vmInfoBuildUtils.addVmGraphicsOptions(infos, specParamsFromVm, vm);
devices.addAll(vmInfoBuildUtils.createGraphicsDevices(infos, specParamsFromVm, vm.getId()));
}
}
// the user may specify floppy path while there is no device in the database
if (!StringUtils.isEmpty(vm.getFloppyPath()) && devices.stream().noneMatch(dev -> dev.getDevice().equals(VmDeviceType.FLOPPY.getName()))) {
devices.add(vmInfoBuildUtils.createFloppyDevice(vm));
}
return devices;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmManager method estimateOverhead.
private int estimateOverhead(VmStatic vmStatic) {
// Prepare VM object using the available bits and pieces
VM compose = new VM(vmStatic, new VmDynamic(), new VmStatistics(), clusterArchitecture, clusterCompatibilityVersion);
// Load device list, TODO ignores unmanaged devices for now
Map<Guid, VmDevice> devices = vmDeviceDao.getVmDeviceByVmId(vmId).stream().filter(VmDevice::isManaged).collect(Collectors.toMap(d -> d.getId().getDeviceId(), Function.identity()));
vmStatic.setManagedDeviceMap(devices);
return vmOverheadCalculator.getTotalRequiredMemoryInMb(compose);
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method createGraphicsDevices.
public List<VmDevice> createGraphicsDevices(Map<GraphicsType, GraphicsInfo> graphicsInfos, Map<String, Object> extraSpecParams, Guid vmId) {
final Comparator<GraphicsType> spiceLastComparator = ComparatorUtils.sortLast(GraphicsType.SPICE);
final List<Entry<GraphicsType, GraphicsInfo>> sortedGraphicsInfos = graphicsInfos.entrySet().stream().sorted(Comparator.comparing(Entry::getKey, spiceLastComparator)).collect(Collectors.toList());
List<VmDevice> result = new ArrayList<>();
for (Entry<GraphicsType, GraphicsInfo> graphicsInfo : sortedGraphicsInfos) {
VmDevice device = new VmDevice();
device.setId(new VmDeviceId(Guid.newGuid(), vmId));
device.setType(VmDeviceGeneralType.GRAPHICS);
device.setDevice(graphicsInfo.getKey().name().toLowerCase());
device.setPlugged(true);
device.setAddress("");
if (extraSpecParams != null) {
device.setSpecParams(extraSpecParams);
}
result.add(device);
}
return result;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method getVmDeviceUnitMapForScsiDisks.
protected Map<Integer, Map<VmDevice, Integer>> getVmDeviceUnitMapForScsiDisks(VM vm, DiskInterface scsiInterface, boolean reserveFirstTwoLuns, boolean reserveForScsiCd) {
List<Disk> disks = getSortedDisks(vm);
Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = new HashMap<>();
LinkedList<VmDevice> vmDeviceList = new LinkedList<>();
for (Disk disk : disks) {
DiskVmElement dve = disk.getDiskVmElementForVm(vm.getId());
if (dve.getDiskInterface() == scsiInterface) {
VmDevice vmDevice = getVmDeviceByDiskId(disk.getId(), vm.getId());
Map<String, String> address = StringMapUtils.string2Map(vmDevice.getAddress());
String unitStr = address.get(VdsProperties.Unit);
String controllerStr = address.get(VdsProperties.Controller);
// Otherwise, adding to 'vmDeviceList' for setting the unit property later.
if (StringUtils.isNotEmpty(unitStr) && StringUtils.isNotEmpty(controllerStr)) {
Integer controllerInt = Integer.valueOf(controllerStr);
boolean controllerOutOfRange = controllerInt >= vm.getNumOfIoThreads() + getDefaultVirtioScsiIndex(vm);
boolean ioThreadsEnabled = vm.getNumOfIoThreads() > 0 && FeatureSupported.virtioScsiIoThread(vm.getCompatibilityVersion());
if ((ioThreadsEnabled && !controllerOutOfRange) || (controllerInt == getDefaultVirtioScsiIndex(vm))) {
if (!vmDeviceUnitMap.containsKey(controllerInt)) {
vmDeviceUnitMap.put(controllerInt, new HashMap<>());
}
vmDeviceUnitMap.get(controllerInt).put(vmDevice, Integer.valueOf(unitStr));
} else {
// controller id not correct, generate the address again later
vmDevice.setAddress(null);
vmDeviceList.add(vmDevice);
}
} else {
vmDeviceList.add(vmDevice);
}
}
}
// Find available unit (disk's index in VirtIO-SCSI controller) for disks with empty address\
IntStream.range(0, vmDeviceList.size()).forEach(index -> {
VmDevice vmDevice = vmDeviceList.get(index);
// TODO: consider changing this so that it will search for the next available and
// less used controller instead of always starting from index.
int controller = getControllerForScsiDisk(vmDevice, vm, index);
if (!vmDeviceUnitMap.containsKey(controller)) {
vmDeviceUnitMap.put(controller, new HashMap<>());
}
int unit = getAvailableUnitForScsiDisk(vmDeviceUnitMap.get(controller), reserveFirstTwoLuns, reserveForScsiCd && controller == 0);
vmDeviceUnitMap.get(controller).put(vmDevice, unit);
});
return vmDeviceUnitMap;
}
Aggregations