use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.
the class ExternalVmMacsFinder method findExternalMacAddresses.
public Set<String> findExternalMacAddresses(VM vm) {
final List<VmNetworkInterface> interfaces = vm.getInterfaces();
if (interfaces == null) {
return Collections.emptySet();
}
final ReadMacPool readMacPool = macPoolPerCluster.getMacPoolForCluster(vm.getClusterId());
return interfaces.stream().map(VmNetworkInterface::getMacAddress).filter(Objects::nonNull).filter(((Predicate<String>) readMacPool::isMacInRange).negate()).collect(Collectors.toSet());
}
use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.
the class ValidateVmMacsQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
// Map with a VM id as the key and violation messages (that are related to the VM) as the values.
final Map<Guid, List<List<String>>> result = new HashMap<>();
for (Entry<Guid, List<VM>> clusterEntry : getParameters().getVmsByCluster().entrySet()) {
final Guid clusterId = clusterEntry.getKey();
final List<VM> clusterVms = clusterEntry.getValue();
final ReadMacPool macPool = macPoolPerCluster.getMacPoolForCluster(clusterId);
final List<VmMacsValidation> vmMacsValidations = vmMacsValidationsFactory.createVmMacsValidationList(clusterId, macPool);
clusterVms.forEach(vm -> result.put(vm.getId(), validateVm(vm, vmMacsValidations)));
}
getQueryReturnValue().setReturnValue(result);
}
use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.
the class MoveMacs method canMigrateMacsToAnotherMacPool.
public ValidationResult canMigrateMacsToAnotherMacPool(ReadMacPool targetPool, List<String> macsToMigrate) {
if (targetPool.isDuplicateMacAddressesAllowed()) {
return ValidationResult.VALID;
}
Map<String, Long> occurrenceCount = macsToMigrate.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
List<String> problematicMacs = macsToMigrate.stream().distinct().filter(mac -> targetPool.isMacInUse(mac) || occurrenceCount.get(mac) > 1).collect(Collectors.toList());
EngineMessage engineMessage = ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES;
Collection<String> replacements = ReplacementUtils.getListVariableAssignmentString(engineMessage, problematicMacs);
return ValidationResult.failWith(engineMessage, replacements).when(!problematicMacs.isEmpty());
}
use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.
the class ChangeVMClusterCommand method validate.
@Override
protected boolean validate() {
if (!canRunActionOnNonManagedVm()) {
return false;
}
if (!isInternalExecution() && !ObjectIdentityChecker.canUpdateField(getVm(), "clusterId", getVm().getStatus())) {
addValidationMessage(EngineMessage.VM_STATUS_NOT_VALID_FOR_UPDATE);
return false;
}
ChangeVmClusterValidator validator = ChangeVmClusterValidator.create(this, newClusterId, getParameters().getVmCustomCompatibilityVersion());
if (macPoolChanged()) {
ReadMacPool macPoolForTargetCluster = macPoolPerCluster.getMacPoolForCluster(newClusterId);
ValidationResult validationResult = moveMacs.canMigrateMacsToAnotherMacPool(macPoolForTargetCluster, getMacsToMigrate());
if (!validationResult.isValid()) {
return validate(validationResult);
}
}
return validator.validate();
}
use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.
the class VmDeviceUtils method canPlugInterface.
private boolean canPlugInterface(VmNic iface, VmBase vmBase) {
ReadMacPool macPool = macPoolPerCluster.getMacPoolForCluster(vmBase.getClusterId());
VmInterfaceManager vmIfaceManager = new VmInterfaceManager();
if (vmIfaceManager.tooManyPluggedInterfaceWithSameMac(iface, macPool)) {
vmIfaceManager.auditLogMacInUseUnplug(iface, vmBase.getName());
return false;
} else {
return true;
}
}
Aggregations