Search in sources :

Example 36 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class NetworkOrchestrator method removeDhcpServiceInSubnet.

@DB
@Override
public void removeDhcpServiceInSubnet(final Nic nic) {
    final Network network = _networksDao.findById(nic.getNetworkId());
    final DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
    try {
        final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getIPv4Gateway(), network.getId(), NicIpAlias.State.active);
        if (ipAlias != null) {
            ipAlias.setState(NicIpAlias.State.revoked);
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
                    final IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address());
                    _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId());
                }
            });
            if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) {
                s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address());
            }
        }
    } catch (final ResourceUnavailableException e) {
        //failed to remove the dhcpconfig on the router.
        s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter.");
    }
}
Also used : Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) IPAddressVO(com.cloud.network.dao.IPAddressVO) NicIpAliasVO(com.cloud.vm.dao.NicIpAliasVO) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) DB(com.cloud.utils.db.DB)

Example 37 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class NetworkOrchestrator method releaseNic.

@DB
protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
    final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network, NicProfile>>() {

        @Override
        public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status) {
            final NicVO nic = _nicDao.lockRow(nicId, true);
            if (nic == null) {
                throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
            }
            final Nic.State originalState = nic.getState();
            final NetworkVO network = _networksDao.findById(nic.getNetworkId());
            if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
                if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
                    nic.setState(Nic.State.Releasing);
                    _nicDao.update(nic.getId(), nic);
                    final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
                    if (guru.release(profile, vmProfile, nic.getReservationId())) {
                        applyProfileToNicForRelease(nic, profile);
                        nic.setState(Nic.State.Allocated);
                        if (originalState == Nic.State.Reserved) {
                            updateNic(nic, network.getId(), -1);
                        } else {
                            _nicDao.update(nic.getId(), nic);
                        }
                    }
                    // Perform release on network elements
                    return new Pair<Network, NicProfile>(network, profile);
                } else {
                    nic.setState(Nic.State.Allocated);
                    updateNic(nic, network.getId(), -1);
                }
            }
            return null;
        }
    });
    // cleanup the entry in vm_network_map
    if (vmProfile.getType().equals(VirtualMachine.Type.User)) {
        final NicVO nic = _nicDao.findById(nicId);
        if (nic != null) {
            final NetworkVO vmNetwork = _networksDao.findById(nic.getNetworkId());
            final VMNetworkMapVO vno = _vmNetworkMapDao.findByVmAndNetworkId(vmProfile.getVirtualMachine().getId(), vmNetwork.getId());
            if (vno != null) {
                _vmNetworkMapDao.remove(vno.getId());
            }
        }
    }
    if (networkToRelease != null) {
        final Network network = networkToRelease.first();
        final NicProfile profile = networkToRelease.second();
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Asking " + element.getName() + " to release " + profile);
                }
                //NOTE: Context appear to never be used in release method
                //implementations. Consider removing it from interface Element
                element.release(network, profile, vmProfile, null);
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) TransactionStatus(com.cloud.utils.db.TransactionStatus) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VMNetworkMapVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO) NicVO(com.cloud.vm.NicVO) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 38 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class NetworkOrchestrator method reallocate.

@DB
@Override
public boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
    final VMInstanceVO vmInstance = _vmDao.findById(vm.getId());
    final DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId());
    if (dc.getNetworkType() == NetworkType.Basic) {
        final List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
        final NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
        final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<Network, List<? extends NicProfile>>();
        profiles.put(network, new ArrayList<NicProfile>());
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientCapacityException {
                cleanupNics(vm);
                allocate(vm, profiles);
            }
        });
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NicVO(com.cloud.vm.NicVO) DB(com.cloud.utils.db.DB)

Example 39 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testDesignNoElementOnPhysicalNetwork.

@Test
public void testDesignNoElementOnPhysicalNetwork() {
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList("STT"));
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NuageVspDeviceVO>emptyList());
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final DeploymentPlan plan = mock(DeploymentPlan.class);
    final Network network = mock(Network.class);
    final Account account = mock(Account.class);
    final Network designednetwork = _nuageVspGuestNetworkGuru.design(offering, plan, network, account);
    assertTrue(designednetwork == null);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) DeploymentPlan(com.cloud.deploy.DeploymentPlan) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 40 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeStop.

@Override
public void finalizeStop(final VirtualMachineProfile profile, final Answer answer) {
    if (answer != null) {
        final VirtualMachine vm = profile.getVirtualMachine();
        final DomainRouterVO domR = _routerDao.findById(vm.getId());
        processStopOrRebootAnswer(domR, answer);
        final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
        for (final Nic nic : routerNics) {
            final Network network = _networkModel.getNetwork(nic.getNetworkId());
            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
            if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
                try {
                    networkTopology.setupDhcpForPvlan(false, domR, domR.getHostId(), nicProfile);
                } catch (final ResourceUnavailableException e) {
                    s_logger.debug("ERROR in finalizeStop: ", e);
                }
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Network(com.cloud.network.Network) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

Network (com.cloud.network.Network)235 ArrayList (java.util.ArrayList)86 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)63 Account (com.cloud.user.Account)60 Test (org.junit.Test)55 NetworkOffering (com.cloud.offering.NetworkOffering)52 PhysicalNetwork (com.cloud.network.PhysicalNetwork)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)50 NetworkVO (com.cloud.network.dao.NetworkVO)38 DataCenter (com.cloud.dc.DataCenter)34 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 NicProfile (com.cloud.vm.NicProfile)31 HostVO (com.cloud.host.HostVO)27 DB (com.cloud.utils.db.DB)27 List (java.util.List)27 DataCenterVO (com.cloud.dc.DataCenterVO)26 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 HashMap (java.util.HashMap)24 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)23 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20