use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method createCloudInitPayloadDevice.
public VmDevice createCloudInitPayloadDevice(Map<String, byte[]> cloudInitContent, VM vm) {
VmPayload vmPayload = new VmPayload();
vmPayload.setDeviceType(VmDeviceType.CDROM);
vmPayload.setVolumeId(CLOUD_INIT_VOL_ID);
for (Entry<String, byte[]> entry : cloudInitContent.entrySet()) {
vmPayload.getFiles().put(entry.getKey(), new String(BASE_64.encode(entry.getValue()), StandardCharsets.UTF_8));
}
return new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.CDROM.getName(), "", vmPayload.getSpecParams(), true, true, true, "", null, null, null);
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmInfoBuilderImpl method buildVmCD.
@Override
public void buildVmCD(VmPayload vmPayload) {
boolean hasPayload = vmPayload != null && vmPayload.getDeviceType() == VmDeviceType.CDROM;
// check if we have payload CD
if (hasPayload) {
Map<String, Object> struct = vmInfoBuildUtils.buildCdDetails(vmPayload, vm);
addDevice(struct, vmPayload, "");
}
// check first if CD was given as a RunOnce parameter
if (vm.isRunOnce() && !StringUtils.isEmpty(vm.getCdPath())) {
VmDevice vmDevice = new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.CDROM.getName(), "", null, true, true, true, "", null, null, null);
Map<String, Object> struct = vmInfoBuildUtils.buildCdDetails(vmDevice, vm);
addDevice(struct, vmDevice, vm.getCdPath());
} else {
// get vm device for this CD from DB
List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.DISK, VmDeviceType.CDROM);
for (VmDevice vmDevice : vmDevices) {
// skip unmanaged devices (handled separately)
if (!vmDevice.isManaged()) {
continue;
}
// the method, so no need to add the device again,
if (VmPayload.isPayload(vmDevice.getSpecParams())) {
continue;
}
String cdPath = vm.getCdPath();
Map<String, Object> struct = vmInfoBuildUtils.buildCdDetails(vmDevice, vm);
vmInfoBuildUtils.addAddress(vmDevice, struct);
addDevice(struct, vmDevice, cdPath == null ? "" : cdPath);
}
}
numOfReservedScsiIndexes++;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmInfoBuilderImpl method buildVmNetworkInterfaces.
@Override
public void buildVmNetworkInterfaces(Map<Guid, String> passthroughVnicToVfMap) {
Map<VmDeviceId, VmDevice> devicesByDeviceId = Entities.businessEntitiesById(vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.INTERFACE, VmDeviceType.BRIDGE));
devicesByDeviceId.putAll(Entities.businessEntitiesById(vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.INTERFACE, VmDeviceType.HOST_DEVICE)));
for (VmNic vmInterface : vm.getInterfaces()) {
// get vm device for this nic from DB
VmDevice vmDevice = devicesByDeviceId.get(new VmDeviceId(vmInterface.getId(), vmInterface.getVmId()));
if (vmDevice != null && vmDevice.isManaged() && vmDevice.isPlugged()) {
Map<String, Object> struct = new HashMap<>();
VmInterfaceType ifaceType = VmInterfaceType.rtl8139;
if (vmInterface.getType() != null) {
ifaceType = VmInterfaceType.forValue(vmInterface.getType());
}
if (vmInterface.isPassthrough()) {
String vfDeviceName = passthroughVnicToVfMap.get(vmInterface.getId());
vmInfoBuildUtils.addNetworkVirtualFunctionProperties(struct, vmInterface, vmDevice, vfDeviceName, vm);
} else {
addNetworkInterfaceProperties(struct, vmInterface, vmDevice, vmInfoBuildUtils.evaluateInterfaceType(ifaceType, vm.getHasAgent()));
}
devices.add(struct);
bootableDevices.add(vmDevice);
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class OvfReader method addDefaultGraphicsDevice.
private void addDefaultGraphicsDevice() {
VmDevice device = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.GRAPHICS);
if (device != null) {
return;
}
List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
GraphicsType graphicsType = vmBase.getDefaultDisplayType() == DisplayType.cirrus ? GraphicsType.VNC : GraphicsType.SPICE;
GraphicsType supportedGraphicsType = null;
for (Pair<GraphicsType, DisplayType> pair : graphicsAndDisplays) {
if (pair.getSecond() == vmBase.getDefaultDisplayType()) {
if (pair.getFirst() == graphicsType) {
supportedGraphicsType = graphicsType;
break;
}
if (supportedGraphicsType == null) {
supportedGraphicsType = pair.getFirst();
}
}
}
if (supportedGraphicsType != null) {
device = new GraphicsDevice(supportedGraphicsType.getCorrespondingDeviceType());
device.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
addManagedVmDevice(device);
} else {
log.warn("Cannot find any graphics type for display type {} supported by OS {} in compatibility version {}", vmBase.getDefaultDisplayType().name(), osRepository.getOsName(vmBase.getOsId()), getVersion());
}
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildConsoleDevice.
public static VmDevice buildConsoleDevice(Map<String, Object> vmStruct, Guid vmId) {
Object[] devices = (Object[]) vmStruct.get(VdsProperties.Devices);
if (devices != null) {
for (Object device : devices) {
Map<String, Object> vdsmDevice = (Map<String, Object>) device;
String deviceName = (String) vdsmDevice.get(VdsProperties.Device);
if (VmDeviceType.CONSOLE.getName().equals(deviceName)) {
String typeName = (String) vdsmDevice.get(VdsProperties.Type);
String alias = StringUtils.defaultString((String) vdsmDevice.get(VdsProperties.Alias));
Guid newDeviceId = Guid.createGuidFromString((String) vdsmDevice.get(VdsProperties.DeviceId));
VmDeviceId id = new VmDeviceId(newDeviceId, vmId);
VmDevice consoleDevice = new VmDevice(id, VmDeviceGeneralType.forValue(typeName), deviceName, "", new HashMap<>(), false, true, false, alias, null, null, null);
return consoleDevice;
}
}
}
return null;
}
Aggregations