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);
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations