Search in sources :

Example 46 with NetworkAttachment

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

the class HostSetupNetworksCommand method getRemovedNetworks.

private Set<String> getRemovedNetworks() {
    if (removedNetworks == null) {
        List<NetworkAttachment> removedNetworkAttachments = Entities.filterEntitiesByRequiredIds(getParameters().getRemovedNetworkAttachments(), existingAttachments);
        removedNetworks = new HashSet<>(removedNetworkAttachments.size());
        Map<Guid, NetworkAttachment> networkIdToAttachment = new MapNetworkAttachments(getParameters().getNetworkAttachments()).byNetworkId();
        for (NetworkAttachment removedAttachment : removedNetworkAttachments) {
            if (!networkIdToAttachment.containsKey(removedAttachment.getNetworkId())) {
                removedNetworks.add(existingNetworkRelatedToAttachment(removedAttachment).getVdsmName());
            }
        }
    }
    return removedNetworks;
}
Also used : MapNetworkAttachments(org.ovirt.engine.core.common.utils.MapNetworkAttachments) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 47 with NetworkAttachment

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

the class GetNetworkAttachmentsByHostIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Guid hostId = getParameters().getId();
    List<NetworkAttachment> networkAttachments = networkAttachmentDao.getAllForHost(hostId);
    List<VdsNetworkInterface> allInterfacesForHost = interfaceDao.getAllInterfacesForVds(hostId);
    VDS vds = hostDao.get(hostId);
    Guid clusterId = vds.getClusterId();
    BusinessEntityMap<Network> networkMap = new BusinessEntityMap<>(networkDao.getAllForCluster(clusterId));
    reportedConfigurationsFiller.fillReportedConfigurations(allInterfacesForHost, networkMap, networkAttachments, vds.getDynamicData().getReportedDnsResolverConfiguration(), clusterId);
    completeNicNames(networkAttachments, allInterfacesForHost);
    completeNetworkNames(networkAttachments, networkMap);
    getQueryReturnValue().setReturnValue(networkAttachments);
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 48 with NetworkAttachment

use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment 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();
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 49 with NetworkAttachment

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

the class AddNetworkAttachmentCommand method executeCommand.

@Override
protected void executeCommand() {
    HostSetupNetworksParameters params = new HostSetupNetworksParameters(getParameters().getVdsId());
    NetworkAttachment networkAttachment = getParameters().getNetworkAttachment();
    params.getNetworkAttachments().add(networkAttachment);
    // storing ids, so we're sure, that they were not mistakenly altered in HostSetupNetworks command.
    Guid networkId = networkAttachment.getNetworkId();
    Guid nicId = networkAttachment.getNicId();
    ActionReturnValue returnValue = runInternalAction(ActionType.HostSetupNetworks, params);
    if (returnValue.getSucceeded()) {
        Guid createdAttachmentId = resolveCreatedAttachmentId(networkId, nicId);
        getReturnValue().setActionReturnValue(createdAttachmentId);
    } else {
        propagateFailure(returnValue);
    }
    setSucceeded(returnValue.getSucceeded());
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 50 with NetworkAttachment

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

the class AddNetworkAttachmentCommand method validate.

@Override
protected boolean validate() {
    NicNameNicIdCompleter completer = new NicNameNicIdCompleter(getHostInterfaces());
    completer.completeNetworkAttachment(getParameters().getNetworkAttachment());
    this.networkIdNameCompleter.completeNetworkAttachment(getParameters().getNetworkAttachment(), getStoragePoolId());
    NetworkAttachment networkAttachment = getParameters().getNetworkAttachment();
    if (networkAttachment == null) {
        return failValidation(EngineMessage.NETWORK_ATTACHMENT_NOT_SPECIFIED);
    }
    if (networkAttachment.getId() != null) {
        return failValidation(EngineMessage.NETWORK_ATTACHMENT_CANNOT_BE_CREATED_WITH_SPECIFIC_ID, ReplacementUtils.createSetVariableString("NETWORK_ATTACHMENT_CANNOT_BE_CREATED_WITH_SPECIFIC_ID_ENTITY", networkAttachment.getId()));
    }
    return true;
}
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