Search in sources :

Example 1 with NetworkACLItemCidrsVO

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

the class NetworkACLItemCidrsDaoImpl method persist.

/* (non-Javadoc)
     * @see com.cloud.network.dao.NetworkAclItemCidrsDao#persist(long, java.util.List)
     */
@Override
public void persist(long networkACLItemId, List<String> cidrs) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    for (String cidr : cidrs) {
        NetworkACLItemCidrsVO vo = new NetworkACLItemCidrsVO(networkACLItemId, cidr);
        persist(vo);
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NetworkACLItemCidrsVO(com.cloud.network.vpc.NetworkACLItemCidrsVO)

Example 2 with NetworkACLItemCidrsVO

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

the class BigSwitchBcfUtils method listACLbyNetwork.

public List<AclData> listACLbyNetwork(Network network) {
    List<AclData> aclList = new ArrayList<AclData>();
    List<FirewallRuleVO> fwRules;
    fwRules = _fwRulesDao.listByNetworkAndPurposeAndNotRevoked(network.getId(), Purpose.Firewall);
    List<FirewallRulesCidrsVO> fwCidrList = null;
    SubnetUtils utils;
    for (FirewallRuleVO rule : fwRules) {
        AclData acl = new AclData();
        acl.setId(rule.getUuid());
        // CloudStack Firewall interface does not have priority
        acl.setPriority((int) rule.getId());
        acl.setIpProto(rule.getProtocol());
        String cidr = null;
        Integer port = rule.getSourcePortStart();
        fwCidrList = _fwCidrsDao.listByFirewallRuleId(rule.getId());
        if (fwCidrList != null) {
            if (fwCidrList.size() > 1 || !rule.getSourcePortEnd().equals(port)) {
                continue;
            } else {
                cidr = fwCidrList.get(0).getCidr();
            }
        }
        if (cidr == null || cidr.equalsIgnoreCase("0.0.0.0/0")) {
            cidr = "";
        } else {
            utils = new SubnetUtils(cidr);
            if (!utils.getInfo().getNetworkAddress().equals(utils.getInfo().getAddress())) {
                continue;
            }
        }
        acl.setSource(acl.new AclNetwork(cidr, port));
        acl.setAction("permit");
        aclList.add(acl);
    }
    List<NetworkACLItemVO> aclItems;
    List<NetworkACLItemCidrsVO> aclCidrList;
    if (network.getNetworkACLId() != null) {
        aclItems = _aclItemDao.listByACL(network.getNetworkACLId());
        for (NetworkACLItem item : aclItems) {
            AclData acl = new AclData();
            acl.setId(item.getUuid());
            acl.setPriority(item.getNumber());
            acl.setIpProto(item.getProtocol());
            // currently BCF supports single cidr policy
            String cidr = null;
            // currently BCF supports single port policy
            Integer port = item.getSourcePortStart();
            aclCidrList = _aclItemCidrsDao.listByNetworkACLItemId(item.getId());
            if (aclCidrList != null) {
                if (aclCidrList.size() > 1 || !item.getSourcePortEnd().equals(port)) {
                    continue;
                } else {
                    cidr = aclCidrList.get(0).getCidr();
                }
            }
            if (cidr == null || cidr.equalsIgnoreCase("0.0.0.0/0")) {
                cidr = "";
            } else {
                utils = new SubnetUtils(cidr);
                if (!utils.getInfo().getNetworkAddress().equals(utils.getInfo().getAddress())) {
                    continue;
                }
            }
            acl.setSource(acl.new AclNetwork(cidr, port));
            acl.setAction(item.getAction().name());
            aclList.add(acl);
        }
    }
    return aclList;
}
Also used : SubnetUtils(org.apache.commons.net.util.SubnetUtils) ArrayList(java.util.ArrayList) NetworkACLItemCidrsVO(com.cloud.network.vpc.NetworkACLItemCidrsVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) FirewallRulesCidrsVO(com.cloud.network.dao.FirewallRulesCidrsVO)

Example 3 with NetworkACLItemCidrsVO

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

the class NetworkACLItemCidrsDaoImpl method getCidrs.

/* (non-Javadoc)
     * @see com.cloud.network.dao.NetworkAclItemCidrsDao#getCidrs(long)
     */
@Override
public List<String> getCidrs(long networkACLItemId) {
    SearchCriteria<NetworkACLItemCidrsVO> sc = cidrsSearch.create();
    sc.setParameters("networkAclItemId", networkACLItemId);
    List<NetworkACLItemCidrsVO> results = search(sc, null);
    List<String> cidrs = new ArrayList<String>(results.size());
    for (NetworkACLItemCidrsVO result : results) {
        cidrs.add(result.getCidr());
    }
    return cidrs;
}
Also used : ArrayList(java.util.ArrayList) NetworkACLItemCidrsVO(com.cloud.network.vpc.NetworkACLItemCidrsVO)

Aggregations

NetworkACLItemCidrsVO (com.cloud.network.vpc.NetworkACLItemCidrsVO)3 ArrayList (java.util.ArrayList)2 FirewallRulesCidrsVO (com.cloud.network.dao.FirewallRulesCidrsVO)1 FirewallRuleVO (com.cloud.network.rules.FirewallRuleVO)1 NetworkACLItem (com.cloud.network.vpc.NetworkACLItem)1 NetworkACLItemVO (com.cloud.network.vpc.NetworkACLItemVO)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 SubnetUtils (org.apache.commons.net.util.SubnetUtils)1