Search in sources :

Example 1 with StaticRoute

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

the class VpcManagerImpl method applyStaticRoutes.

private boolean applyStaticRoutes(final List<? extends StaticRoute> routes, final Account caller, final boolean updateRoutesInDB) throws ResourceUnavailableException {
    final List<StaticRouteProfile> staticRouteProfiles = new ArrayList<>(routes.size());
    for (final StaticRoute route : routes) {
        staticRouteProfiles.add(new StaticRouteProfile(route));
    }
    if (!applyStaticRoutes(staticRouteProfiles)) {
        s_logger.warn("Routes are not completely applied");
        return false;
    } else {
        if (updateRoutesInDB) {
            for (final StaticRoute route : routes) {
                if (route.getState() == StaticRoute.State.Revoke) {
                    _staticRouteDao.remove(route.getId());
                    s_logger.debug("Removed route " + route + " from the DB");
                } else if (route.getState() == StaticRoute.State.Add) {
                    final StaticRouteVO ruleVO = _staticRouteDao.findById(route.getId());
                    ruleVO.setState(StaticRoute.State.Active);
                    _staticRouteDao.update(ruleVO.getId(), ruleVO);
                    s_logger.debug("Marked route " + route + " with state " + StaticRoute.State.Active);
                }
            }
        }
    }
    return true;
}
Also used : StaticRoute(com.cloud.legacymodel.network.vpc.StaticRoute) StaticRouteProfile(com.cloud.legacymodel.network.vpc.StaticRouteProfile) ArrayList(java.util.ArrayList)

Example 2 with StaticRoute

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

the class ListStaticRoutesCmd method execute.

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

Example 3 with StaticRoute

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

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) {
            _vpcService.revokeStaticRoute(getEntityId());
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create static route");
        }
    }
}
Also used : StaticRoute(com.cloud.legacymodel.network.vpc.StaticRoute) StaticRouteResponse(com.cloud.api.response.StaticRouteResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 4 with StaticRoute

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

the class ApiResponseHelper method createStaticRouteResponse.

@Override
public StaticRouteResponse createStaticRouteResponse(final StaticRoute result) {
    final StaticRouteResponse response = new StaticRouteResponse();
    response.setId(result.getUuid());
    if (result.getVpcId() != null) {
        final Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
        }
    }
    response.setCidr(result.getCidr());
    response.setGwIpAddress(result.getGwIpAddress());
    StaticRoute.State state = result.getState();
    if (state.equals(StaticRoute.State.Revoke)) {
        state = StaticRoute.State.Deleting;
    }
    response.setState(state.toString());
    populateAccount(response, result.getAccountId());
    populateDomain(response, result.getDomainId());
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        if (tagResponse != null) {
            tagResponses.add(tagResponse);
        }
    }
    response.setTags(tagResponses);
    response.setObjectName("staticroute");
    return response;
}
Also used : StaticRouteResponse(com.cloud.api.response.StaticRouteResponse) StaticRoute(com.cloud.legacymodel.network.vpc.StaticRoute) ResourceTag(com.cloud.server.ResourceTag) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList)

Example 5 with StaticRoute

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

Aggregations

StaticRoute (com.cloud.legacymodel.network.vpc.StaticRoute)7 ArrayList (java.util.ArrayList)4 StaticRouteResponse (com.cloud.api.response.StaticRouteResponse)3 ServerApiException (com.cloud.api.ServerApiException)2 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 List (java.util.List)2 ListResponse (com.cloud.api.response.ListResponse)1 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)1 NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)1 Provider (com.cloud.legacymodel.network.Network.Provider)1 PrivateGateway (com.cloud.legacymodel.network.vpc.PrivateGateway)1 StaticRouteProfile (com.cloud.legacymodel.network.vpc.StaticRouteProfile)1 Vpc (com.cloud.legacymodel.network.vpc.Vpc)1 Account (com.cloud.legacymodel.user.Account)1 User (com.cloud.legacymodel.user.User)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1