Search in sources :

Example 46 with InsufficientAddressCapacityException

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

the class NetworkOrchestratorTest method configureTestConfigureNicProfileBasedOnRequestedIpTests.

private void configureTestConfigureNicProfileBasedOnRequestedIpTests(NicProfile nicProfile, long ipvoId, boolean ipVoIsNull, IPAddressVO.State state, String vlanGateway, String vlanNetmask, String macAddress, NicProfile requestedNicProfile, String nicProfileMacAddress, String requestedIpv4Address) {
    IPAddressVO ipVoSpy = Mockito.spy(new IPAddressVO(new Ip("192.168.100.100"), 0l, 0l, 0l, true));
    ipVoSpy.setState(state);
    requestedNicProfile.setRequestedIPv4(requestedIpv4Address);
    nicProfile.setMacAddress(nicProfileMacAddress);
    when(ipVoSpy.getId()).thenReturn(ipvoId);
    when(ipVoSpy.getState()).thenReturn(state);
    if (ipVoIsNull) {
        when(testOrchastrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
    } else {
        when(testOrchastrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
    }
    VlanVO vlanSpy = Mockito.spy(new VlanVO(Vlan.VlanType.DirectAttached, "vlanTag", vlanGateway, vlanNetmask, 0l, "192.168.100.100 - 192.168.100.200", 0l, new Long(0l), "ip6Gateway", "ip6Cidr", "ip6Range"));
    Mockito.doReturn(0l).when(vlanSpy).getId();
    when(testOrchastrator._vlanDao.findByNetworkIdAndIpv4(Mockito.anyLong(), Mockito.anyString())).thenReturn(vlanSpy);
    when(testOrchastrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
    when(testOrchastrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
    when(testOrchastrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
    try {
        when(testOrchastrator._networkModel.getNextAvailableMacAddressInNetwork(Mockito.anyLong())).thenReturn(macAddress);
    } catch (InsufficientAddressCapacityException e) {
        e.printStackTrace();
    }
}
Also used : Ip(com.cloud.utils.net.Ip) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO)

Example 47 with InsufficientAddressCapacityException

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

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");
    }
    if (lbProtocol != null && !lbProtocol.toLowerCase().equals("tcp")) {
        throw new InvalidParameterValueException("Only TCP protocol is supported because HAProxy can only do TCP.");
    }
    try {
        final LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay(), getClientTimeout(), getServerTimeout());
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (final NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    } catch (final InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) LoadBalancer(com.cloud.network.rules.LoadBalancer) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 48 with InsufficientAddressCapacityException

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

the class VmwareVmImplementer method configureDomainRouterNicsAndDetails.

private void configureDomainRouterNicsAndDetails(VirtualMachineProfile vm, VirtualMachineTO to, Map<String, String> details, List<NicProfile> nicProfiles) {
    NicProfile publicNicProfile = null;
    for (NicProfile nicProfile : nicProfiles) {
        if (nicProfile.getTrafficType() == Networks.TrafficType.Public) {
            publicNicProfile = nicProfile;
            break;
        }
    }
    if (publicNicProfile != null) {
        NicTO[] nics = to.getNics();
        // reserve extra NICs
        NicTO[] expandedNics = new NicTO[nics.length];
        int i = 0;
        int deviceId = -1;
        for (i = 0; i < nics.length; i++) {
            expandedNics[i] = nics[i];
            if (nics[i].getDeviceId() > deviceId)
                deviceId = nics[i].getDeviceId();
        }
        deviceId++;
        long networkId = publicNicProfile.getNetworkId();
        NetworkVO network = networkDao.findById(networkId);
        for (; i < nics.length; i++) {
            NicTO nicTo = new NicTO();
            nicTo.setDeviceId(deviceId++);
            nicTo.setBroadcastType(publicNicProfile.getBroadcastType());
            nicTo.setType(publicNicProfile.getTrafficType());
            nicTo.setIp("0.0.0.0");
            nicTo.setNetmask("255.255.255.255");
            try {
                String mac = networkMgr.getNextAvailableMacAddressInNetwork(networkId);
                nicTo.setMac(mac);
            } catch (InsufficientAddressCapacityException e) {
                throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
            }
            nicTo.setDns1(publicNicProfile.getIPv4Dns1());
            nicTo.setDns2(publicNicProfile.getIPv4Dns2());
            if (publicNicProfile.getIPv4Gateway() != null) {
                nicTo.setGateway(publicNicProfile.getIPv4Gateway());
            } else {
                nicTo.setGateway(network.getGateway());
            }
            nicTo.setDefaultNic(false);
            nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri());
            nicTo.setIsolationuri(publicNicProfile.getIsolationUri());
            Integer networkRate = networkMgr.getNetworkRate(network.getId(), null);
            nicTo.setNetworkRateMbps(networkRate);
            expandedNics[i] = nicTo;
        }
        to.setNics(expandedNics);
        VirtualMachine router = vm.getVirtualMachine();
        DomainRouterVO routerVO = domainRouterDao.findById(router.getId());
        if (routerVO != null && routerVO.getIsRedundantRouter()) {
            Long peerRouterId = nicDao.getPeerRouterId(publicNicProfile.getMacAddress(), router.getId());
            DomainRouterVO peerRouterVO = null;
            if (peerRouterId != null) {
                peerRouterVO = domainRouterDao.findById(peerRouterId);
                if (peerRouterVO != null) {
                    details.put("PeerRouterInstanceName", peerRouterVO.getInstanceName());
                }
            }
        }
    }
    StringBuffer sbMacSequence = new StringBuffer();
    for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
        sbMacSequence.append(nicTo.getMac()).append("|");
    }
    if (!sbMacSequence.toString().isEmpty()) {
        sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
        String bootArgs = to.getBootArgs();
        to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DomainRouterVO(com.cloud.vm.DomainRouterVO) NicTO(com.cloud.agent.api.to.NicTO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 49 with InsufficientAddressCapacityException

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

the class NetworkMigrationManagerImpl method migrateNicsInDB.

private Boolean migrateNicsInDB(NicVO originalNic, Network networkInNewPhysicalNet, DataCenter dc, ReservationContext context) {
    s_logger.debug("migrating nics in database.");
    UserVmVO vmVO = _vmDao.findById(originalNic.getInstanceId());
    VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
    NicProfile nicProfile = new NicProfile(originalNic, networkInNewPhysicalNet, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(networkInNewPhysicalNet), null);
    try {
        nicProfile = _networkMgr.allocateNic(nicProfile, networkInNewPhysicalNet, originalNic.isDefaultNic(), nicProfile.getDeviceId(), vmProfile).first();
    } catch (InsufficientVirtualNetworkCapacityException | InsufficientAddressCapacityException e) {
        throw new CloudRuntimeException("Allocation of new nicProfile failed during migration", e);
    }
    // Update vm_network_map table
    if (vmProfile.getType() == VirtualMachine.Type.User) {
        final VMNetworkMapVO vno = new VMNetworkMapVO(vmVO.getId(), networkInNewPhysicalNet.getId());
        _vmNetworkMapDao.persist(vno);
    }
    NicVO newNic = _nicDao.findById(nicProfile.getId());
    copyNicDetails(originalNic.getId(), newNic.getId());
    // Update nic uuid here
    moveServices(originalNic, newNic);
    if (originalNic.getState() == Nic.State.Reserved) {
        final VirtualMachine vm = vmProfile.getVirtualMachine();
        final Host host = _hostDao.findById(vm.getHostId());
        final DeployDestination dest = new DeployDestination(dc, null, null, host);
        try {
            nicProfile = _networkMgr.prepareNic(vmProfile, dest, context, nicProfile.getId(), networkInNewPhysicalNet);
            _itMgr.replugNic(networkInNewPhysicalNet, _itMgr.toNicTO(nicProfile, host.getHypervisorType()), _itMgr.toVmTO(vmProfile), dest.getHost());
        } catch (ResourceUnavailableException | InsufficientCapacityException e) {
            throw new CloudRuntimeException("Migration of Nic failed", e);
        }
    }
    // Mark the old nic as removed
    markAsNonDefault(originalNic);
    _networkMgr.removeNic(vmProfile, originalNic);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Nic is migrated successfully for vm " + vmVO + " to " + networkInNewPhysicalNet);
    }
    return true;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) Host(com.cloud.host.Host) NicProfile(com.cloud.vm.NicProfile) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VMNetworkMapVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NicVO(com.cloud.vm.NicVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 50 with InsufficientAddressCapacityException

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

the class Ipv6AddressManagerImpl method acquireGuestIpv6Address.

/**
 * Allocates a guest IPv6 address for the guest NIC. It will throw exceptions in the following cases:
 * <ul>
 *    <li>there is no IPv6 address available in the network;</li>
 *    <li>IPv6 address is equals to the Gateway;</li>
 *    <li>the network offering is empty;</li>
 *    <li>the IPv6 address is not in the network;</li>
 *    <li>the requested IPv6 address is already in use in the network.</li>
 * </ul>
 */
@Override
@DB
public String acquireGuestIpv6Address(Network network, String requestedIpv6) throws InsufficientAddressCapacityException {
    if (!_networkModel.areThereIPv6AddressAvailableInNetwork(network.getId())) {
        throw new InsufficientAddressCapacityException(String.format("There is no IPv6 address available in the network [name=%s, network id=%s]", network.getName(), network.getId()), DataCenter.class, network.getDataCenterId());
    }
    if (NetUtils.isIPv6EUI64(requestedIpv6)) {
        throw new InsufficientAddressCapacityException(String.format("Requested IPv6 address [%s] may not be a EUI-64 address", requestedIpv6), DataCenter.class, network.getDataCenterId());
    }
    checkIfCanAllocateIpv6Address(network, requestedIpv6);
    IpAddresses requestedIpPair = new IpAddresses(null, requestedIpv6);
    _networkModel.checkRequestedIpAddresses(network.getId(), requestedIpPair);
    IPAddressVO ip = ipAddressDao.findByIpAndSourceNetworkId(network.getId(), requestedIpv6);
    if (ip != null) {
        State ipState = ip.getState();
        if (ipState != State.Free) {
            throw new InsufficientAddressCapacityException(String.format("Requested ip address [%s] is not free [ip state=%]", requestedIpv6, ipState), DataCenter.class, network.getDataCenterId());
        }
    }
    return requestedIpv6;
}
Also used : IpAddresses(com.cloud.network.Network.IpAddresses) State(com.cloud.network.IpAddress.State) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) IPAddressVO(com.cloud.network.dao.IPAddressVO) DB(com.cloud.utils.db.DB)

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