Search in sources :

Example 1 with NicProfileHelper

use of com.cloud.network.router.NicProfileHelper in project cosmic by MissionCriticalCloud.

the class PrivateGatewayRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    boolean result = false;
    try {
        final NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
        _network = networkModel.getNetwork(_privateGateway.getNetworkId());
        final NicProfileHelper nicProfileHelper = visitor.getVirtualNetworkApplianceFactory().getNicProfileHelper();
        final NicProfile requested = nicProfileHelper.createPrivateNicProfileForGateway(_privateGateway, _router);
        final NetworkHelper networkHelper = visitor.getVirtualNetworkApplianceFactory().getNetworkHelper();
        if (!networkHelper.checkRouterVersion(_router)) {
            s_logger.warn("Router requires upgrade. Unable to send command to router: " + _router.getId());
            return false;
        }
        final VirtualMachineManager itMgr = visitor.getVirtualNetworkApplianceFactory().getItMgr();
        _nicProfile = itMgr.addVmToNetwork(_router, _network, requested);
        // setup source nat
        if (_nicProfile != null) {
            _isAddOperation = true;
            result = visitor.visit(this);
        }
    } catch (final CloudException ex) {
        s_logger.error("Failed to create private gateway " + _privateGateway + " on router " + _router + " due to ", ex);
        result = false;
    } finally {
        if (!result) {
            s_logger.debug("Failed to setup gateway " + _privateGateway + " on router " + _router + " with the source nat. Will now remove the gateway.");
            _isAddOperation = false;
            final boolean isRemoved = destroyPrivateGateway(visitor);
            if (isRemoved) {
                s_logger.debug("Removed the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
            } else {
                s_logger.warn("Failed to remove the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
            }
        }
    }
    return result;
}
Also used : NetworkModel(com.cloud.network.NetworkModel) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) NicProfileHelper(com.cloud.network.router.NicProfileHelper) CloudException(com.cloud.exception.CloudException) NicProfile(com.cloud.vm.NicProfile) NetworkHelper(com.cloud.network.router.NetworkHelper)

Example 2 with NicProfileHelper

use of com.cloud.network.router.NicProfileHelper in project cloudstack by apache.

the class PrivateGatewayRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    boolean result = false;
    try {
        final NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
        _network = networkModel.getNetwork(_privateGateway.getNetworkId());
        final NicProfileHelper nicProfileHelper = visitor.getVirtualNetworkApplianceFactory().getNicProfileHelper();
        final NicProfile requested = nicProfileHelper.createPrivateNicProfileForGateway(_privateGateway, _router);
        final NetworkHelper networkHelper = visitor.getVirtualNetworkApplianceFactory().getNetworkHelper();
        if (!networkHelper.checkRouterVersion(_router)) {
            s_logger.warn("Router requires upgrade. Unable to send command to router: " + _router.getId());
            return false;
        }
        final VirtualMachineManager itMgr = visitor.getVirtualNetworkApplianceFactory().getItMgr();
        _nicProfile = itMgr.addVmToNetwork(_router, _network, requested);
        // setup source nat
        if (_nicProfile != null) {
            _isAddOperation = true;
            // result = setupVpcPrivateNetwork(router, true, guestNic);
            result = visitor.visit(this);
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to create private gateway " + _privateGateway + " on router " + _router + " due to ", ex);
    } finally {
        if (!result) {
            s_logger.debug("Failed to setup gateway " + _privateGateway + " on router " + _router + " with the source nat. Will now remove the gateway.");
            _isAddOperation = false;
            final boolean isRemoved = destroyPrivateGateway(visitor);
            if (isRemoved) {
                s_logger.debug("Removed the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
            } else {
                s_logger.warn("Failed to remove the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
            }
        }
    }
    return result;
}
Also used : NetworkModel(com.cloud.network.NetworkModel) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) NicProfileHelper(com.cloud.network.router.NicProfileHelper) NicProfile(com.cloud.vm.NicProfile) NetworkHelper(com.cloud.network.router.NetworkHelper) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Aggregations

NetworkModel (com.cloud.network.NetworkModel)2 NetworkHelper (com.cloud.network.router.NetworkHelper)2 NicProfileHelper (com.cloud.network.router.NicProfileHelper)2 NicProfile (com.cloud.vm.NicProfile)2 VirtualMachineManager (com.cloud.vm.VirtualMachineManager)2 CloudException (com.cloud.exception.CloudException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1