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;
}
}
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());
}
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);
}
Aggregations