use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method createVideoDeviceByDisplayType.
public VmDevice createVideoDeviceByDisplayType(DisplayType displayType, Guid vmId) {
VmDevice vmDevice = new VmDevice();
vmDevice.setId(new VmDeviceId(Guid.newGuid(), vmId));
vmDevice.setType(VmDeviceGeneralType.VIDEO);
vmDevice.setDevice(displayType.getDefaultVmDeviceType().getName());
vmDevice.setPlugged(true);
vmDevice.setAddress("");
return vmDevice;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method calculateAddressForScsiDisk.
public void calculateAddressForScsiDisk(VM vm, Disk disk, VmDevice device, Map<Integer, Map<VmDevice, Integer>> vmDeviceSpaprVscsiUnitMap, Map<Integer, Map<VmDevice, Integer>> vmDeviceVirtioScsiUnitMap) {
Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
int defaultSpaprVscsiControllerIndex = controllerIndexMap.get(DiskInterface.SPAPR_VSCSI);
int defaultVirtioScsiControllerIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
Integer unitIndex = null;
switch(disk.getDiskVmElementForVm(vm.getId()).getDiskInterface()) {
case SPAPR_VSCSI:
if (StringUtils.isEmpty(device.getAddress())) {
unitIndex = vmDeviceSpaprVscsiUnitMap.get(defaultSpaprVscsiControllerIndex).get(device);
device.setAddress(createAddressForScsiDisk(defaultSpaprVscsiControllerIndex, unitIndex).toString());
}
break;
case VirtIO_SCSI:
int controllerIndex = defaultVirtioScsiControllerIndex;
VmDevice deviceFromMap = device;
for (Map.Entry<Integer, Map<VmDevice, Integer>> controllerToDevices : vmDeviceVirtioScsiUnitMap.entrySet()) {
Optional<VmDevice> maybeDeviceFromMap = controllerToDevices.getValue().keySet().stream().filter(d -> d.getId().equals(device.getId())).findFirst();
if (maybeDeviceFromMap.isPresent()) {
deviceFromMap = maybeDeviceFromMap.get();
controllerIndex = controllerToDevices.getKey();
unitIndex = controllerToDevices.getValue().get(deviceFromMap);
break;
}
}
if (StringUtils.isEmpty(deviceFromMap.getAddress())) {
if (unitIndex == null) {
// should never get here, but for safety having this fallback and generating a new unit id
unitIndex = getAvailableUnitForScsiDisk(vmDeviceVirtioScsiUnitMap.get(controllerIndex), false, false);
log.debug("The unit was null for disk '{}' on controller '{}', generating a new one '{}'", disk.getId(), controllerIndex, unitIndex);
}
device.setAddress(createAddressForScsiDisk(controllerIndex, unitIndex).toString());
}
break;
}
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method createSysprepPayloadDevice.
public VmDevice createSysprepPayloadDevice(String sysPrepContent, VM vm) {
// We do not validate the size of the content being passed to the VM payload by VmPayload.isPayloadSizeLegal().
// The sysprep file size isn't being verified for 3.0 clusters and below, so we maintain the same behavior here.
VmPayload vmPayload = new VmPayload();
vmPayload.setDeviceType(VmDeviceType.FLOPPY);
vmPayload.getFiles().put(osRepository.getSysprepFileName(vm.getOs(), vm.getCompatibilityVersion()), new String(BASE_64.encode(sysPrepContent.getBytes()), StandardCharsets.UTF_8));
return new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.FLOPPY.getName(), "", vmPayload.getSpecParams(), true, true, true, "", null, null, null);
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuilderImpl method buildSysprepVmPayload.
@Override
public void buildSysprepVmPayload(String sysPrepContent) {
VmDevice vmDevice = vmInfoBuildUtils.createSysprepPayloadDevice(sysPrepContent, vm);
Map<String, Object> struct = vmInfoBuildUtils.buildFloppyDetails(vmDevice);
addDevice(struct, vmDevice, vm.getFloppyPath());
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class UpdateVmDiskCommand method loadVmDiskAttachedToInfo.
private void loadVmDiskAttachedToInfo() {
if (getOldDisk() != null) {
List<Pair<VM, VmDevice>> attachedVmsInfo = vmDao.getVmsWithPlugInfo(getOldDisk().getId());
for (Pair<VM, VmDevice> pair : attachedVmsInfo) {
VM vm = pair.getFirst();
vmsDiskOrSnapshotAttachedTo.add(vm);
if (Boolean.TRUE.equals(pair.getSecond().isPlugged())) {
if (pair.getSecond().getSnapshotId() != null) {
vmsDiskSnapshotPluggedTo.add(vm);
} else {
vmsDiskPluggedTo.add(vm);
}
vmsDiskOrSnapshotPluggedTo.add(vm);
}
if (vm.getId().equals(getParameters().getVmId())) {
vmDeviceForVm = pair.getSecond();
}
}
}
}
Aggregations