Search in sources :

Example 1 with VpcGateway

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

the class VpcGatewayDaoImpl method getNetworkAclIdForPrivateIp.

@Override
public Long getNetworkAclIdForPrivateIp(final long vpcId, final long networkId, final String ipaddr) {
    final SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create();
    sc.setParameters("vpcId", vpcId);
    sc.setParameters("networkid", networkId);
    sc.setParameters("ipaddress", ipaddr);
    final VpcGateway vpcGateway = findOneBy(sc);
    if (vpcGateway != null) {
        return vpcGateway.getNetworkACLId();
    } else {
        return null;
    }
}
Also used : VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway)

Example 2 with VpcGateway

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

the class VpcManagerImpl method listPrivateGateway.

@Override
public Pair<List<PrivateGateway>, Integer> listPrivateGateway(final ListPrivateGatewaysCmd cmd) {
    final String ipAddress = cmd.getIpAddress();
    final String networkId = cmd.getNetworkId();
    final Long vpcId = cmd.getVpcId();
    final Long id = cmd.getId();
    Boolean isRecursive = cmd.isRecursive();
    final Boolean listAll = cmd.listAll();
    Long domainId = cmd.getDomainId();
    final String accountName = cmd.getAccountName();
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final String state = cmd.getState();
    final Long projectId = cmd.getProjectId();
    final Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final SearchBuilder<VpcGatewayVO> sb = _vpcGatewayDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    final SearchCriteria<VpcGatewayVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (id != null) {
        sc.addAnd("id", Op.EQ, id);
    }
    if (ipAddress != null) {
        sc.addAnd("ip4Address", Op.EQ, ipAddress);
    }
    if (state != null) {
        sc.addAnd("state", Op.EQ, state);
    }
    if (vpcId != null) {
        sc.addAnd("vpcId", Op.EQ, vpcId);
    }
    if (networkId != null) {
        sc.addAnd("networkId", Op.EQ, networkId);
    }
    final Pair<List<VpcGatewayVO>, Integer> vos = _vpcGatewayDao.searchAndCount(sc, searchFilter);
    final List<PrivateGateway> privateGtws = new ArrayList<>(vos.first().size());
    for (final VpcGateway vo : vos.first()) {
        privateGtws.add(getPrivateGatewayProfile(vo));
    }
    return new Pair<>(privateGtws, vos.second());
}
Also used : Account(com.cloud.legacymodel.user.Account) Ternary(com.cloud.legacymodel.utils.Ternary) ArrayList(java.util.ArrayList) PrivateGateway(com.cloud.legacymodel.network.vpc.PrivateGateway) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(com.cloud.legacymodel.utils.Pair)

Example 3 with VpcGateway

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

the class NetworkACLServiceImpl method replaceNetworkACLonPrivateGw.

@Override
public boolean replaceNetworkACLonPrivateGw(final long aclId, final long privateGatewayId) throws ResourceUnavailableException {
    final Account caller = CallContext.current().getCallingAccount();
    final VpcGateway gateway = _vpcGatewayDao.findById(privateGatewayId);
    if (gateway == null) {
        throw new InvalidParameterValueException("Unable to find specified private gateway");
    }
    final VpcGatewayVO vo = _vpcGatewayDao.findById(privateGatewayId);
    if (vo.getState() != VpcGateway.State.Ready) {
        throw new InvalidParameterValueException("Gateway is not in Ready state");
    }
    final NetworkACL acl = _networkACLDao.findById(aclId);
    if (acl == null) {
        throw new InvalidParameterValueException("Unable to find specified NetworkACL");
    }
    if (gateway.getVpcId() == null) {
        throw new InvalidParameterValueException("Unable to find specified vpc id");
    }
    if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
        final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
        if (vpc == null) {
            throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL");
        }
        _accountMgr.checkAccess(caller, null, true, vpc);
        if (!gateway.getVpcId().equals(acl.getVpcId())) {
            throw new InvalidParameterValueException("private gateway: " + privateGatewayId + " and ACL: " + aclId + " do not belong to the same VPC");
        }
    }
    final PrivateGateway privateGateway = _vpcSvc.getVpcPrivateGateway(gateway.getId());
    _accountMgr.checkAccess(caller, null, true, privateGateway);
    return _networkAclMgr.replaceNetworkACLForPrivateGw(acl, privateGateway);
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) Vpc(com.cloud.legacymodel.network.vpc.Vpc) NetworkACL(com.cloud.legacymodel.network.vpc.NetworkACL) PrivateGateway(com.cloud.legacymodel.network.vpc.PrivateGateway)

Aggregations

VpcGateway (com.cloud.legacymodel.network.vpc.VpcGateway)3 PrivateGateway (com.cloud.legacymodel.network.vpc.PrivateGateway)2 Account (com.cloud.legacymodel.user.Account)2 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 NetworkACL (com.cloud.legacymodel.network.vpc.NetworkACL)1 Vpc (com.cloud.legacymodel.network.vpc.Vpc)1 Pair (com.cloud.legacymodel.utils.Pair)1 Ternary (com.cloud.legacymodel.utils.Ternary)1 VpcGatewayVO (com.cloud.network.vpc.VpcGatewayVO)1 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)1 Filter (com.cloud.utils.db.Filter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1