Search in sources :

Example 6 with StaticRoute

use of com.cloud.network.vpc.StaticRoute in project cloudstack by apache.

the class ListStaticRoutesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends StaticRoute>, Integer> result = _vpcService.listStaticRoutes(this);
    ListResponse<StaticRouteResponse> response = new ListResponse<StaticRouteResponse>();
    List<StaticRouteResponse> routeResponses = new ArrayList<StaticRouteResponse>();
    for (StaticRoute route : result.first()) {
        StaticRouteResponse ruleData = _responseGenerator.createStaticRouteResponse(route);
        routeResponses.add(ruleData);
    }
    response.setResponses(routeResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : StaticRoute(com.cloud.network.vpc.StaticRoute) StaticRouteResponse(org.apache.cloudstack.api.response.StaticRouteResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with StaticRoute

use of com.cloud.network.vpc.StaticRoute 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 8 with StaticRoute

use of com.cloud.network.vpc.StaticRoute in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method deleteNetwork.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_DELETE, eventDescription = "deleting network", async = true)
public boolean deleteNetwork(final long networkId, final boolean forced) {
    final Account caller = CallContext.current().getCallingAccount();
    // Verify network id
    final NetworkVO network = _networksDao.findById(networkId);
    if (network == null) {
        // see NetworkVO.java
        final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find network with specified id");
        ex.addProxyObject(String.valueOf(networkId), "networkId");
        throw ex;
    }
    // don't allow to delete system network
    if (isNetworkSystem(network)) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id is system and can't be removed");
        ex.addProxyObject(network.getUuid(), "networkId");
        throw ex;
    }
    final Account owner = _accountMgr.getAccount(network.getAccountId());
    // Only Admin can delete Shared networks
    if (network.getGuestType() == GuestType.Shared && !_accountMgr.isAdmin(caller.getId())) {
        throw new InvalidParameterValueException("Only Admins can delete network with guest type " + GuestType.Shared);
    }
    // Perform permission check
    _accountMgr.checkAccess(caller, null, true, network);
    if (forced && !_accountMgr.isRootAdmin(caller.getId())) {
        throw new InvalidParameterValueException("Delete network with 'forced' option can only be called by root admins");
    }
    // VPC networks should be checked for static routes before deletion
    if (network.getVpcId() != null) {
        // don't allow to remove network tier when there are static routes pointing to an ipaddress in the tier CIDR.
        final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcIdAndNotRevoked(network.getVpcId());
        for (final StaticRoute route : routes) {
            if (NetUtils.isIpWithtInCidrRange(route.getGwIpAddress(), network.getCidr())) {
                throw new CloudRuntimeException("Can't delete network " + network.getName() + " as it has static routes " + "applied pointing to the CIDR of the network (" + network.getCidr() + "). Example static route: " + route.getCidr() + " to " + route.getGwIpAddress() + ". Please remove all the routes pointing to the " + "network tier CIDR before attempting to delete it.");
            }
        }
    }
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
    return _networkMgr.destroyNetwork(networkId, context, forced);
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) StaticRoute(com.cloud.network.vpc.StaticRoute) User(com.cloud.user.User) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) ActionEvent(com.cloud.event.ActionEvent)

Example 9 with StaticRoute

use of com.cloud.network.vpc.StaticRoute 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.network.vpc.StaticRoute) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 10 with StaticRoute

use of com.cloud.network.vpc.StaticRoute in project cloudstack by apache.

the class CreateStaticRouteCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    boolean success = false;
    StaticRoute route = null;
    try {
        CallContext.current().setEventDetails("Static route Id: " + getEntityId());
        success = _vpcService.applyStaticRoute(getEntityId());
        // State is different after the route is applied, so retrieve the object only here
        route = _entityMgr.findById(StaticRoute.class, getEntityId());
        StaticRouteResponse routeResponse = new StaticRouteResponse();
        if (route != null) {
            routeResponse = _responseGenerator.createStaticRouteResponse(route);
            setResponseObject(routeResponse);
        }
        routeResponse.setResponseName(getCommandName());
    } finally {
        if (!success || route == null) {
            _entityMgr.remove(StaticRoute.class, getEntityId());
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create static route");
        }
    }
}
Also used : StaticRoute(com.cloud.network.vpc.StaticRoute) StaticRouteResponse(org.apache.cloudstack.api.response.StaticRouteResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

StaticRoute (com.cloud.network.vpc.StaticRoute)10 ArrayList (java.util.ArrayList)5 StaticRouteResponse (com.cloud.api.response.StaticRouteResponse)3 StaticRouteResponse (org.apache.cloudstack.api.response.StaticRouteResponse)3 ServerApiException (com.cloud.api.ServerApiException)2 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)2 Vpc (com.cloud.network.vpc.Vpc)2 ResourceTag (com.cloud.server.ResourceTag)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 List (java.util.List)2 Command (com.cloud.agent.api.Command)1 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)1 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)1 SetupGuestNetworkCommand (com.cloud.agent.api.SetupGuestNetworkCommand)1 AggregationControlCommand (com.cloud.agent.api.routing.AggregationControlCommand)1 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)1 ListResponse (com.cloud.api.response.ListResponse)1 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1 ActionEvent (com.cloud.event.ActionEvent)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1