Search in sources :

Example 46 with NetworkRuleConflictException

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

the class CreateStaticRouteCmd method create.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void create() throws ResourceAllocationException {
    try {
        StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getCidr());
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } catch (NetworkRuleConflictException ex) {
        s_logger.info("Network rule conflict: " + ex.getMessage());
        s_logger.trace("Network rule conflict: ", ex);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
    }
}
Also used : StaticRoute(com.cloud.network.vpc.StaticRoute) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 47 with NetworkRuleConflictException

use of com.cloud.exception.NetworkRuleConflictException in project CloudStack-archive by CloudStack-extras.

the class CreateLBStickinessPolicyCmd method create.

@Override
public void create() {
    try {
        StickinessPolicy result = _lbService.createLBStickinessPolicy(this);
        this.setEntityId(result.getId());
    } catch (NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) StickinessPolicy(com.cloud.network.rules.StickinessPolicy)

Example 48 with NetworkRuleConflictException

use of com.cloud.exception.NetworkRuleConflictException in project CloudStack-archive by CloudStack-extras.

the class CreatePortForwardingRuleCmd 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 {
        PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, getOpenFirewall());
        setEntityId(result.getId());
    } catch (NetworkRuleConflictException ex) {
        s_logger.info("Network rule conflict: ", ex);
        s_logger.trace("Network Rule Conflict: ", ex);
        throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 49 with NetworkRuleConflictException

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

the class VpcManagerImpl method createStaticRoute.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_CREATE, eventDescription = "creating static route", create = true)
public StaticRoute createStaticRoute(final long vpcId, final String cidr, final String gwIpAddress) throws NetworkRuleConflictException {
    final Account caller = CallContext.current().getCallingAccount();
    final Vpc vpc = getActiveVpc(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Can't add static route to VPC that is being deleted");
    }
    _accountMgr.checkAccess(caller, null, false, vpc);
    if (!NetUtils.isValidIp4Cidr(cidr)) {
        throw new InvalidParameterValueException("Invalid format for cidr " + cidr);
    }
    if (!NetUtils.isValidIp4(gwIpAddress)) {
        throw new InvalidParameterValueException("Invalid format for ip address " + gwIpAddress);
    }
    // CIDR should be outside of link-local cidr
    if (NetUtils.isNetworkAWithinNetworkB(cidr, NetUtils.getLinkLocalCIDR())) {
        throw new InvalidParameterValueException("CIDR should be outside of link local cidr " + NetUtils.getLinkLocalCIDR());
    }
    // Verify against blacklisted routes
    if (isCidrBlacklisted(cidr, vpc.getZoneId())) {
        throw new InvalidParameterValueException("The static gateway cidr overlaps with one of the blacklisted routes of the zone the VPC belongs to");
    }
    return Transaction.execute(new TransactionCallbackWithException<StaticRouteVO, NetworkRuleConflictException>() {

        @Override
        public StaticRouteVO doInTransaction(final TransactionStatus status) throws NetworkRuleConflictException {
            StaticRouteVO newRoute = new StaticRouteVO(cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId(), gwIpAddress);
            s_logger.debug("Adding static route " + newRoute);
            newRoute = _staticRouteDao.persist(newRoute);
            detectDuplicateCidr(newRoute);
            if (!_staticRouteDao.setStateToAdd(newRoute)) {
                throw new CloudRuntimeException("Unable to update the state to add for " + newRoute);
            }
            CallContext.current().setEventDetails("Static route Id: " + newRoute.getId());
            return newRoute;
        }
    });
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 50 with NetworkRuleConflictException

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

the class RulesManagerImpl method isIpReadyForStaticNat.

protected void isIpReadyForStaticNat(final long vmId, final IPAddressVO ipAddress, final String vmIp, final Account caller, final long callerUserId) throws NetworkRuleConflictException, ResourceUnavailableException {
    if (ipAddress.isSourceNat()) {
        throw new InvalidParameterValueException("Can't enable static, ip address " + ipAddress + " is a sourceNat ip address");
    }
    if (!ipAddress.isOneToOneNat()) {
        // Dont allow to enable static nat if PF/LB rules exist for the IP
        final List<FirewallRuleVO> portForwardingRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipAddress.getId(), Purpose.PortForwarding);
        if (portForwardingRules != null && !portForwardingRules.isEmpty()) {
            throw new NetworkRuleConflictException("Failed to enable static nat for the ip address " + ipAddress + " as it already has PortForwarding rules assigned");
        }
        final List<FirewallRuleVO> loadBalancingRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipAddress.getId(), Purpose.LoadBalancing);
        if (loadBalancingRules != null && !loadBalancingRules.isEmpty()) {
            throw new NetworkRuleConflictException("Failed to enable static nat for the ip address " + ipAddress + " as it already has LoadBalancing rules assigned");
        }
    } else if (ipAddress.getAssociatedWithVmId() != null && ipAddress.getAssociatedWithVmId().longValue() != vmId) {
        throw new NetworkRuleConflictException("Failed to enable static for the ip address " + ipAddress + " and vm id=" + vmId + " as it's already assigned to antoher vm");
    }
    // check wether the vm ip is alreday associated with any public ip address
    final IPAddressVO oldIP = _ipAddressDao.findByAssociatedVmIdAndVmIp(vmId, vmIp);
    if (oldIP != null) {
        // If elasticIP functionality is supported in the network, we always have to disable static nat on the old
        // ip in order to re-enable it on the new one
        final Long networkId = oldIP.getAssociatedWithNetworkId();
        final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
        boolean reassignStaticNat = false;
        if (networkId != null) {
            final Network guestNetwork = _networkModel.getNetwork(networkId);
            final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
            if (offering.getElasticIp()) {
                reassignStaticNat = true;
            }
        }
        // If there is public ip address already associated with the vm, throw an exception
        if (!reassignStaticNat) {
            throw new InvalidParameterValueException("Failed to enable static nat on the  ip " + ipAddress.getAddress() + " with Id " + ipAddress.getUuid() + " as the vm " + vm.getInstanceName() + " with Id " + vm.getUuid() + " is already associated with another public ip " + oldIP.getAddress() + " with id " + oldIP.getUuid());
        }
        // unassign old static nat rule
        s_logger.debug("Disassociating static nat for ip " + oldIP);
        if (!disableStaticNat(oldIP.getId(), caller, callerUserId, true)) {
            throw new CloudRuntimeException("Failed to disable old static nat rule for vm " + vm.getInstanceName() + " with id " + vm.getUuid() + "  and public ip " + oldIP);
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) VMInstanceVO(com.cloud.vm.VMInstanceVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Aggregations

NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)85 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)26 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)25 ServerApiException (org.apache.cloudstack.api.ServerApiException)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)19 ServerApiException (com.cloud.api.ServerApiException)18 Network (com.cloud.network.Network)18 IPAddressVO (com.cloud.network.dao.IPAddressVO)17 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)16 TransactionStatus (com.cloud.utils.db.TransactionStatus)16 DB (com.cloud.utils.db.DB)15 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)14 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)13 Account (com.cloud.user.Account)12 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)11 IpAddress (com.cloud.network.IpAddress)10 ActionEvent (com.cloud.event.ActionEvent)8