Search in sources :

Example 11 with Network

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

the class AddEmptyStoragePoolCommand method addDefaultNetworks.

private void addDefaultNetworks() {
    Network net = new Network();
    net.setId(Guid.newGuid());
    net.setName(managementNetworkUtil.getDefaultManagementNetworkName());
    NetworkUtils.setNetworkVdsmName(net);
    net.setDescription(AddClusterCommand.DefaultNetworkDescription);
    net.setDataCenterId(getStoragePool().getId());
    net.setVmNetwork(true);
    networkDao.save(net);
    networkHelper.addPermissionsOnNetwork(getCurrentUser().getId(), net.getId());
    VnicProfile profile = networkHelper.createVnicProfile(net);
    vnicProfileDao.save(profile);
    networkHelper.addPermissionsOnVnicProfile(getCurrentUser().getId(), profile.getId(), true);
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile)

Example 12 with Network

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

the class RemoveStoragePoolCommand method removeNetworks.

private void removeNetworks() {
    final List<Network> networks = networkDao.getAllForDataCenter(getStoragePoolId());
    for (Network network : networks) {
        if (network.isExternal()) {
            for (VmNic nic : vmNicDao.getAllForNetwork(network.getId())) {
                externalNetworkManagerFactory.create(nic, network).deallocateIfExternal();
            }
        }
    }
    TransactionSupport.executeInNewTransaction(() -> {
        for (final Network net : networks) {
            List<VnicProfile> profiles = vnicProfileDao.getAllForNetwork(net.getId());
            for (VnicProfile vnicProfile : profiles) {
                getCompensationContext().snapshotEntity(vnicProfile);
                vnicProfileDao.remove(vnicProfile.getId());
            }
            getCompensationContext().snapshotEntity(net);
            networkDao.remove(net.getId());
        }
        getCompensationContext().stateChanged();
        return null;
    });
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 13 with Network

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

the class IscsiBondValidatorTest method addedLogicalNetworkBelongToAnotherDatacenter.

@Test
public void addedLogicalNetworkBelongToAnotherDatacenter() {
    IscsiBond iscsiBond = createIscsiBond("First", Guid.newGuid());
    List<Network> networks = new ArrayList<>();
    networks.add(createNetwork(iscsiBond.getStoragePoolId()));
    doReturn(networks).when(networkDao).getAllForDataCenter(iscsiBond.getStoragePoolId());
    iscsiBond.getNetworkIds().add(networks.get(0).getId());
    iscsiBond.getNetworkIds().add(Guid.newGuid());
    ValidationResult res = validator.validateAddedLogicalNetworks(iscsiBond);
    assertThat(res, failsWith(EngineMessage.NETWORKS_DONT_EXIST_IN_DATA_CENTER));
    assertEquals(2, res.getVariableReplacements().size());
    assertEquals("$networkIds " + iscsiBond.getNetworkIds().get(1).toString(), res.getVariableReplacements().get(0));
    assertEquals("$dataCenterId " + iscsiBond.getStoragePoolId().toString(), res.getVariableReplacements().get(1));
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) IscsiBond(org.ovirt.engine.core.common.businessentities.IscsiBond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 14 with Network

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

the class IscsiBondValidatorTest method addedRequiredLogicalNetworks.

@Test
public void addedRequiredLogicalNetworks() {
    IscsiBond iscsiBond = createIscsiBond("First", Guid.newGuid());
    List<Network> networks = new ArrayList<>();
    networks.add(createNetwork(iscsiBond.getStoragePoolId()));
    networks.add(createNetwork(iscsiBond.getStoragePoolId()));
    doReturn(networks).when(networkDao).getAllForDataCenter(iscsiBond.getStoragePoolId());
    for (Network network : networks) {
        iscsiBond.getNetworkIds().add(network.getId());
    }
    List<NetworkCluster> networkClusters = new ArrayList<>();
    networkClusters.add(createNetworkCluster(true));
    doReturn(networkClusters).when(networkClusterDao).getAllForNetwork(any());
    ValidationResult res = validator.validateAddedLogicalNetworks(iscsiBond);
    assertThat(res, failsWith(EngineMessage.ACTION_TYPE_FAILED_ISCSI_BOND_NETWORK_CANNOT_BE_REQUIRED));
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) IscsiBond(org.ovirt.engine.core.common.businessentities.IscsiBond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 15 with Network

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

the class IscsiBondValidatorTest method addedLogicalNetworkBelongToSameDatacenter.

@Test
public void addedLogicalNetworkBelongToSameDatacenter() {
    IscsiBond iscsiBond = createIscsiBond("First", Guid.newGuid());
    List<Network> networks = new ArrayList<>();
    networks.add(createNetwork(iscsiBond.getStoragePoolId()));
    networks.add(createNetwork(iscsiBond.getStoragePoolId()));
    doReturn(networks).when(networkDao).getAllForDataCenter(iscsiBond.getStoragePoolId());
    for (Network network : networks) {
        iscsiBond.getNetworkIds().add(network.getId());
    }
    List<NetworkCluster> networkClusters = new ArrayList<>();
    networkClusters.add(createNetworkCluster(false));
    doReturn(networkClusters).when(networkClusterDao).getAllForNetwork(any());
    assertEquals(ValidationResult.VALID, validator.validateAddedLogicalNetworks(iscsiBond));
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) IscsiBond(org.ovirt.engine.core.common.businessentities.IscsiBond) Test(org.junit.Test)

Aggregations

Network (org.ovirt.engine.core.common.businessentities.network.Network)292 Test (org.junit.Test)105 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)63 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)47 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)46 ArrayList (java.util.ArrayList)44 Guid (org.ovirt.engine.core.compat.Guid)44 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)39 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)23 List (java.util.List)21 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)21 HashMap (java.util.HashMap)19 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)19 Map (java.util.Map)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)13 HashSet (java.util.HashSet)9 Set (java.util.Set)9 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9