Search in sources :

Example 1 with Vlan

use of com.cloud.legacymodel.dc.Vlan in project cosmic by MissionCriticalCloud.

the class CreateVlanIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        final Vlan result = _configService.createVlanAndPublicIpRange(this);
        if (result != null) {
            final VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vlan ip range");
        }
    } catch (final ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (final InsufficientCapacityException ex) {
        s_logger.info(ex.toString());
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
}
Also used : VlanIpRangeResponse(com.cloud.api.response.VlanIpRangeResponse) ServerApiException(com.cloud.api.ServerApiException) Vlan(com.cloud.legacymodel.dc.Vlan) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException)

Example 2 with Vlan

use of com.cloud.legacymodel.dc.Vlan in project cosmic by MissionCriticalCloud.

the class DedicatePublicIpRangeCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    final Vlan result = _configService.dedicatePublicIpRange(this);
    if (result != null) {
        final VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate vlan ip range");
    }
}
Also used : VlanIpRangeResponse(com.cloud.api.response.VlanIpRangeResponse) ServerApiException(com.cloud.api.ServerApiException) Vlan(com.cloud.legacymodel.dc.Vlan)

Example 3 with Vlan

use of com.cloud.legacymodel.dc.Vlan in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method commitVlan.

private Vlan commitVlan(final Long zoneId, final Long podId, final String startIP, final String endIP, final String newVlanGatewayFinal, final String newVlanNetmaskFinal, final String vlanId, final Boolean forVirtualNetwork, final Long networkId, final Long physicalNetworkId, final String startIPv6, final String endIPv6, final String ip6Gateway, final String ip6Cidr, final Domain domain, final Account vlanOwner, final Network network, final Pair<Boolean, Pair<String, String>> sameSubnet) {
    return Transaction.execute(new TransactionCallback<Vlan>() {

        @Override
        public Vlan doInTransaction(final TransactionStatus status) {
            String newVlanNetmask = newVlanNetmaskFinal;
            String newVlanGateway = newVlanGatewayFinal;
            if ((sameSubnet == null || sameSubnet.first() == false) && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared && _vlanDao.listVlansByNetworkId(networkId) != null) {
                final Map<Capability, String> dhcpCapabilities = _networkSvc.getNetworkOfferingServiceCapabilities(_networkOfferingDao.findById(network.getNetworkOfferingId()), Service.Dhcp);
                final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
                if (supportsMultipleSubnets == null || !Boolean.valueOf(supportsMultipleSubnets)) {
                    throw new InvalidParameterValueException("The Dhcp serivice provider for this network dose not support the dhcp  across multiple subnets");
                }
                s_logger.info("adding a new subnet to the network " + network.getId());
            } else if (sameSubnet != null) {
                // if it is same subnet the user might not send the vlan and the
                // netmask details. so we are
                // figuring out while validation and setting them here.
                newVlanGateway = sameSubnet.second().first();
                newVlanNetmask = sameSubnet.second().second();
            }
            final Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, newVlanGateway, newVlanNetmask, vlanId, domain, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
            // gateway that will be configured on the corresponding routervm.
            return vlan;
        }
    });
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Vlan(com.cloud.legacymodel.dc.Vlan) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Vlan

use of com.cloud.legacymodel.dc.Vlan in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method isIP6AddressAvailableInNetwork.

@Override
public boolean isIP6AddressAvailableInNetwork(final long networkId) {
    final Network network = _networksDao.findById(networkId);
    if (network == null) {
        return false;
    }
    if (network.getIp6Gateway() == null) {
        return false;
    }
    final List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
    for (final Vlan vlan : vlans) {
        if (isIP6AddressAvailableInVlan(vlan.getId())) {
            return true;
        }
    }
    return false;
}
Also used : Network(com.cloud.legacymodel.network.Network) Vlan(com.cloud.legacymodel.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Example 5 with Vlan

use of com.cloud.legacymodel.dc.Vlan in project cosmic by MissionCriticalCloud.

the class Ipv6AddressManagerImpl method assignDirectIp6Address.

@Override
public UserIpv6Address assignDirectIp6Address(final long dcId, final Account owner, final Long networkId, final String requestedIp6) throws InsufficientAddressCapacityException {
    final Network network = _networkDao.findById(networkId);
    if (network == null) {
        return null;
    }
    final List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
    if (vlans == null) {
        s_logger.debug("Cannot find related vlan attached to network " + networkId);
        return null;
    }
    String ip = null;
    Vlan ipVlan = null;
    if (requestedIp6 == null) {
        if (!_networkModel.isIP6AddressAvailableInNetwork(networkId)) {
            throw new InsufficientAddressCapacityException("There is no more address available in the network " + network.getName(), DataCenter.class, network.getDataCenterId());
        }
        for (final Vlan vlan : vlans) {
            if (!_networkModel.isIP6AddressAvailableInVlan(vlan.getId())) {
                continue;
            }
            ip = NetUtils.getIp6FromRange(vlan.getIp6Range());
            int count = 0;
            while (_ipv6Dao.findByNetworkIdAndIp(networkId, ip) != null) {
                ip = NetUtils.getNextIp6InRange(ip, vlan.getIp6Range());
                count++;
                // It's an arbitrate number to prevent the infinite loop
                if (count > _ipv6RetryMax) {
                    ip = null;
                    break;
                }
            }
            if (ip != null) {
                ipVlan = vlan;
            }
        }
        if (ip == null) {
            throw new InsufficientAddressCapacityException("Cannot find a usable IP in the network " + network.getName() + " after " + _ipv6RetryMax + "(network.ipv6.search.retry.max) times retry!", DataCenter.class, network.getDataCenterId());
        }
    } else {
        for (final Vlan vlan : vlans) {
            if (NetUtils.isIp6InRange(requestedIp6, vlan.getIp6Range())) {
                ipVlan = vlan;
                break;
            }
        }
        if (ipVlan == null) {
            throw new CloudRuntimeException("Requested IPv6 is not in the predefined range!");
        }
        ip = requestedIp6;
        if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip) != null) {
            throw new CloudRuntimeException("The requested IP is already taken!");
        }
    }
    final Zone zone = zoneRepository.findById(dcId).orElse(null);
    final Long mac = zone.getMacAddress();
    final Long nextMac = mac + 1;
    zone.setMacAddress(nextMac);
    zoneRepository.save(zone);
    final String macAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(mac));
    final UserIpv6AddressVO ipVO = new UserIpv6AddressVO(ip, dcId, macAddress, ipVlan.getId());
    ipVO.setPhysicalNetworkId(network.getPhysicalNetworkId());
    ipVO.setSourceNetworkId(networkId);
    ipVO.setState(UserIpv6Address.State.Allocated);
    ipVO.setDomainId(owner.getDomainId());
    ipVO.setAccountId(owner.getAccountId());
    _ipv6Dao.persist(ipVO);
    return ipVO;
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Zone(com.cloud.db.model.Zone) Network(com.cloud.legacymodel.network.Network) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) Vlan(com.cloud.legacymodel.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Aggregations

Vlan (com.cloud.legacymodel.dc.Vlan)12 VlanVO (com.cloud.dc.VlanVO)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)4 ArrayList (java.util.ArrayList)4 VlanIpRangeResponse (com.cloud.api.response.VlanIpRangeResponse)3 Network (com.cloud.legacymodel.network.Network)3 ServerApiException (com.cloud.api.ServerApiException)2 HostPodVO (com.cloud.dc.HostPodVO)2 IpAddress (com.cloud.network.IpAddress)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 List (java.util.List)2 ListResponse (com.cloud.api.response.ListResponse)1 SystemVmResponse (com.cloud.api.response.SystemVmResponse)1 Zone (com.cloud.db.model.Zone)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 HostVO (com.cloud.host.HostVO)1 ConfigurePortForwardingRulesOnLogicalRouterAnswer (com.cloud.legacymodel.communication.answer.ConfigurePortForwardingRulesOnLogicalRouterAnswer)1 ConfigurePortForwardingRulesOnLogicalRouterCommand (com.cloud.legacymodel.communication.command.ConfigurePortForwardingRulesOnLogicalRouterCommand)1