Search in sources :

Example 41 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cloudstack by apache.

the class AssociateIPAddrCmd method create.

@Override
public void create() throws ResourceAllocationException {
    try {
        IpAddress ip = null;
        if (!isPortable()) {
            ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId(), getDisplayIp(), ipAddress);
        } else {
            ip = _networkService.allocatePortableIP(_accountService.getAccount(getEntityOwnerId()), 1, getZoneId(), getNetworkId(), getVpcId());
        }
        if (ip != null) {
            setEntityId(ip.getId());
            setEntityUuid(ip.getUuid());
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to allocate IP address");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientAddressCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) IpAddress(com.cloud.network.IpAddress) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 42 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cloudstack by apache.

the class CreateLoadBalancerRuleCmd method create.

@Override
public void create() {
    // cidr list parameter is deprecated
    if (cidrlist != null) {
        throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command");
    }
    try {
        LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay());
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    } catch (InsufficientAddressCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    } catch (InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) LoadBalancer(com.cloud.network.rules.LoadBalancer) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 43 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cloudstack by apache.

the class CreateApplicationLoadBalancerCmd method create.

@Override
public void create() {
    try {
        ApplicationLoadBalancerRule result = _appLbService.createApplicationLoadBalancer(getName(), getDescription(), getScheme(), getSourceIpNetworkId(), getSourceIp(), getSourcePort(), getInstancePort(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getDisplay());
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    } catch (InsufficientAddressCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    } catch (InsufficientVirtualNetworkCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ApplicationLoadBalancerRule(org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 44 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cloudstack by apache.

the class AddIpToVmNicCmd method create.

@Override
public void create() throws ResourceAllocationException {
    NicSecondaryIp result;
    IpAddresses requestedIpPair = new IpAddresses(ipAddr, null);
    if (!NetUtils.isIpv4(ipAddr)) {
        requestedIpPair = new IpAddresses(null, ipAddr);
    }
    try {
        result = _networkService.allocateSecondaryGuestIP(getNicId(), requestedIpPair);
        if (result != null) {
            setEntityId(result.getId());
            setEntityUuid(result.getUuid());
        }
    } catch (InsufficientAddressCapacityException e) {
        throw new InvalidParameterValueException("Allocating guest ip for nic failed : " + e.getMessage());
    }
    if (result == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign secondary ip to nic");
    }
}
Also used : IpAddresses(com.cloud.network.Network.IpAddresses) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicSecondaryIp(com.cloud.vm.NicSecondaryIp)

Example 45 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cloudstack by apache.

the class NetworkOrchestrator method prepareNic.

@Override
public NicProfile prepareNic(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context, final long nicId, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vmProfile.getId());
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    final NicVO nic = _nicDao.findById(nicId);
    NicProfile profile = null;
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
        nic.setState(Nic.State.Reserving);
        nic.setReservationId(context.getReservationId());
        _nicDao.update(nic.getId(), nic);
        URI broadcastUri = nic.getBroadcastUri();
        if (broadcastUri == null) {
            broadcastUri = network.getBroadcastUri();
        }
        final URI isolationUri = nic.getIsolationUri();
        profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.reserve(profile, network, vmProfile, dest, context);
        nic.setIPv4Address(profile.getIPv4Address());
        nic.setAddressFormat(profile.getFormat());
        nic.setIPv6Address(profile.getIPv6Address());
        nic.setIPv6Cidr(profile.getIPv6Cidr());
        nic.setIPv6Gateway(profile.getIPv6Gateway());
        nic.setMacAddress(profile.getMacAddress());
        nic.setIsolationUri(profile.getIsolationUri());
        nic.setBroadcastUri(profile.getBroadCastUri());
        nic.setReserver(guru.getName());
        nic.setState(Nic.State.Reserved);
        nic.setIPv4Netmask(profile.getIPv4Netmask());
        nic.setIPv4Gateway(profile.getIPv4Gateway());
        if (profile.getReservationStrategy() != null) {
            nic.setReservationStrategy(profile.getReservationStrategy());
        }
        updateNic(nic, network.getId(), 1);
    } else {
        profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.updateNicProfile(profile, network);
        nic.setState(Nic.State.Reserved);
        updateNic(nic, network.getId(), 1);
    }
    final List<Provider> providersToImplement = getNetworkProviders(network.getId());
    for (final NetworkElement element : networkElements) {
        if (providersToImplement.contains(element.getProvider())) {
            if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
            }
            if (!prepareElement(element, network, profile, vmProfile, dest, context)) {
                throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity", Network.class, network.getId());
            }
        }
    }
    profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
    guru.updateNicProfile(profile, network);
    configureExtraDhcpOptions(network, nicId);
    return profile;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) ConfigDriveNetworkElement(com.cloud.network.element.ConfigDriveNetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) URI(java.net.URI) 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)

Aggregations

InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)22 IPAddressVO (com.cloud.network.dao.IPAddressVO)16 TransactionStatus (com.cloud.utils.db.TransactionStatus)15 Account (com.cloud.user.Account)14 DataCenter (com.cloud.dc.DataCenter)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 NicProfile (com.cloud.vm.NicProfile)12 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)11 DB (com.cloud.utils.db.DB)11 VlanVO (com.cloud.dc.VlanVO)9 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)9 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 PublicIp (com.cloud.network.addr.PublicIp)8 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)8 NicVO (com.cloud.vm.NicVO)8 ArrayList (java.util.ArrayList)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)7 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)7