Search in sources :

Example 1 with VpcProvider

use of com.cloud.network.element.VpcProvider in project cloudstack by apache.

the class VpcManagerImpl method startVpc.

protected boolean startVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // deploy provider
    boolean success = true;
    final List<Provider> providersToImplement = getVpcProviders(vpc.getId());
    for (final VpcProvider element : getVpcElements()) {
        if (providersToImplement.contains(element.getProvider())) {
            if (element.implementVpc(vpc, dest, context)) {
                s_logger.debug("Vpc " + vpc + " has started succesfully");
            } else {
                s_logger.warn("Vpc " + vpc + " failed to start");
                success = false;
            }
        }
    }
    return success;
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider)

Example 2 with VpcProvider

use of com.cloud.network.element.VpcProvider in project cloudstack by apache.

the class VpcManagerImpl method applyStaticRoutes.

protected boolean applyStaticRoutes(final List<StaticRouteProfile> routes) throws ResourceUnavailableException {
    if (routes.isEmpty()) {
        s_logger.debug("No static routes to apply");
        return true;
    }
    final Vpc vpc = _vpcDao.findById(routes.get(0).getVpcId());
    s_logger.debug("Applying static routes for vpc " + vpc);
    final String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat);
    for (final VpcProvider provider : getVpcElements()) {
        if (!(provider instanceof StaticNatServiceProvider && provider.getName().equalsIgnoreCase(staticNatProvider))) {
            continue;
        }
        if (provider.applyStaticRoutes(vpc, routes)) {
            s_logger.debug("Applied static routes for vpc " + vpc);
        } else {
            s_logger.warn("Failed to apply static routes for vpc " + vpc);
            return false;
        }
    }
    return true;
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider)

Example 3 with VpcProvider

use of com.cloud.network.element.VpcProvider in project cloudstack by apache.

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 {
        // do cleanup
        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) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) ActionEvent(com.cloud.event.ActionEvent)

Example 4 with VpcProvider

use of com.cloud.network.element.VpcProvider in project cloudstack by apache.

the class VpcManagerImpl method deleteVpcPrivateGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_DELETE, eventDescription = "deleting private gateway")
@DB
public boolean deleteVpcPrivateGateway(final long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
    final VpcGatewayVO gatewayVO = _vpcGatewayDao.acquireInLockTable(gatewayId);
    if (gatewayVO == null || gatewayVO.getType() != VpcGateway.Type.Private) {
        throw new ConcurrentOperationException("Unable to lock gateway " + gatewayId);
    }
    try {
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) {
                // don't allow to remove gateway when there are static
                // routes associated with it
                final long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId());
                if (routeCount > 0) {
                    throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount + " static routes applied. Remove the routes first");
                }
                gatewayVO.setState(VpcGateway.State.Deleting);
                _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
                s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
            }
        });
        // 1) delete the gateway on the backend
        final List<Provider> providersToImplement = getVpcProviders(gatewayVO.getVpcId());
        final PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
        for (final VpcProvider provider : getVpcElements()) {
            if (providersToImplement.contains(provider.getProvider())) {
                if (provider.deletePrivateGateway(gateway)) {
                    s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
                } else {
                    s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
                    gatewayVO.setState(VpcGateway.State.Ready);
                    _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
                    s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Ready);
                    return false;
                }
            }
        }
        // 2) Delete private gateway from the DB
        return deletePrivateGatewayFromTheDB(gateway);
    } finally {
        if (gatewayVO != null) {
            _vpcGatewayDao.releaseFromLockTable(gatewayId);
        }
    }
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 5 with VpcProvider

use of com.cloud.network.element.VpcProvider in project cloudstack by apache.

the class VpcManagerImpl method shutdownVpc.

@Override
public boolean shutdownVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    // check if vpc exists
    final Vpc vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId);
    }
    // permission check
    _accountMgr.checkAccess(caller, null, false, vpc);
    // shutdown provider
    s_logger.debug("Shutting down vpc " + vpc);
    // TODO - shutdown all vpc resources here (ACLs, gateways, etc)
    boolean success = true;
    final List<Provider> providersToImplement = getVpcProviders(vpc.getId());
    final ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller);
    for (final VpcProvider element : getVpcElements()) {
        if (providersToImplement.contains(element.getProvider())) {
            if (element.shutdownVpc(vpc, context)) {
                s_logger.debug("Vpc " + vpc + " has been shutdown succesfully");
            } else {
                s_logger.warn("Vpc " + vpc + " failed to shutdown");
                success = false;
            }
        }
    }
    return success;
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CallContext(org.apache.cloudstack.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) ReservationContext(com.cloud.vm.ReservationContext)

Aggregations

VpcProvider (com.cloud.network.element.VpcProvider)6 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)5 Provider (com.cloud.network.Network.Provider)4 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Account (com.cloud.user.Account)1 DB (com.cloud.utils.db.DB)1 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 ReservationContext (com.cloud.vm.ReservationContext)1 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)1 CallContext (org.apache.cloudstack.context.CallContext)1