Search in sources :

Example 1 with NetworkACLItemResponse

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

the class ListNetworkACLsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends NetworkACLItem>, Integer> result = _networkACLService.listNetworkACLItems(this);
    ListResponse<NetworkACLItemResponse> response = new ListResponse<NetworkACLItemResponse>();
    List<NetworkACLItemResponse> aclResponses = new ArrayList<NetworkACLItemResponse>();
    for (NetworkACLItem acl : result.first()) {
        NetworkACLItemResponse ruleData = _responseGenerator.createNetworkACLItemResponse(acl);
        aclResponses.add(ruleData);
    }
    response.setResponses(aclResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NetworkACLItemResponse(org.apache.cloudstack.api.response.NetworkACLItemResponse)

Example 2 with NetworkACLItemResponse

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

the class UpdateNetworkACLItemCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    CallContext.current().setEventDetails("Rule Id: " + getId());
    NetworkACLItem aclItem = _networkACLService.updateNetworkACLItem(getId(), getProtocol(), getSourceCidrList(), getTrafficType(), getAction(), getNumber(), getSourcePortStart(), getSourcePortEnd(), getIcmpCode(), getIcmpType(), this.getCustomId(), this.isDisplay());
    if (aclItem == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network ACL item");
    }
    NetworkACLItemResponse aclResponse = _responseGenerator.createNetworkACLItemResponse(aclItem);
    setResponseObject(aclResponse);
    aclResponse.setResponseName(getCommandName());
}
Also used : NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkACLItemResponse(org.apache.cloudstack.api.response.NetworkACLItemResponse)

Example 3 with NetworkACLItemResponse

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

the class CreateNetworkACLCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    boolean success = false;
    NetworkACLItem rule = _networkACLService.getNetworkACLItem(getEntityId());
    try {
        CallContext.current().setEventDetails("Rule ID: " + getEntityId());
        success = _networkACLService.applyNetworkACL(rule.getAclId());
        // State is different after the rule is applied, so get new object here
        rule = _networkACLService.getNetworkACLItem(getEntityId());
        NetworkACLItemResponse aclResponse = new NetworkACLItemResponse();
        if (rule != null) {
            aclResponse = _responseGenerator.createNetworkACLItemResponse(rule);
            setResponseObject(aclResponse);
        }
        aclResponse.setResponseName(getCommandName());
    } finally {
        if (!success || rule == null) {
            _networkACLService.revokeNetworkACLItem(getEntityId());
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network ACL Item");
        }
    }
}
Also used : NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkACLItemResponse(org.apache.cloudstack.api.response.NetworkACLItemResponse)

Example 4 with NetworkACLItemResponse

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

the class ApiResponseHelper method createNetworkACLItemResponse.

@Override
public NetworkACLItemResponse createNetworkACLItemResponse(NetworkACLItem aclItem) {
    NetworkACLItemResponse response = new NetworkACLItemResponse();
    response.setId(aclItem.getUuid());
    response.setProtocol(aclItem.getProtocol());
    if (aclItem.getSourcePortStart() != null) {
        response.setStartPort(Integer.toString(aclItem.getSourcePortStart()));
    }
    if (aclItem.getSourcePortEnd() != null) {
        response.setEndPort(Integer.toString(aclItem.getSourcePortEnd()));
    }
    response.setCidrList(StringUtils.join(aclItem.getSourceCidrList(), ","));
    response.setTrafficType(aclItem.getTrafficType().toString());
    NetworkACLItem.State state = aclItem.getState();
    String stateToSet = state.toString();
    if (state.equals(NetworkACLItem.State.Revoke)) {
        stateToSet = "Deleting";
    }
    response.setIcmpCode(aclItem.getIcmpCode());
    response.setIcmpType(aclItem.getIcmpType());
    response.setState(stateToSet);
    response.setNumber(aclItem.getNumber());
    response.setAction(aclItem.getAction().toString());
    response.setForDisplay(aclItem.isDisplay());
    NetworkACL acl = ApiDBUtils.findByNetworkACLId(aclItem.getAclId());
    if (acl != null) {
        response.setAclId(acl.getUuid());
    }
    //set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.NetworkACL, aclItem.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("networkacl");
    return response;
}
Also used : NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ResourceTag(com.cloud.server.ResourceTag) ArrayList(java.util.ArrayList) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) NetworkACL(com.cloud.network.vpc.NetworkACL) NetworkACLItemResponse(org.apache.cloudstack.api.response.NetworkACLItemResponse)

Aggregations

NetworkACLItem (com.cloud.network.vpc.NetworkACLItem)4 NetworkACLItemResponse (org.apache.cloudstack.api.response.NetworkACLItemResponse)4 ArrayList (java.util.ArrayList)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 NetworkACL (com.cloud.network.vpc.NetworkACL)1 ResourceTag (com.cloud.server.ResourceTag)1 List (java.util.List)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1