Search in sources :

Example 36 with HostDevice

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;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 37 with HostDevice

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);
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 38 with HostDevice

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));
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Predicate(java.util.function.Predicate) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) Set(java.util.Set) Entities(org.ovirt.engine.core.common.businessentities.Entities) Singleton(javax.inject.Singleton) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) HashSet(java.util.HashSet) Objects(java.util.Objects) Inject(javax.inject.Inject) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Map(java.util.Map) HostNicVfsConfigDao(org.ovirt.engine.core.dao.network.HostNicVfsConfigDao) NetworkCommonUtils(org.ovirt.engine.core.common.utils.NetworkCommonUtils) InterfaceDao(org.ovirt.engine.core.dao.network.InterfaceDao) HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice)

Example 39 with HostDevice

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;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Predicate(java.util.function.Predicate) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) Set(java.util.Set) Entities(org.ovirt.engine.core.common.businessentities.Entities) Singleton(javax.inject.Singleton) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) HashSet(java.util.HashSet) Objects(java.util.Objects) Inject(javax.inject.Inject) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Map(java.util.Map) HostNicVfsConfigDao(org.ovirt.engine.core.dao.network.HostNicVfsConfigDao) NetworkCommonUtils(org.ovirt.engine.core.common.utils.NetworkCommonUtils) InterfaceDao(org.ovirt.engine.core.dao.network.InterfaceDao) HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) Guid(org.ovirt.engine.core.compat.Guid)

Example 40 with HostDevice

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;
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice)

Aggregations

HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)46 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)16 Guid (org.ovirt.engine.core.compat.Guid)14 Map (java.util.Map)11 List (java.util.List)10 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)10 HashMap (java.util.HashMap)9 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)9 Collectors (java.util.stream.Collectors)8 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)7 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)7 HostDeviceDao (org.ovirt.engine.core.dao.HostDeviceDao)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Objects (java.util.Objects)6 Inject (javax.inject.Inject)6 StringUtils (org.apache.commons.lang.StringUtils)6 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)6 VmDeviceDao (org.ovirt.engine.core.dao.VmDeviceDao)6