Search in sources :

Example 81 with VmDevice

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

Example 82 with 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;
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) Base64(org.apache.commons.codec.binary.Base64) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) VmNicFilterParameterDao(org.ovirt.engine.core.dao.network.VmNicFilterParameterDao) VmNicFilterParameter(org.ovirt.engine.core.common.businessentities.network.VmNicFilterParameter) Matcher(java.util.regex.Matcher) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) StringMapUtils(org.ovirt.engine.core.utils.StringMapUtils) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) ComparatorUtils(org.ovirt.engine.core.utils.collections.ComparatorUtils) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) CinderVolumeDriver(org.ovirt.engine.core.common.businessentities.storage.CinderVolumeDriver) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Set(java.util.Set) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) StandardCharsets(java.nio.charset.StandardCharsets) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) VnicProfileDao(org.ovirt.engine.core.dao.network.VnicProfileDao) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) IoTuneUtils(org.ovirt.engine.core.vdsbroker.vdsbroker.IoTuneUtils) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) StorageServerConnectionDao(org.ovirt.engine.core.dao.StorageServerConnectionDao) LinkedHashSet(java.util.LinkedHashSet) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) SupportedAdditionalClusterFeature(org.ovirt.engine.core.common.businessentities.SupportedAdditionalClusterFeature) VM(org.ovirt.engine.core.common.businessentities.VM) ClusterFeatureDao(org.ovirt.engine.core.dao.ClusterFeatureDao) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) VdsNumaNodeDao(org.ovirt.engine.core.dao.VdsNumaNodeDao) Date(java.util.Date) NetworkQoS(org.ovirt.engine.core.common.businessentities.network.NetworkQoS) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) LoggerFactory(org.slf4j.LoggerFactory) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) Version(org.ovirt.engine.core.compat.Version) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) VmDevicesMonitoring(org.ovirt.engine.core.vdsbroker.monitoring.VmDevicesMonitoring) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) TimeZone(java.util.TimeZone) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) NetworkQoSDao(org.ovirt.engine.core.dao.network.NetworkQoSDao) Objects(java.util.Objects) List(java.util.List) WindowsJavaTimezoneMapping(org.ovirt.engine.core.compat.WindowsJavaTimezoneMapping) Entry(java.util.Map.Entry) Optional(java.util.Optional) AuditLogType(org.ovirt.engine.core.common.AuditLogType) Pattern(java.util.regex.Pattern) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) NetworkClusterDao(org.ovirt.engine.core.dao.network.NetworkClusterDao) NetworkQosMapper(org.ovirt.engine.core.vdsbroker.vdsbroker.NetworkQosMapper) IntStream(java.util.stream.IntStream) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) VdsStatisticsDao(org.ovirt.engine.core.dao.VdsStatisticsDao) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) PDIVMapBuilder(org.ovirt.engine.core.common.utils.PDIVMapBuilder) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ArchStrategyFactory(org.ovirt.engine.core.utils.archstrategy.ArchStrategyFactory) CollectionUtils(org.apache.commons.collections.CollectionUtils) LexoNumericNameableComparator(org.ovirt.engine.core.common.businessentities.comparators.LexoNumericNameableComparator) Network(org.ovirt.engine.core.common.businessentities.network.Network) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) LinkedList(java.util.LinkedList) StorageDomainStaticDao(org.ovirt.engine.core.dao.StorageDomainStaticDao) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) ValidationUtils(org.ovirt.engine.core.common.utils.ValidationUtils) MapUtils(org.apache.commons.collections.MapUtils) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) CinderConnectionInfo(org.ovirt.engine.core.common.businessentities.storage.CinderConnectionInfo) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) NetworkFilterDao(org.ovirt.engine.core.dao.network.NetworkFilterDao) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices) VmNumaNodeDao(org.ovirt.engine.core.dao.VmNumaNodeDao) Comparator(java.util.Comparator) StorageQosDao(org.ovirt.engine.core.dao.qos.StorageQosDao) Collections(java.util.Collections) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Map(java.util.Map) HashMap(java.util.HashMap) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices)

Example 83 with VmDevice

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);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 84 with VmDevice

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

Example 85 with VmDevice

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();
            }
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16