Search in sources :

Example 11 with PrivateGateway

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

the class VpcManagerImpl method applyVpcPrivateGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_CREATE, eventDescription = "Applying VPC private gateway", async = true)
public PrivateGateway applyVpcPrivateGateway(final long gatewayId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException {
    final VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId);
    boolean success = true;
    try {
        final List<Provider> providersToImplement = getVpcProviders(vo.getVpcId());
        final PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
        for (final VpcProvider provider : getVpcElements()) {
            if (providersToImplement.contains(provider.getProvider())) {
                if (!provider.createPrivateGateway(gateway)) {
                    success = false;
                }
            }
        }
        if (success) {
            s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
            if (vo.getState() != VpcGateway.State.Ready) {
                vo.setState(VpcGateway.State.Ready);
                _vpcGatewayDao.update(vo.getId(), vo);
                s_logger.debug("Marke gateway " + gateway + " with state " + VpcGateway.State.Ready);
            }
            CallContext.current().setEventDetails("Private Gateway Id: " + gatewayId);
            return getVpcPrivateGateway(gatewayId);
        } else {
            s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
            return null;
        }
    } finally {
        if (!success) {
            if (destroyOnFailure) {
                s_logger.debug("Destroying private gateway " + vo + " that failed to start");
                // fail, destroyPrivateGateway is already called
                if (deletePrivateGatewayFromTheDB(getVpcPrivateGateway(gatewayId))) {
                    s_logger.warn("Successfully destroyed vpc " + vo + " that failed to start");
                } else {
                    s_logger.warn("Failed to destroy vpc " + vo + " that failed to start");
                }
            }
        }
    }
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) PrivateGateway(com.cloud.legacymodel.network.vpc.PrivateGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 12 with PrivateGateway

use of com.cloud.legacymodel.network.vpc.PrivateGateway 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

PrivateGateway (com.cloud.legacymodel.network.vpc.PrivateGateway)12 ArrayList (java.util.ArrayList)6 List (java.util.List)5 NetworkVO (com.cloud.network.dao.NetworkVO)4 ServerApiException (com.cloud.api.ServerApiException)3 ActionEvent (com.cloud.event.ActionEvent)3 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 Network (com.cloud.legacymodel.network.Network)3 Account (com.cloud.legacymodel.user.Account)3 IPAddressVO (com.cloud.network.dao.IPAddressVO)3 LinkedList (java.util.LinkedList)3 PrivateGatewayResponse (com.cloud.api.response.PrivateGatewayResponse)2 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)2 Provider (com.cloud.legacymodel.network.Network.Provider)2 Vpc (com.cloud.legacymodel.network.vpc.Vpc)2 VpcGateway (com.cloud.legacymodel.network.vpc.VpcGateway)2 VpcProvider (com.cloud.network.element.VpcProvider)2 DB (com.cloud.utils.db.DB)2 Filter (com.cloud.utils.db.Filter)2