use of org.ovirt.engine.core.common.businessentities.VmDevice 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.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuilderImpl method buildUnmanagedDevices.
@Override
public void buildUnmanagedDevices(String hibernationVolHandle) {
@SuppressWarnings("unchecked") Map<String, String> customMap = (Map<String, String>) createInfo.getOrDefault(VdsProperties.Custom, new HashMap<>());
List<VmDevice> vmDevices = vmDeviceDao.getUnmanagedDevicesByVmId(vm.getId());
if (!vmDevices.isEmpty()) {
StringBuilder id = new StringBuilder();
for (VmDevice vmDevice : vmDevices) {
Map<String, Object> struct = new HashMap<>();
id.append(VdsProperties.Device);
id.append("_");
id.append(vmDevice.getDeviceId());
if (VmDeviceCommonUtils.isMemory(vmDevice)) {
handleMemoryDevice(vmDevice, hibernationVolHandle, devices);
continue;
}
if (VmDeviceCommonUtils.isInWhiteList(vmDevice.getType(), vmDevice.getDevice())) {
struct.put(VdsProperties.Type, vmDevice.getType().getValue());
struct.put(VdsProperties.Device, vmDevice.getDevice());
vmInfoBuildUtils.addAddress(vmDevice, struct);
struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
devices.add(struct);
} else {
customMap.put(id.toString(), vmDevice.toString());
}
}
}
createInfo.put(VdsProperties.Custom, customMap);
createInfo.put(DEVICES, devices);
}
use of org.ovirt.engine.core.common.businessentities.VmDevice 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.VmDevice 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.VmDevice in project ovirt-engine by oVirt.
the class VmInfoBuilderImpl method buildSmartcardDevice.
private void buildSmartcardDevice() {
List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.SMARTCARD, VmDeviceType.SMARTCARD);
for (VmDevice vmDevice : vmDevices) {
Map<String, Object> struct = new HashMap<>();
struct.put(VdsProperties.Type, vmDevice.getType().getValue());
struct.put(VdsProperties.Device, vmDevice.getDevice());
addDevice(struct, vmDevice, null);
}
}
Aggregations