Search in sources :

Example 6 with NetworkACLItem

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

the class ListNetworkACLsCmd method execute.

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

Example 7 with NetworkACLItem

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

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.legacymodel.network.vpc.NetworkACLItem) ServerApiException(com.cloud.api.ServerApiException) NetworkACLItemResponse(com.cloud.api.response.NetworkACLItemResponse)

Example 8 with NetworkACLItem

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

the class CommandSetupHelper method createNetworkACLsCommands.

public void createNetworkACLsCommands(final List<? extends NetworkACLItem> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId, final boolean privateGateway) {
    final List<NetworkACLTO> rulesTO = new ArrayList<>();
    String guestVlan = null;
    final Network guestNtwk = _networkDao.findById(guestNetworkId);
    final URI uri = guestNtwk.getBroadcastUri();
    if (uri != null) {
        guestVlan = BroadcastDomainType.getValue(uri);
    }
    if (rules != null) {
        for (final NetworkACLItem rule : rules) {
            final NetworkACLTO ruleTO = new NetworkACLTO(rule, guestVlan, rule.getTrafficType());
            rulesTO.add(ruleTO);
        }
    }
    final NicTO nicTO = _networkHelper.getNicTO(router, guestNetworkId, null);
    final SetNetworkACLCommand cmd = new SetNetworkACLCommand(rulesTO, nicTO);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, guestVlan);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final Zone zone = zoneRepository.findById(router.getDataCenterId()).orElse(null);
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, zone.getNetworkType().toString());
    if (privateGateway) {
        cmd.setAccessDetail(NetworkElementCommand.VPC_PRIVATE_GATEWAY, String.valueOf(VpcGateway.Type.Private));
    }
    cmds.addCommand(cmd);
}
Also used : NetworkACLItem(com.cloud.legacymodel.network.vpc.NetworkACLItem) NetworkACLTO(com.cloud.legacymodel.to.NetworkACLTO) Zone(com.cloud.db.model.Zone) Network(com.cloud.legacymodel.network.Network) ArrayList(java.util.ArrayList) SetNetworkACLCommand(com.cloud.legacymodel.communication.command.SetNetworkACLCommand) URI(java.net.URI) NicTO(com.cloud.legacymodel.to.NicTO)

Example 9 with NetworkACLItem

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

the class ApiResponseHelper method createNetworkACLItemResponse.

@Override
public NetworkACLItemResponse createNetworkACLItemResponse(final NetworkACLItem aclItem) {
    final 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());
    final 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());
    final NetworkACL acl = ApiDBUtils.findByNetworkACLId(aclItem.getAclId());
    if (acl != null) {
        response.setAclId(acl.getUuid());
    }
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.NetworkACL, aclItem.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("networkacl");
    return response;
}
Also used : NetworkACLItem(com.cloud.legacymodel.network.vpc.NetworkACLItem) ResourceTag(com.cloud.server.ResourceTag) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList) NetworkACL(com.cloud.legacymodel.network.vpc.NetworkACL) NetworkACLItemResponse(com.cloud.api.response.NetworkACLItemResponse)

Aggregations

NetworkACLItem (com.cloud.legacymodel.network.vpc.NetworkACLItem)9 ArrayList (java.util.ArrayList)5 NetworkACLItemResponse (com.cloud.api.response.NetworkACLItemResponse)4 ServerApiException (com.cloud.api.ServerApiException)2 Zone (com.cloud.db.model.Zone)2 Network (com.cloud.legacymodel.network.Network)2 NetworkACL (com.cloud.legacymodel.network.vpc.NetworkACL)2 NicTO (com.cloud.legacymodel.to.NicTO)2 List (java.util.List)2 ListResponse (com.cloud.api.response.ListResponse)1 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1 SetNetworkACLCommand (com.cloud.legacymodel.communication.command.SetNetworkACLCommand)1 SetPublicIpACLCommand (com.cloud.legacymodel.communication.command.SetPublicIpACLCommand)1 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 PrivateGateway (com.cloud.legacymodel.network.vpc.PrivateGateway)1 Vpc (com.cloud.legacymodel.network.vpc.Vpc)1 NetworkACLTO (com.cloud.legacymodel.to.NetworkACLTO)1 PublicIpACLTO (com.cloud.legacymodel.to.PublicIpACLTO)1 Account (com.cloud.legacymodel.user.Account)1 Pair (com.cloud.legacymodel.utils.Pair)1