Search in sources :

Example 51 with NetworkAttachment

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

the class HostSetupNetworksValidator method validateCustomProperties.

ValidationResult validateCustomProperties(SimpleCustomPropertiesUtil util, Map<String, String> validPropertiesForVm, Map<String, String> validPropertiesForNonVm) {
    for (NetworkAttachment attachment : params.getNetworkAttachments()) {
        Network network = existingNetworkRelatedToAttachment(attachment);
        if (attachment.hasProperties()) {
            List<ValidationError> errors = util.validateProperties(network.isVmNetwork() ? validPropertiesForVm : validPropertiesForNonVm, attachment.getProperties());
            if (!errors.isEmpty()) {
                handleCustomPropertiesError(util, errors);
                EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_NETWORK_CUSTOM_PROPERTIES_BAD_INPUT;
                return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentStringWithMultipleValues(engineMessage, network.getName()));
            }
        }
    }
    return ValidationResult.VALID;
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) ValidationError(org.ovirt.engine.core.common.utils.customprop.ValidationError) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 52 with NetworkAttachment

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

the class HostSetupNetworksValidator method validateQosNotPartiallyConfigured.

/**
 * Ensure that either none or all of the networks on a single interface have QoS configured on them.
 */
ValidationResult validateQosNotPartiallyConfigured(Collection<NetworkAttachment> attachmentsToConfigure) {
    Set<String> someSubInterfacesHaveQos = new HashSet<>();
    Set<String> notAllSubInterfacesHaveQos = new HashSet<>();
    // first map which interfaces have some QoS configured on them, and which interfaces lack some QoS configuration
    for (NetworkAttachment networkAttachment : attachmentsToConfigure) {
        Network network = getNetworkRelatedToAttachment(networkAttachment);
        if (NetworkUtils.qosConfiguredOnInterface(networkAttachment, network)) {
            someSubInterfacesHaveQos.add(networkAttachment.getNicName());
        } else {
            notAllSubInterfacesHaveQos.add(networkAttachment.getNicName());
        }
    }
    // if any base interface has some sub-interfaces with QoS and some without - this is a partial configuration
    for (String ifaceName : someSubInterfacesHaveQos) {
        if (notAllSubInterfacesHaveQos.contains(ifaceName)) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_HOST_NETWORK_QOS_INTERFACES_WITHOUT_QOS, ReplacementUtils.createSetVariableString("ACTION_TYPE_FAILED_HOST_NETWORK_QOS_INTERFACES_WITHOUT_QOS_LIST", ifaceName));
        }
    }
    return ValidationResult.VALID;
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) HashSet(java.util.HashSet) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 53 with NetworkAttachment

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

the class HostSetupNetworksValidator method getAttachmentsToConfigure.

/**
 * @return all attachments passed in {@link HostSetupNetworksParameters#networkAttachments} plus
 * all previously existing attachments not mentioned in user request, but except for those listed in
 * {@link org.ovirt.engine.core.common.action.HostSetupNetworksParameters#removedNetworkAttachments}
 */
Collection<NetworkAttachment> getAttachmentsToConfigure() {
    Map<Guid, NetworkAttachment> networkAttachmentsMap = new HashMap<>(existingAttachments.size() + params.getNetworkAttachments().size());
    List<NetworkAttachment> newAttachments = new ArrayList<>();
    for (NetworkAttachment attachment : params.getNetworkAttachments()) {
        if (attachment.getId() == null) {
            newAttachments.add(attachment);
        } else {
            networkAttachmentsMap.put(attachment.getId(), attachment);
        }
    }
    for (NetworkAttachment existingAttachment : existingAttachments) {
        Guid existingAttachmentId = existingAttachment.getId();
        if (!networkAttachmentsMap.containsKey(existingAttachmentId) && !params.getRemovedNetworkAttachments().contains(existingAttachmentId)) {
            networkAttachmentsMap.put(existingAttachmentId, existingAttachment);
        }
    }
    List<NetworkAttachment> result = new ArrayList<>(networkAttachmentsMap.values());
    result.addAll(newAttachments);
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 54 with NetworkAttachment

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

the class NicNameNicIdCompleterTest method testProperNetworkAttachmentBindingToNicNameAndNicIdAccessors.

@Test
public void testProperNetworkAttachmentBindingToNicNameAndNicIdAccessors() {
    NetworkAttachment networkAttachment = new NetworkAttachment();
    networkAttachment.setNicId(Guid.newGuid());
    networkAttachment.setNicName("nic name");
    NicNameAndNicIdAccessors accessors = new NicNameAndNicIdAccessors.FromNetworkAttachment(networkAttachment);
    assertThat("id should be bound to nicId", accessors.getId(), is(networkAttachment.getNicId()));
    assertThat("name should be bound to nicName", accessors.getName(), is(networkAttachment.getNicName()));
    accessors.setId(Guid.newGuid());
    accessors.setName("another name");
    assertThat("id should be bound to nicId", networkAttachment.getNicId(), is(accessors.getId()));
    assertThat("name should be bound to nicName", networkAttachment.getNicName(), is(accessors.getName()));
}
Also used : NicNameAndNicIdAccessors(org.ovirt.engine.core.bll.network.host.NicNameNicIdCompleter.NicNameAndNicIdAccessors) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 55 with NetworkAttachment

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

the class ReportedConfigurationsFillerTest method testFillReportedConfiguration.

/**
 * @param network network which will contain qos and will be attached to nic.
 * @param nic nic to which network should be attached
 * @param networkQos qos of network
 */
private void testFillReportedConfiguration(Network network, VdsNetworkInterface nic, HostNetworkQos networkQos) {
    nic.setNetworkName(network.getName());
    when(interfaceDao.getAllInterfacesForVds(eq(hostId))).thenReturn(Arrays.asList(baseNic, vlanNic));
    when(networkDao.getAllForCluster(eq(clusterId))).thenReturn(Collections.singletonList(network));
    NetworkAttachment networkAttachment = new NetworkAttachment();
    networkAttachment.setNicId(baseNic.getId());
    networkAttachment.setNicName(baseNic.getName());
    networkAttachment.setNetworkId(network.getId());
    when(effectiveHostNetworkQos.getQos(networkAttachment, network)).thenReturn(networkQos);
    filler.fillReportedConfiguration(networkAttachment, hostId);
    verify(filler).createNetworkInSyncWithVdsNetworkInterface(networkAttachment, nic, network, reportedDnsResolverConfiguration, cluster);
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Aggregations

NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)167 Test (org.junit.Test)79 Network (org.ovirt.engine.core.common.businessentities.network.Network)62 Guid (org.ovirt.engine.core.compat.Guid)37 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)36 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)35 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)20 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)18 HashMap (java.util.HashMap)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)14 ArrayList (java.util.ArrayList)10 IpConfiguration (org.ovirt.engine.core.common.businessentities.network.IpConfiguration)10 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)9 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)8 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)7 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)7 AnonymousHostNetworkQos (org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos)6 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)5 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)5