Search in sources :

Example 16 with NetworkRuleConflictException

use of com.cloud.legacymodel.exceptions.NetworkRuleConflictException 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().startsWith("tcp")) {
        throw new InvalidParameterValueException("Only TCP protocol is supported because HAProxy can only do TCP.");
    }
    if (getAlgorithm() != null && !NetUtils.isValidAlgorithm(getAlgorithm())) {
        throw new InvalidParameterValueException("Only source/roundrobin/leastconn are supported loadbalance algorithms.");
    }
    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.legacymodel.exceptions.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException)

Example 17 with NetworkRuleConflictException

use of com.cloud.legacymodel.exceptions.NetworkRuleConflictException in project cosmic by MissionCriticalCloud.

the class CreateEgressFirewallRuleCmd method create.

@Override
public void create() {
    if (getSourceCidrList() != null) {
        final String guestCidr = _networkService.getNetwork(getNetworkId()).getCidr();
        for (final String cidr : getSourceCidrList()) {
            if (!NetUtils.isValidIp4Cidr(cidr) && !NetUtils.isValidIp6Cidr(cidr)) {
                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Source cidrs formatting error " + cidr);
            }
            if (cidr.equals(NetUtils.ALL_IP4_CIDRS)) {
                continue;
            }
            if (!NetUtils.isNetworkAWithinNetworkB(cidr, guestCidr)) {
                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, cidr + " is not within the guest cidr " + guestCidr);
            }
        }
    }
    if (getProtocol().equalsIgnoreCase(NetUtils.ALL_PROTO)) {
        if (getSourcePortStart() != null && getSourcePortEnd() != null) {
            throw new InvalidParameterValueException("Do not pass ports to protocol ALL, protocol ALL do not require ports. Unable to create " + "firewall rule for the network id=" + networkId);
        }
    }
    if (getVpcId() != null) {
        throw new InvalidParameterValueException("Unable to create firewall rule for the network id=" + networkId + " as firewall egress rule can be created only for non vpc networks.");
    }
    try {
        final FirewallRule result = _firewallService.createEgressFirewallRule(this);
        if (result != null) {
            setEntityId(result.getId());
            setEntityUuid(result.getUuid());
        }
    } catch (final 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 : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) FirewallRule(com.cloud.legacymodel.network.FirewallRule) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException)

Example 18 with NetworkRuleConflictException

use of com.cloud.legacymodel.exceptions.NetworkRuleConflictException in project cosmic by MissionCriticalCloud.

the class CreateIpForwardingRuleCmd 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 {
        final StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
        setEntityId(rule.getId());
        setEntityUuid(rule.getUuid());
    } catch (final NetworkRuleConflictException e) {
        s_logger.info("Unable to create static NAT rule due to ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException)

Example 19 with NetworkRuleConflictException

use of com.cloud.legacymodel.exceptions.NetworkRuleConflictException in project cosmic by MissionCriticalCloud.

the class CreateStaticRouteCmd method create.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void create() throws ResourceAllocationException {
    try {
        checkDeprecatedParameters();
        final StaticRoute result = _vpcService.createStaticRoute(getVpcId(), getCidr(), getNextHop());
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } catch (final 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.legacymodel.network.vpc.StaticRoute) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException)

Example 20 with NetworkRuleConflictException

use of com.cloud.legacymodel.exceptions.NetworkRuleConflictException in project cosmic by MissionCriticalCloud.

the class CreateRemoteAccessVpnCmd method create.

@Override
public void create() {
    try {
        final RemoteAccessVpn vpn = _ravService.createRemoteAccessVpn(publicIpId, ipRange, getOpenFirewall(), isDisplay());
        if (vpn != null) {
            setEntityId(vpn.getId());
            setEntityUuid(vpn.getUuid());
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn");
        }
    } catch (final NetworkRuleConflictException e) {
        s_logger.info("Network rule conflict: " + e.getMessage());
        s_logger.trace("Network Rule Conflict: ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn)

Aggregations

NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)26 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)14 ServerApiException (com.cloud.api.ServerApiException)12 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)10 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)9 Network (com.cloud.legacymodel.network.Network)8 IPAddressVO (com.cloud.network.dao.IPAddressVO)8 DB (com.cloud.utils.db.DB)7 TransactionStatus (com.cloud.utils.db.TransactionStatus)7 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)6 Account (com.cloud.legacymodel.user.Account)6 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)5 CallContext (com.cloud.context.CallContext)4 ActionEvent (com.cloud.event.ActionEvent)4 IpAddress (com.cloud.network.IpAddress)4 NetworkOffering (com.cloud.offering.NetworkOffering)4 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)3 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)3 FirewallRule (com.cloud.legacymodel.network.FirewallRule)3 Ip (com.cloud.legacymodel.network.Ip)3