Search in sources :

Example 1 with StaticRouteResponse

use of org.apache.cloudstack.api.response.StaticRouteResponse in project cloudstack by apache.

the class ApiResponseHelper method createStaticRouteResponse.

@Override
public StaticRouteResponse createStaticRouteResponse(StaticRoute result) {
    StaticRouteResponse response = new StaticRouteResponse();
    response.setId(result.getUuid());
    if (result.getVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
        }
    }
    response.setCidr(result.getCidr());
    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
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setObjectName("staticroute");
    return response;
}
Also used : StaticRouteResponse(org.apache.cloudstack.api.response.StaticRouteResponse) StaticRoute(com.cloud.network.vpc.StaticRoute) ResourceTag(com.cloud.server.ResourceTag) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse)

Example 2 with StaticRouteResponse

use of org.apache.cloudstack.api.response.StaticRouteResponse 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 3 with StaticRouteResponse

use of org.apache.cloudstack.api.response.StaticRouteResponse 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) {
            _vpcService.revokeStaticRoute(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)3 StaticRouteResponse (org.apache.cloudstack.api.response.StaticRouteResponse)3 ArrayList (java.util.ArrayList)2 Vpc (com.cloud.network.vpc.Vpc)1 ResourceTag (com.cloud.server.ResourceTag)1 List (java.util.List)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1