Search in sources :

Example 21 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class IpAddressManagerImpl method allocatePortableIp.

@Override
@DB
public IpAddress allocatePortableIp(final Account ipOwner, Account caller, final long dcId, final Long networkId, final Long vpcID) throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException {
    GlobalLock portableIpLock = GlobalLock.getInternLock("PortablePublicIpRange");
    IPAddressVO ipaddr;
    try {
        portableIpLock.lock(5);
        ipaddr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO, InsufficientAddressCapacityException>() {

            @Override
            public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
                PortableIpVO allocatedPortableIp;
                List<PortableIpVO> portableIpVOs = _portableIpDao.listByRegionIdAndState(1, PortableIp.State.Free);
                if (portableIpVOs == null || portableIpVOs.isEmpty()) {
                    InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available portable IP addresses", Region.class, new Long(1));
                    throw ex;
                }
                // allocate first portable IP to the user
                allocatedPortableIp = portableIpVOs.get(0);
                allocatedPortableIp.setAllocatedTime(new Date());
                allocatedPortableIp.setAllocatedToAccountId(ipOwner.getAccountId());
                allocatedPortableIp.setAllocatedInDomainId(ipOwner.getDomainId());
                allocatedPortableIp.setState(PortableIp.State.Allocated);
                _portableIpDao.update(allocatedPortableIp.getId(), allocatedPortableIp);
                // To make portable IP available as a zone level resource we need to emulate portable IP's (which are
                // provisioned at region level) as public IP provisioned in a zone. user_ip_address and vlan combo give the
                // identity of a public IP in zone. Create entry for portable ip in these tables.
                // provision portable IP range VLAN into the zone
                long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public).getId();
                Network network = _networkModel.getSystemNetworkByZoneAndTrafficType(dcId, TrafficType.Public);
                String range = allocatedPortableIp.getAddress() + "-" + allocatedPortableIp.getAddress();
                VlanVO vlan = new VlanVO(VlanType.VirtualNetwork, allocatedPortableIp.getVlan(), allocatedPortableIp.getGateway(), allocatedPortableIp.getNetmask(), dcId, range, network.getId(), physicalNetworkId, null, null, null);
                vlan = _vlanDao.persist(vlan);
                // provision the portable IP in to user_ip_address table
                IPAddressVO ipaddr = new IPAddressVO(new Ip(allocatedPortableIp.getAddress()), dcId, networkId, vpcID, physicalNetworkId, network.getId(), vlan.getId(), true);
                ipaddr.setState(State.Allocated);
                ipaddr.setAllocatedTime(new Date());
                ipaddr.setAllocatedInDomainId(ipOwner.getDomainId());
                ipaddr.setAllocatedToAccountId(ipOwner.getId());
                ipaddr = _ipAddressDao.persist(ipaddr);
                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_PORTABLE_IP_ASSIGN, ipaddr.getId(), ipaddr.getDataCenterId(), ipaddr.getId(), ipaddr.getAddress().toString(), ipaddr.isSourceNat(), null, ipaddr.getSystem(), ipaddr.getClass().getName(), ipaddr.getUuid());
                return ipaddr;
            }
        });
    } finally {
        portableIpLock.unlock();
    }
    return ipaddr;
}
Also used : TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) PortableIp(org.apache.cloudstack.region.PortableIp) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) TransactionStatus(com.cloud.utils.db.TransactionStatus) PortableIpVO(org.apache.cloudstack.region.PortableIpVO) Date(java.util.Date) GlobalLock(com.cloud.utils.db.GlobalLock) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) DB(com.cloud.utils.db.DB)

Example 22 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class NetworkModelImpl method getStartIpv6Address.

@Override
public String getStartIpv6Address(long networkId) {
    List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
    if (vlans == null) {
        return null;
    }
    String startIpv6 = null;
    // Get the start ip of first create vlan(not the lowest, because if you add a lower vlan, lowest vlan would change)
    for (Vlan vlan : vlans) {
        if (vlan.getIp6Range() != null) {
            startIpv6 = vlan.getIp6Range().split("-")[0];
            break;
        }
    }
    return startIpv6;
}
Also used : Vlan(com.cloud.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Example 23 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class VpcManagerImpl method configure.

@Override
@DB
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    // configure default vpc offering
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
                s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
                final Set<Provider> defaultProviders = new HashSet<Provider>();
                defaultProviders.add(Provider.VPCVirtualRouter);
                for (final Service svc : getSupportedServices()) {
                    if (svc == Service.Lb) {
                        final Set<Provider> lbProviders = new HashSet<Provider>();
                        lbProviders.add(Provider.VPCVirtualRouter);
                        lbProviders.add(Provider.InternalLbVm);
                        svcProviderMap.put(svc, lbProviders);
                    } else {
                        svcProviderMap.put(svc, defaultProviders);
                    }
                }
                createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, true, State.Enabled, null, false, false, false);
            }
            // configure default vpc offering with Netscaler as LB Provider
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCNSOfferingName) == null) {
                s_logger.debug("Creating default VPC offering with Netscaler as LB Provider" + VpcOffering.defaultVPCNSOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
                final Set<Provider> defaultProviders = new HashSet<Provider>();
                defaultProviders.add(Provider.VPCVirtualRouter);
                for (final Service svc : getSupportedServices()) {
                    if (svc == Service.Lb) {
                        final Set<Provider> lbProviders = new HashSet<Provider>();
                        lbProviders.add(Provider.Netscaler);
                        lbProviders.add(Provider.InternalLbVm);
                        svcProviderMap.put(svc, lbProviders);
                    } else {
                        svcProviderMap.put(svc, defaultProviders);
                    }
                }
                createVpcOffering(VpcOffering.defaultVPCNSOfferingName, VpcOffering.defaultVPCNSOfferingName, svcProviderMap, false, State.Enabled, null, false, false, false);
            }
            if (_vpcOffDao.findByUniqueName(VpcOffering.redundantVPCOfferingName) == null) {
                s_logger.debug("Creating Redundant VPC offering " + VpcOffering.redundantVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
                final Set<Provider> defaultProviders = new HashSet<Provider>();
                defaultProviders.add(Provider.VPCVirtualRouter);
                for (final Service svc : getSupportedServices()) {
                    if (svc == Service.Lb) {
                        final Set<Provider> lbProviders = new HashSet<Provider>();
                        lbProviders.add(Provider.VPCVirtualRouter);
                        lbProviders.add(Provider.InternalLbVm);
                        svcProviderMap.put(svc, lbProviders);
                    } else {
                        svcProviderMap.put(svc, defaultProviders);
                    }
                }
                createVpcOffering(VpcOffering.redundantVPCOfferingName, VpcOffering.redundantVPCOfferingName, svcProviderMap, true, State.Enabled, null, false, false, true);
            }
        }
    });
    final Map<String, String> configs = _configDao.getConfiguration(params);
    final String value = configs.get(Config.VpcCleanupInterval.key());
    // 1 hour
    _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60);
    final String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
    // max=3 is default
    _maxNetworks = NumbersUtil.parseInt(maxNtwks, 3);
    IpAddressSearch = _ipAddressDao.createSearchBuilder();
    IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
    IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
    IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ);
    IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
    final SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder();
    virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
    IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER);
    IpAddressSearch.done();
    return true;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NetworkService(com.cloud.network.NetworkService) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) VlanVO(com.cloud.dc.VlanVO) Map(java.util.Map) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Example 24 with VlanVO

use of com.cloud.dc.VlanVO 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 25 with VlanVO

use of com.cloud.dc.VlanVO 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

VlanVO (com.cloud.dc.VlanVO)58 ArrayList (java.util.ArrayList)22 IPAddressVO (com.cloud.network.dao.IPAddressVO)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)14 DB (com.cloud.utils.db.DB)14 HostVO (com.cloud.host.HostVO)11 Network (com.cloud.network.Network)11 Account (com.cloud.user.Account)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 List (java.util.List)8 Answer (com.cloud.agent.api.Answer)7 AccountVlanMapVO (com.cloud.dc.AccountVlanMapVO)7 DataCenter (com.cloud.dc.DataCenter)7 PublicIp (com.cloud.network.addr.PublicIp)7 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)6 NetworkOffering (com.cloud.offering.NetworkOffering)6 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)6