Search in sources :

Example 46 with Network

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

the class VpcVirtualNetworkApplianceManagerImpl method setupVpcPrivateNetwork.

/**
     * @param router
     * @param add
     * @param privateNic
     * @return
     * @throws ResourceUnavailableException
     */
protected boolean setupVpcPrivateNetwork(final VirtualRouter router, final boolean add, final NicProfile privateNic) throws ResourceUnavailableException {
    if (router.getState() == State.Running) {
        final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIPv4Address());
        final Network network = _networkDao.findById(privateNic.getNetworkId());
        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, privateNic.getMacAddress());
        final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
        privateIps.add(ip);
        final Commands cmds = new Commands(Command.OnError.Stop);
        _commandSetupHelper.createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add);
        try {
            if (_nwHelper.sendCommandsToRouter(router, cmds)) {
                s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc network " + network);
                return true;
            } else {
                s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network);
                return false;
            }
        } catch (final Exception ex) {
            s_logger.warn("Failed to send  " + (add ? "add " : "delete ") + " private network " + network + " commands to rotuer ");
            return false;
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup private network command to the backend");
    } else {
        s_logger.warn("Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 47 with Network

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

the class NetworkHelperImpl method configureGuestNic.

@Override
public LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException {
    // Form networks
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
    // 1) Guest network
    final Network guestNetwork = routerDeploymentDefinition.getGuestNetwork();
    if (guestNetwork != null) {
        s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
        String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
        if (!routerDeploymentDefinition.isPublicNetwork()) {
            final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, routerDeploymentDefinition.getPodId());
            if (guestNetwork.getCidr() != null) {
                if (placeholder != null && placeholder.getIPv4Address() != null) {
                    s_logger.debug("Requesting ipv4 address " + placeholder.getIPv4Address() + " stored in placeholder nic for the network " + guestNetwork);
                    defaultNetworkStartIp = placeholder.getIPv4Address();
                } else {
                    final String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
                    if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
                        defaultNetworkStartIp = startIp;
                    } else if (s_logger.isDebugEnabled()) {
                        s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ip address from the range");
                    }
                }
            }
            if (guestNetwork.getIp6Cidr() != null) {
                if (placeholder != null && placeholder.getIPv6Address() != null) {
                    s_logger.debug("Requesting ipv6 address " + placeholder.getIPv6Address() + " stored in placeholder nic for the network " + guestNetwork);
                    defaultNetworkStartIpv6 = placeholder.getIPv6Address();
                } else {
                    final String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
                    if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
                        defaultNetworkStartIpv6 = startIpv6;
                    } else if (s_logger.isDebugEnabled()) {
                        s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ipv6 address from the range");
                    }
                }
            }
        }
        final NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
        if (routerDeploymentDefinition.isPublicNetwork()) {
            if (routerDeploymentDefinition.isRedundant()) {
                gatewayNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null));
            } else {
                gatewayNic.setIPv4Address(guestNetwork.getGateway());
            }
            gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
            gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
            gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
            gatewayNic.setMode(guestNetwork.getMode());
            final String gatewayCidr = guestNetwork.getCidr();
            gatewayNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr));
        } else {
            gatewayNic.setDefaultNic(true);
        }
        networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(gatewayNic)));
    }
    return networks;
}
Also used : Network(com.cloud.network.Network) Nic(com.cloud.vm.Nic) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 48 with Network

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

the class NetworkHelperImpl method configurePublicNic.

protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) {
    final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
    if (routerDeploymentDefinition.isPublicNetwork()) {
        s_logger.debug("Adding nic for Virtual Router in Public network ");
        // if source nat service is supported by the network, get the source
        // nat ip address
        final NicProfile defaultNic = new NicProfile();
        defaultNic.setDefaultNic(true);
        final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP();
        defaultNic.setIPv4Address(sourceNatIp.getAddress().addr());
        defaultNic.setIPv4Gateway(sourceNatIp.getGateway());
        defaultNic.setIPv4Netmask(sourceNatIp.getNetmask());
        defaultNic.setMacAddress(sourceNatIp.getMacAddress());
        // get broadcast from public network
        final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId());
        if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) {
            defaultNic.setBroadcastType(BroadcastDomainType.Vxlan);
            defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
            defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
        } else {
            defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
            defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
            defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
        }
        //If guest nic has already been added we will have 2 devices in the list.
        if (hasGuestNic) {
            defaultNic.setDeviceId(2);
        }
        final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
        final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false);
        final String publicIp = defaultNic.getIPv4Address();
        // We want to use the identical MAC address for RvR on public
        // interface if possible
        final NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId());
        if (peerNic != null) {
            s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress());
            defaultNic.setMacAddress(peerNic.getMacAddress());
        }
        publicConfig.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
    }
    return publicConfig;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) LinkedHashMap(java.util.LinkedHashMap)

Example 49 with Network

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

the class VpcVirtualNetworkApplianceManagerImpl method destroyPrivateGateway.

@Override
public boolean destroyPrivateGateway(final PrivateGateway gateway, final VirtualRouter router) throws ConcurrentOperationException, ResourceUnavailableException {
    boolean result = true;
    if (!_networkModel.isVmPartOfNetwork(router.getId(), gateway.getNetworkId())) {
        s_logger.debug("Router doesn't have nic for gateway " + gateway + " so no need to removed it");
        return result;
    }
    final Network privateNetwork = _networkModel.getNetwork(gateway.getNetworkId());
    final NicProfile nicProfile = _networkModel.getNicProfile(router, privateNetwork.getId(), null);
    s_logger.debug("Releasing private ip for gateway " + gateway + " from " + router);
    result = setupVpcPrivateNetwork(router, false, nicProfile);
    if (!result) {
        s_logger.warn("Failed to release private ip for gateway " + gateway + " on router " + router);
        return false;
    }
    // revoke network acl on the private gateway.
    if (!_networkACLMgr.revokeACLItemsForPrivateGw(gateway)) {
        s_logger.debug("Failed to delete network acl items on " + gateway + " from router " + router);
        return false;
    }
    s_logger.debug("Removing router " + router + " from private network " + privateNetwork + " as a part of delete private gateway");
    result = result && _itMgr.removeVmFromNetwork(router, privateNetwork, null);
    s_logger.debug("Private gateawy " + gateway + " is removed from router " + router);
    return result;
}
Also used : Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile)

Example 50 with Network

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

the class StorageNetworkGuru method release.

@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
    Network nw = _nwDao.findById(nic.getNetworkId());
    if (!_sNwMgr.isStorageIpRangeAvailable(nw.getDataCenterId())) {
        return super.release(nic, vm, reservationId);
    }
    _sNwMgr.releaseIpAddress(nic.getIPv4Address());
    s_logger.debug("Release an storage ip " + nic.getIPv4Address());
    nic.deallocate();
    return true;
}
Also used : Network(com.cloud.network.Network)

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