Search in sources :

Example 16 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NetworkModelImpl method getProviderToIpList.

@Override
public Map<Provider, ArrayList<PublicIpAddress>> getProviderToIpList(Network network, Map<PublicIpAddress, Set<Service>> ipToServices) {
    NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (!offering.isConserveMode()) {
        for (PublicIpAddress ip : ipToServices.keySet()) {
            Set<Service> services = new HashSet<Service>();
            services.addAll(ipToServices.get(ip));
            if (services != null && services.contains(Service.Firewall)) {
                services.remove(Service.Firewall);
            }
            if (services != null && services.size() > 1) {
                throw new CloudRuntimeException("Ip " + ip.getAddress() + " is used by multiple services!");
            }
        }
    }
    Map<Service, Set<PublicIpAddress>> serviceToIps = new HashMap<Service, Set<PublicIpAddress>>();
    for (PublicIpAddress ip : ipToServices.keySet()) {
        for (Service service : ipToServices.get(ip)) {
            Set<PublicIpAddress> ips = serviceToIps.get(service);
            if (ips == null) {
                ips = new HashSet<PublicIpAddress>();
            }
            ips.add(ip);
            serviceToIps.put(service, ips);
        }
    }
    // TODO Check different provider for same IP
    Map<Provider, Set<Service>> providerToServices = getProviderServicesMap(network.getId());
    Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = new HashMap<Provider, ArrayList<PublicIpAddress>>();
    for (Provider provider : providerToServices.keySet()) {
        if (!(getElementImplementingProvider(provider.getName()) instanceof IpDeployingRequester)) {
            continue;
        }
        Set<Service> services = providerToServices.get(provider);
        ArrayList<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
        Set<PublicIpAddress> ipSet = new HashSet<PublicIpAddress>();
        for (Service service : services) {
            Set<PublicIpAddress> serviceIps = serviceToIps.get(service);
            if (serviceIps == null || serviceIps.isEmpty()) {
                continue;
            }
            ipSet.addAll(serviceIps);
        }
        Set<PublicIpAddress> sourceNatIps = serviceToIps.get(Service.SourceNat);
        if (sourceNatIps != null && !sourceNatIps.isEmpty()) {
            ipList.addAll(0, sourceNatIps);
            ipSet.removeAll(sourceNatIps);
        }
        ipList.addAll(ipSet);
        providerToIpList.put(provider, ipList);
    }
    return providerToIpList;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HashSet(java.util.HashSet)

Example 17 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class IpAddressManagerImpl method assignSystemIp.

@Override
public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException {
    Network guestNetwork = _networksDao.findById(networkId);
    NetworkOffering off = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
    IpAddress ip = null;
    if ((off.getElasticLb() && forElasticLb) || (off.getElasticIp() && forElasticIp)) {
        try {
            s_logger.debug("Allocating system IP address for load balancer rule...");
            // allocate ip
            ip = allocateIP(owner, true, guestNetwork.getDataCenterId());
            // apply ip associations
            ip = associateIPToGuestNetwork(ip.getId(), networkId, true);
            ;
        } catch (ResourceAllocationException ex) {
            throw new CloudRuntimeException("Failed to allocate system ip due to ", ex);
        } catch (ConcurrentOperationException ex) {
            throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex);
        } catch (ResourceUnavailableException ex) {
            throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex);
        }
        if (ip == null) {
            throw new CloudRuntimeException("Failed to allocate system ip");
        }
    }
    return ip;
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 18 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NetworkModelImpl method getNetworkTag.

@Override
public String getNetworkTag(HypervisorType hType, Network network) {
    // no network tag for control traffic type
    TrafficType effectiveTrafficType = network.getTrafficType();
    if (hType == HypervisorType.VMware && effectiveTrafficType == TrafficType.Control)
        effectiveTrafficType = TrafficType.Management;
    if (effectiveTrafficType == TrafficType.Control) {
        return null;
    }
    Long physicalNetworkId = null;
    if (effectiveTrafficType != TrafficType.Guest) {
        physicalNetworkId = getNonGuestNetworkPhysicalNetworkId(network, effectiveTrafficType);
    } else {
        NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        physicalNetworkId = network.getPhysicalNetworkId();
        if (physicalNetworkId == null) {
            physicalNetworkId = findPhysicalNetworkId(network.getDataCenterId(), offering.getTags(), offering.getTrafficType());
        }
    }
    if (physicalNetworkId == null) {
        assert (false) : "Can't get the physical network";
        s_logger.warn("Can't get the physical network");
        return null;
    }
    return _pNTrafficTypeDao.getNetworkTag(physicalNetworkId, effectiveTrafficType, hType);
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) TrafficType(com.cloud.network.Networks.TrafficType)

Example 19 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NiciraNvpElementTest method implementSharedNetworkNumericalVlanIdWithoutL2GatewayService.

@Test(expected = CloudRuntimeException.class)
public void implementSharedNetworkNumericalVlanIdWithoutL2GatewayService() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getGuestType()).thenReturn(GuestType.Shared);
    when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
    when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
    HostVO niciraNvpHost = mock(HostVO.class);
    when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
    when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    final DeployDestination dest = mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    //SHARED NETWORKS CASE 2
    when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(false);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanTag()).thenReturn("111");
    when(vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Arrays.asList(new VlanVO[] { vlanVO }));
    when(niciraNvpHost.getDetail("l2gatewayserviceuuid")).thenReturn(null);
    element.implement(network, offering, dest, context);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Domain(com.cloud.domain.Domain) VlanVO(com.cloud.dc.VlanVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 20 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NiciraNvpElementTest method implementSharedNetworkNumericalVlanIdTest.

@Test
public void implementSharedNetworkNumericalVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // SHARED NETWORKS CASE 2: NUMERICAL VLAN ID
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getGuestType()).thenReturn(GuestType.Shared);
    when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
    when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
    HostVO niciraNvpHost = mock(HostVO.class);
    when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
    when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    final DeployDestination dest = mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    //SHARED NETWORKS CASE 2
    when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(false);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanTag()).thenReturn("111");
    when(vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Arrays.asList(new VlanVO[] { vlanVO }));
    when(niciraNvpHost.getDetail("l2gatewayserviceuuid")).thenReturn("bbbb-bbbb-bbbb");
    final ConfigureSharedNetworkVlanIdAnswer answer = mock(ConfigureSharedNetworkVlanIdAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
    assertTrue(element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Domain(com.cloud.domain.Domain) VlanVO(com.cloud.dc.VlanVO) URI(java.net.URI) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Aggregations

NetworkOffering (com.cloud.offering.NetworkOffering)94 Network (com.cloud.network.Network)51 Account (com.cloud.user.Account)41 Test (org.junit.Test)34 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)24 DataCenter (com.cloud.dc.DataCenter)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)23 NetworkVO (com.cloud.network.dao.NetworkVO)22 DeployDestination (com.cloud.deploy.DeployDestination)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 HostVO (com.cloud.host.HostVO)17 ReservationContext (com.cloud.vm.ReservationContext)17 Domain (com.cloud.domain.Domain)16 IPAddressVO (com.cloud.network.dao.IPAddressVO)13 List (java.util.List)13 NicProfile (com.cloud.vm.NicProfile)12 DeploymentPlan (com.cloud.deploy.DeploymentPlan)11 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)11 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)11