Search in sources :

Example 11 with InsufficientVirtualNetworkCapacityException

use of com.cloud.exception.InsufficientVirtualNetworkCapacityException 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 12 with InsufficientVirtualNetworkCapacityException

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

the class NiciraNvpGuestNetworkGuru method implement.

@Override
public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert network.getState() == State.Implementing : "Why are we implementing " + network;
    final long dcId = dest.getDataCenter().getId();
    Long physicalNetworkId = network.getPhysicalNetworkId();
    // physical network id can be null in Guest Network in Basic zone, so locate the physical network
    if (physicalNetworkId == null) {
        physicalNetworkId = networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    }
    final NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    if (name.length() > MAX_NAME_LENGTH) {
        name = name.substring(0, MAX_NAME_LENGTH - 1);
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
        return null;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
    final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
    if (offering.getGuestType().equals(GuestType.Shared)) {
        try {
            checkL2GatewayServiceSharedNetwork(niciraNvpHost);
        } catch (Exception e) {
            s_logger.error("L2 Gateway Service Issue: " + e.getMessage());
            return null;
        }
    }
    final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
    final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("CreateLogicalSwitchCommand failed");
        return null;
    }
    try {
        implemented.setBroadcastUri(new URI("lswitch", answer.getLogicalSwitchUuid(), null));
        implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch);
        s_logger.info("Implemented OK, network linked to  = " + implemented.getBroadcastUri().toString());
    } catch (final URISyntaxException e) {
        s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
        return null;
    }
    return implemented;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) URI(java.net.URI) HostVO(com.cloud.host.HostVO) URISyntaxException(java.net.URISyntaxException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException)

Example 13 with InsufficientVirtualNetworkCapacityException

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

the class GuestNetworkGuru method allocate.

@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    assert network.getTrafficType() == TrafficType.Guest : "Look at my name!  Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
    if (nic == null) {
        nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
    }
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    if (nic.getIPv4Address() == null) {
        nic.setBroadcastUri(network.getBroadcastUri());
        nic.setIsolationUri(network.getBroadcastUri());
        nic.setIPv4Gateway(network.getGateway());
        String guestIp = null;
        if (network.getSpecifyIpRanges()) {
            _ipAddrMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIPv4(), null);
        } else {
            //if Vm is router vm and source nat is enabled in the network, set ip4 to the network gateway
            boolean isGateway = false;
            if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
                if (network.getVpcId() != null) {
                    final Vpc vpc = _vpcDao.findById(network.getVpcId());
                    // Redundant Networks need a guest IP that is not the same as the gateway IP.
                    if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VPCVirtualRouter) && !vpc.isRedundant()) {
                        isGateway = true;
                    }
                } else {
                    if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VirtualRouter)) {
                        isGateway = true;
                    }
                }
            }
            if (isGateway) {
                guestIp = network.getGateway();
            } else {
                guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
                if (guestIp == null) {
                    throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, dc.getId());
                }
            }
            nic.setIPv4Address(guestIp);
            nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
            nic.setIPv4Dns1(dc.getDns1());
            nic.setIPv4Dns2(dc.getDns2());
            nic.setFormat(AddressFormat.Ip4);
        }
    }
    nic.setReservationStrategy(ReservationStrategy.Start);
    if (nic.getMacAddress() == null) {
        nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
        if (nic.getMacAddress() == null) {
            throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
        }
    }
    return nic;
}
Also used : DataCenter(com.cloud.dc.DataCenter) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) Vpc(com.cloud.network.vpc.Vpc) NicProfile(com.cloud.vm.NicProfile)

Example 14 with InsufficientVirtualNetworkCapacityException

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

the class ContrailGuru method implement.

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
        vnModel.setProperties(_manager.getModelController(), network);
    }
    try {
        if (!vnModel.verify(_manager.getModelController())) {
            vnModel.update(_manager.getModelController());
        }
    } catch (Exception ex) {
        s_logger.warn("virtual-network update: ", ex);
        return network;
    }
    _manager.getDatabase().getVirtualNetworks().add(vnModel);
    if (network.getVpcId() != null) {
        List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
        if (ips.isEmpty()) {
            s_logger.debug("Creating a source nat ip for network " + network);
            Account owner = _accountMgr.getAccount(network.getAccountId());
            try {
                PublicIp publicIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
                IPAddressVO ip = publicIp.ip();
                ip.setVpcId(network.getVpcId());
                _ipAddressDao.acquireInLockTable(ip.getId());
                _ipAddressDao.update(ip.getId(), ip);
                _ipAddressDao.releaseFromLockTable(ip.getId());
            } catch (Exception e) {
                s_logger.error("Unable to allocate source nat ip: " + e);
            }
        }
    }
    return network;
}
Also used : Account(com.cloud.user.Account) PublicIp(com.cloud.network.addr.PublicIp) IPAddressVO(com.cloud.network.dao.IPAddressVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 15 with InsufficientVirtualNetworkCapacityException

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

the class ContrailGuru method allocate.

/**
     * Allocate the NicProfile object.
     * At this point the UUID of the nic is not yet known. We defer allocating the VMI and instance-ip objects
     * until the reserve API is called because of this reason.
     */
@Override
public NicProfile allocate(Network network, NicProfile profile, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    s_logger.debug("allocate NicProfile on " + network.getName());
    if (profile != null && profile.getRequestedIPv4() != null) {
        throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + profile);
    }
    if (profile == null) {
        profile = new NicProfile(ReservationStrategy.Create, null, null, null, null);
    }
    profile.setReservationStrategy(ReservationStrategy.Start);
    URI broadcastUri = null;
    try {
        broadcastUri = new URI("vlan://untagged");
    } catch (Exception e) {
        s_logger.warn("unable to instantiate broadcast URI: " + e);
    }
    profile.setBroadcastUri(broadcastUri);
    return profile;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException)

Aggregations

InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)17 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)7 VspNetwork (net.nuage.vsp.acs.client.api.model.VspNetwork)6 DataCenter (com.cloud.dc.DataCenter)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 HostVO (com.cloud.host.HostVO)4 VlanVO (com.cloud.dc.VlanVO)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)3 AccountVO (com.cloud.user.AccountVO)3 NicVO (com.cloud.vm.NicVO)3 IOException (java.io.IOException)3 Answer (com.cloud.agent.api.Answer)2 Network (com.cloud.network.Network)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 Vpc (com.cloud.network.vpc.Vpc)2 NicProfile (com.cloud.vm.NicProfile)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 URI (java.net.URI)2