use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildHostDevices.
/**
* Parse Host Device Information in the form of
*
* {
* 'computer': {
* 'params': {'capability': 'system', 'product': 'ProLiant DL160 G6 '}
* },
* 'pci_0000_00_1d_2': {
* 'params': {
* 'capability': 'pci',
* 'iommu_group': '9',
* 'parent': 'computer',
* 'product': '82801JI (ICH10 Family) USB UHCI Controller #3',
* 'product_id': '0x3a36',
* 'vendor': 'Intel Corporation',
* 'vendor_id': '0x8086'
* 'mdev': {
* 'nvidia-11': {'available_instances': '16', 'name': 'GRID M60-0B'}
* ...
* }
* }
* },
* 'pci_0000_00_1d_1': {
* ...
* },
* },
*
* }
*/
public static List<HostDevice> buildHostDevices(Map<String, Map<String, Map<String, Object>>> deviceList) {
List<HostDevice> devices = new ArrayList<>();
for (Entry<String, Map<String, Map<String, Object>>> entry : deviceList.entrySet()) {
Map<String, Object> params = entry.getValue().get(VdsProperties.PARAMS);
String deviceName = entry.getKey();
HostDevice device = new HostDevice();
device.setDeviceName(entry.getKey());
device.setCapability(params.get(VdsProperties.CAPABILITY).toString());
// special case for root device "computer"
device.setParentDeviceName(VdsProperties.ROOT_HOST_DEVICE.equals(deviceName) ? // set parent to self, for DB integrity
VdsProperties.ROOT_HOST_DEVICE : params.get(VdsProperties.PARENT_NAME).toString());
device.setAssignable(params.containsKey(VdsProperties.IS_ASSIGNABLE) ? assignBoolValue(params, VdsProperties.IS_ASSIGNABLE) : true);
if (params.containsKey(VdsProperties.MDEV)) {
device.setMdevTypes(((Map<String, Object>) params.get(VdsProperties.MDEV)).keySet());
}
if (params.containsKey(VdsProperties.IOMMU_GROUP)) {
device.setIommuGroup(Integer.parseInt(params.get(VdsProperties.IOMMU_GROUP).toString()));
}
if (params.containsKey(VdsProperties.PRODUCT_ID)) {
device.setProductId(params.get(VdsProperties.PRODUCT_ID).toString());
}
if (params.containsKey(VdsProperties.PRODUCT_NAME)) {
device.setProductName(params.get(VdsProperties.PRODUCT_NAME).toString());
}
if (params.containsKey(VdsProperties.VENDOR_NAME)) {
device.setVendorName(params.get(VdsProperties.VENDOR_NAME).toString());
}
if (params.containsKey(VdsProperties.VENDOR_ID)) {
device.setVendorId(params.get(VdsProperties.VENDOR_ID).toString());
}
if (params.containsKey(VdsProperties.PHYSICAL_FUNCTION)) {
device.setParentPhysicalFunction(params.get(VdsProperties.PHYSICAL_FUNCTION).toString());
}
if (params.containsKey(VdsProperties.TOTAL_VFS)) {
device.setTotalVirtualFunctions(Integer.parseInt(params.get(VdsProperties.TOTAL_VFS).toString()));
}
if (params.containsKey(VdsProperties.NET_INTERFACE_NAME)) {
device.setNetworkInterfaceName(params.get(VdsProperties.NET_INTERFACE_NAME).toString());
}
if (params.containsKey(VdsProperties.DRIVER)) {
device.setDriver(params.get(VdsProperties.DRIVER).toString());
}
if (params.containsKey(VdsProperties.Address)) {
device.setAddress((Map<String, String>) params.get(VdsProperties.Address));
}
devices.add(device);
}
return devices;
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImpl method getNicByPciDevice.
private VdsNetworkInterface getNicByPciDevice(final HostDevice pciDevice, final Collection<HostDevice> devices, final Collection<VdsNetworkInterface> hostNics) {
final HostDevice netDevice = getFirstChildNetworkDevice(pciDevice, devices);
if (netDevice == null) {
return null;
}
final Collection<VdsNetworkInterface> hostInterfaces = hostNics == null ? interfaceDao.getAllInterfacesForVds(netDevice.getHostId()) : hostNics;
return hostInterfaces.stream().filter(iface -> iface.getName().equals(netDevice.getNetworkInterfaceName())).findFirst().orElse(null);
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImpl method setVmIdOnVfs.
@Override
public void setVmIdOnVfs(Guid hostId, Guid vmId, final Set<String> vfsNames) {
List<HostDevice> hostDevices = hostDeviceDao.getHostDevicesByHostId(hostId);
List<HostDevice> vfs = hostDevices.stream().filter(device -> vfsNames.contains(device.getDeviceName()) && isVf(device)).collect(Collectors.toList());
if (vmId != null) {
HostDevice alreadyTakenVf = vfs.stream().filter(vf -> vf.getVmId() != null).findFirst().orElse(null);
if (alreadyTakenVf != null) {
throw new IllegalStateException(String.format("VF %s is already taken by VM %s", alreadyTakenVf.getName(), alreadyTakenVf.getVmId()));
}
}
setVmIdOnVfsDevices(vmId, new HashSet<>(vfs));
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImpl method removeVmIdFromVfs.
@Override
public Guid removeVmIdFromVfs(final Guid vmId) {
List<HostDevice> hostDevices = hostDeviceDao.getAll();
List<HostDevice> vfsUsedByVm = hostDevices.stream().filter(device -> vmId.equals(device.getVmId()) && isVf(device)).collect(Collectors.toList());
Guid hostId = vfsUsedByVm.isEmpty() ? null : vfsUsedByVm.get(0).getHostId();
if (hostId != null) {
setVmIdOnVfsDevices(null, new HashSet<>(vfsUsedByVm));
}
return hostId;
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImpl method getHostNicVfsConfigsWithNumVfsDataByHostId.
@Override
public List<HostNicVfsConfig> getHostNicVfsConfigsWithNumVfsDataByHostId(Guid hostId) {
List<HostNicVfsConfig> hostNicVfsConfigList = hostNicVfsConfigDao.getAllVfsConfigByHostId(hostId);
List<HostDevice> deviceList = getDevicesByHostId(hostId);
for (HostNicVfsConfig hostNicVfsConfig : hostNicVfsConfigList) {
updateVfsConfigWithNumOfVfsData(hostNicVfsConfig, null, deviceList);
}
return hostNicVfsConfigList;
}
Aggregations