Search in sources :

Example 36 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class StorageNetworkGuru method reserve.

@Override
public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    if (!_sNwMgr.isStorageIpRangeAvailable(dest.getZone().getId())) {
        super.reserve(nic, network, vm, dest, context);
        return;
    }
    final Pod pod = dest.getPod();
    final Integer vlan;
    final StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId());
    if (ip == null) {
        throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId());
    }
    vlan = ip.getVlan();
    nic.setIPv4Address(ip.getIpAddress());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac())));
    nic.setFormat(AddressFormat.Ip4);
    nic.setIPv4Netmask(ip.getNetmask());
    nic.setBroadcastType(BroadcastDomainType.Storage);
    nic.setIPv4Gateway(ip.getGateway());
    if (vlan != null) {
        nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan));
    } else {
        nic.setBroadcastUri(null);
    }
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a storage nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.dc.Pod) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Example 37 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class IpAddressManagerImpl method associateIPToGuestNetwork.

@DB
@Override
public IPAddressVO associateIPToGuestNetwork(final long ipId, final long networkId, final boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    Account owner = null;
    final IPAddressVO ipToAssoc = _ipAddressDao.findById(ipId);
    if (ipToAssoc != null) {
        final Network network = _networksDao.findById(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Invalid network id is given");
        }
        final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
        if (zone.getNetworkType() == NetworkType.Advanced) {
            if (network.getGuestType() == Network.GuestType.Shared) {
                if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
                    _accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.UseEntry, false, network);
                } else {
                    throw new InvalidParameterValueException("IP can be associated with guest network of 'shared' type only if " + "network services Source Nat, Static Nat, Port Forwarding, Load balancing, firewall are enabled in the network");
                }
            }
        } else {
            _accountMgr.checkAccess(caller, null, true, ipToAssoc);
        }
        owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId());
    } else {
        s_logger.debug("Unable to find ip address by id: " + ipId);
        return null;
    }
    if (ipToAssoc.getAssociatedWithNetworkId() != null) {
        s_logger.debug("IP " + ipToAssoc + " is already assocaited with network id" + networkId);
        return ipToAssoc;
    }
    final Network network = _networksDao.findById(networkId);
    if (network != null) {
        _accountMgr.checkAccess(owner, AccessType.UseEntry, false, network);
    } else {
        s_logger.debug("Unable to find ip address by id: " + ipId);
        return null;
    }
    final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
    // allow associating IP addresses to guest network only
    if (network.getTrafficType() != TrafficType.Guest) {
        throw new InvalidParameterValueException("Ip address can be associated to the network with trafficType " + TrafficType.Guest);
    }
    // - and it belongs to the system
    if (network.getAccountId() != owner.getId()) {
        if (zone.getNetworkType() != NetworkType.Basic && !(zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Shared)) {
            throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP");
        }
    }
    if (zone.getNetworkType() == NetworkType.Advanced) {
        // In Advance zone allow to do IP assoc only for Isolated networks with source nat service enabled
        if (network.getGuestType() == GuestType.Isolated && !(_networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat))) {
            throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " + Service.SourceNat.getName() + " enabled");
        }
        // In Advance zone allow to do IP assoc only for shared networks with source nat/static nat/lb/pf services enabled
        if (network.getGuestType() == GuestType.Shared && !isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
            throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + " ip address can be associated with network of guest type " + GuestType.Shared + "only if at " + "least one of the services " + Service.SourceNat.getName() + "/" + Service.StaticNat.getName() + "/" + Service.Lb.getName() + "/" + Service.PortForwarding.getName() + " is enabled");
        }
    }
    s_logger.debug("Associating ip " + ipToAssoc + " to network " + network);
    final IPAddressVO ip = _ipAddressDao.findById(ipId);
    // update ip address with networkId
    ip.setAssociatedWithNetworkId(networkId);
    _ipAddressDao.update(ipId, ip);
    boolean success = false;
    try {
        success = applyIpAssociations(network, false);
        if (success) {
            s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network);
        } else {
            s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network);
        }
        return ip;
    } finally {
        if (!success && releaseOnFailure) {
            if (ip != null) {
                try {
                    s_logger.warn("Failed to associate ip address, so releasing ip from the database " + ip);
                    _ipAddressDao.markAsUnavailable(ip.getId());
                    if (!applyIpAssociations(network, true)) {
                        // if fail to apply ip assciations again, unassign ip address without updating resource
                        // count and generating usage event as there is no need to keep it in the db
                        _ipAddressDao.unassignIpAddress(ip.getId());
                    }
                } catch (final Exception e) {
                    s_logger.warn("Unable to disassociate ip address for recovery", e);
                }
            }
        }
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) IPAddressVO(com.cloud.network.dao.IPAddressVO) AccountLimitException(com.cloud.exception.AccountLimitException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DB(com.cloud.utils.db.DB)

Example 38 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class PodBasedNetworkGuru method reserve.

@Override
public void reserve(final NicProfile nic, final Network config, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    final Pod pod = dest.getPod();
    Pair<String, Long> ip = null;
    _ipAllocDao.releaseIpAddress(nic.getId());
    final DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dest.getZone().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId());
    if (vo != null) {
        ip = new Pair<>(vo.getIpAddress(), vo.getMacAddress());
    }
    if (ip == null) {
        throw new InsufficientAddressCapacityException("Unable to get a management ip address", Pod.class, pod.getId());
    }
    nic.setIPv4Address(ip.first());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.second())));
    nic.setIPv4Gateway(pod.getGateway());
    nic.setFormat(AddressFormat.Ip4);
    final String netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
    nic.setIPv4Netmask(netmask);
    nic.setBroadcastType(BroadcastDomainType.Native);
    nic.setBroadcastUri(null);
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.dc.Pod) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) DataCenterIpAddressVO(com.cloud.dc.DataCenterIpAddressVO)

Example 39 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class AssociateIPAddrCmd method create.

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

Example 40 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

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 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;
    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.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.reserve(profile, network, vmProfile, dest, context);
        nic.setIPv4Address(profile.getIPv4Address());
        nic.setAddressFormat(profile.getFormat());
        nic.setIPv6Address(profile.getIPv6Address());
        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.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());
            }
        }
    }
    guru.updateNicProfile(profile, network);
    return profile;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) 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) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) 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