use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.
the class AddNetworkAttachmentCommand method resolveCreatedAttachmentId.
private Guid resolveCreatedAttachmentId(final Guid requiredNetworkId, Guid configuredNicId) {
VdsNetworkInterface configuredNic = interfaceDao.get(configuredNicId);
List<NetworkAttachment> attachmentsOnNic = networkAttachmentDao.getAllForNic(configuredNic.getId());
NetworkAttachment createNetworkAttachment = attachmentsOnNic.stream().filter(networkAttachment -> networkAttachment.getNetworkId().equals(requiredNetworkId)).findFirst().orElse(null);
if (createNetworkAttachment == null) {
throw new IllegalStateException();
}
return createNetworkAttachment.getId();
}
use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method validateAttachmentNotReferenceVlanDevice.
private ValidationResult validateAttachmentNotReferenceVlanDevice(NetworkAttachment attachment) {
VdsNetworkInterface nic = existingInterfacesMap.get(attachment.getNicName());
EngineMessage engineMessage = EngineMessage.ATTACHMENT_REFERENCE_VLAN_DEVICE;
return ValidationResult.failWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, attachment.getNetworkName()), ReplacementUtils.createSetVariableString(VAR_NIC_NAME, attachment.getNicName())).when(nic != null && NetworkCommonUtils.isVlan(nic));
}
use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method validateModifiedBondSlaves.
ValidationResult validateModifiedBondSlaves(CreateOrUpdateBond modifiedOrNewBond) {
for (String slaveName : modifiedOrNewBond.getSlaves()) {
VdsNetworkInterface potentialSlave = existingInterfacesMap.get(slaveName);
HostInterfaceValidator slaveHostInterfaceValidator = createHostInterfaceValidator(potentialSlave);
ValidationResult interfaceExists = slaveHostInterfaceValidator.interfaceExists(slaveName);
if (!interfaceExists.isValid()) {
return interfaceExists;
}
ValidationResult interfaceIsValidSlave = slaveHostInterfaceValidator.interfaceIsValidSlave();
if (!interfaceIsValidSlave.isValid()) {
return interfaceIsValidSlave;
}
/*
* definition of currently processed bond references this slave, but this slave already 'slaves' for
* another bond. This is ok only when this bond will be removed as a part of this request
* or the slave will be removed from its former bond, as a part of this request.
*/
String currentSlavesBondName = potentialSlave.getBondName();
if (potentialSlave.isPartOfBond() && /*
* we're creating new bond, and it's definition contains reference to slave already assigned
* to a different bond.
*/
(!potentialSlave.isPartOfBond(modifiedOrNewBond.getName()) && // … but this bond is also removed in this request, so it's ok.
!isBondRemoved(currentSlavesBondName) && // … or slave was removed from its former bond
!bondIsUpdatedAndDoesNotContainCertainSlave(slaveName, currentSlavesBondName))) {
EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ALREADY_IN_BOND;
return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, slaveName));
}
ValidationResult slaveHasAttachedNetworksValidationResult = validateSlaveHasNoNetworks(potentialSlave.getName());
if (!slaveHasAttachedNetworksValidationResult.isValid()) {
return slaveHasAttachedNetworksValidationResult;
}
if (slaveUsedMultipleTimesInDifferentBonds(slaveName)) {
return new ValidationResult(EngineMessage.NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES, ReplacementUtils.createSetVariableString("NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES_ENTITY", slaveName));
}
ValidationResult slaveHasNoLabelsValidationResult = validateSlaveHasNoLabels(slaveName);
if (!slaveHasNoLabelsValidationResult.isValid()) {
return slaveHasNoLabelsValidationResult;
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.
the class GetInterfacesByLabelForNetworkQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
Network network = networkDao.get(getParameters().getId());
Set<VdsNetworkInterface> interfacesByLabelForNetwork = new HashSet<>();
if (network == null) {
getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
return;
}
List<NetworkCluster> clusters = networkClusterDao.getAllForNetwork(network.getId());
if (clusters.isEmpty()) {
getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
return;
}
List<VdsNetworkInterface> labeledNics = new ArrayList<>();
for (NetworkCluster networkCluster : clusters) {
labeledNics.addAll(interfaceDao.getAllInterfacesByLabelForCluster(networkCluster.getClusterId(), network.getLabel()));
}
if (labeledNics.isEmpty()) {
getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
return;
}
List<VdsNetworkInterface> networkNics = interfaceDao.getVdsInterfacesByNetworkId(network.getId());
Map<String, VdsNetworkInterface> labeledNicsByName = Entities.entitiesByName(labeledNics);
for (VdsNetworkInterface networkNic : networkNics) {
if (labeledNicsByName.containsKey(NetworkCommonUtils.stripVlan(networkNic))) {
interfacesByLabelForNetwork.add(networkNic);
}
}
getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
}
use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.
the class GetNetworkLabelsByHostNicIdQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
VdsNetworkInterface nic = interfaceDao.get(getParameters().getId());
getQueryReturnValue().setReturnValue(nic == null || !NetworkUtils.isLabeled(nic) ? Collections.<NetworkLabel>emptyList() : convertToNetworkLabels(nic.getLabels()));
}
Aggregations