Search in sources :

Example 11 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class SyncMacsOfDbNicsWithSnapshotTest method testSyncWhenNeedToSyncMacs.

private void testSyncWhenNeedToSyncMacs(boolean macsInSnapshotAreExpectedToBeAlreadyAllocated) {
    String snapshottedMac = "1";
    String currentMac = "2";
    VmNic snapshottedNic = createNic(snapshottedMac);
    VmNic currentNic = createNic(currentMac);
    createSyncMacsOfDbNicsWithSnapshot(macsInSnapshotAreExpectedToBeAlreadyAllocated).sync(Arrays.asList(currentNic), Arrays.asList(snapshottedNic));
    verifyMethodCallOn(VmNic::getMacAddress, 1, snapshottedNic, currentNic);
    verify(macPool).freeMacs(Collections.singletonList(currentMac));
    verify(macPool).addMacs(macsInSnapshotAreExpectedToBeAlreadyAllocated ? Collections.emptyList() : Collections.singletonList(snapshottedMac));
    verifyNoMoreInteractionsOn(snapshottedNic, currentNic);
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 12 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class ChangeVmClusterValidator method validate.

protected boolean validate() {
    VM vm = parentCommand.getVm();
    if (vm == null) {
        parentCommand.addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
        return false;
    } else {
        targetCluster = clusterDao.get(targetClusterId);
        if (targetCluster == null) {
            parentCommand.addValidationMessage(EngineMessage.VM_CLUSTER_IS_NOT_VALID);
            return false;
        }
        // Check that the target cluster is in the same data center.
        if (!targetCluster.getStoragePoolId().equals(vm.getStoragePoolId())) {
            parentCommand.addValidationMessage(EngineMessage.VM_CANNOT_MOVE_TO_CLUSTER_IN_OTHER_STORAGE_POOL);
            return false;
        }
        if (vmCompatibilityVersion == null) {
            vmCompatibilityVersion = targetCluster.getCompatibilityVersion();
        }
        List<VmNic> interfaces = vmNicDao.getAllForVm(vm.getId());
        if (!validateDestinationClusterContainsNetworks(interfaces)) {
            return false;
        }
        // Check if VM static parameters are compatible for new cluster.
        ValidationResult isCpuSocketsValid = VmValidator.validateCpuSockets(vm.getStaticData(), vmCompatibilityVersion);
        if (!isCpuSocketsValid.isValid()) {
            return parentCommand.validate(isCpuSocketsValid);
        }
        // Check if the display type is supported
        if (!parentCommand.validate(vmHandler.isGraphicsAndDisplaySupported(vm.getOs(), vmDeviceUtils.getGraphicsTypesOfEntity(vm.getId()), vm.getDefaultDisplayType(), vmCompatibilityVersion))) {
            return false;
        }
        if (vmDeviceUtils.hasVirtioScsiController(vm.getId())) {
            // Verify OS compatibility
            if (!parentCommand.validate(vmHandler.isOsTypeSupportedForVirtioScsi(vm.getOs(), vmCompatibilityVersion))) {
                return false;
            }
        }
        // A existing VM cannot be changed into a cluster without a defined architecture
        if (targetCluster.getArchitecture() == ArchitectureType.undefined) {
            return parentCommand.failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
        } else if (targetCluster.getArchitecture() != vm.getClusterArch()) {
            return parentCommand.failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_CLUSTER_DIFFERENT_ARCHITECTURES);
        }
        // Cluster must have a cpu profile
        List<CpuProfile> cpuProfiles = cpuProfileDao.getAllForCluster(targetClusterId, parentCommand.getUserId(), true, ActionGroup.ASSIGN_CPU_PROFILE);
        if (cpuProfiles.isEmpty()) {
            return parentCommand.failValidation(EngineMessage.ACTION_TYPE_CPU_PROFILE_EMPTY);
        }
    }
    return true;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 13 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class VmDeviceUtils method addImportedInterfaces.

/**
 * Add network interfaces to an imported VM or template.
 *
 * @param vmDevicesToUpdate    list of devices to be updated in the DB
 */
private void addImportedInterfaces(VmBase vmBase, List<VmDevice> vmDevicesToUpdate) {
    for (VmNic iface : vmBase.getInterfaces()) {
        Guid deviceId = iface.getId();
        VmDevice vmDevice = addInterface(vmBase.getId(), deviceId, true, iface.isPassthrough(), getVmDeviceAddress(vmBase, deviceId));
        VmDevice exportedDevice = vmBase.getManagedDeviceMap().get(deviceId);
        if (exportedDevice == null) {
            vmBase.getManagedDeviceMap().put(deviceId, vmDevice);
            exportedDevice = vmDevice;
        }
        exportedDevice.setPlugged(exportedDevice.isPlugged() && canPlugInterface(iface, vmBase));
        updateImportedVmDevice(vmBase, vmDevice, deviceId, vmDevicesToUpdate);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Guid(org.ovirt.engine.core.compat.Guid) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 14 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class VmInterfaceManagerTest method testAuditLogMacInUseUnplug.

@Test
public void testAuditLogMacInUseUnplug() {
    final VmNic iface = createNewInterface();
    vmInterfaceManager.auditLogMacInUseUnplug(iface, VM_NAME);
    verifyCommonAuditLogFilledProperly(AuditLogType.MAC_ADDRESS_IS_IN_USE_UNPLUG, iface);
    assertEquals(auditLogableCaptor.getValue().getVmName(), VM_NAME);
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Test(org.junit.Test)

Example 15 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class VmInterfaceManagerTest method createNewInterface.

/**
 * @return A new interface that can be used in tests.
 */
private static VmNic createNewInterface() {
    VmNic iface = new VmNic();
    iface.setId(Guid.newGuid());
    iface.setMacAddress(RandomUtils.instance().nextString(10));
    return iface;
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Aggregations

VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)47 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 VM (org.ovirt.engine.core.common.businessentities.VM)6 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)6 Network (org.ovirt.engine.core.common.businessentities.network.Network)5 Guid (org.ovirt.engine.core.compat.Guid)5 HashMap (java.util.HashMap)4 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 List (java.util.List)3 Map (java.util.Map)3 VmNicValidator (org.ovirt.engine.core.bll.validator.VmNicValidator)3 Version (org.ovirt.engine.core.compat.Version)3 Collectors (java.util.stream.Collectors)2 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)2 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)2 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)2 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2