Search in sources :

Example 11 with VirtualRouter

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

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final DhcpPvlanRules dhcp) throws ResourceUnavailableException {
    final VirtualRouter router = dhcp.getRouter();
    final PvlanSetupCommand setupCommand = dhcp.getSetupCommand();
    // In fact we send command to the host of router, we're not programming
    // router but the host
    final Commands cmds = new Commands(Command.OnError.Stop);
    cmds.addCommand(setupCommand);
    try {
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } catch (final ResourceUnavailableException e) {
        s_logger.warn("Timed Out", e);
        return false;
    }
}
Also used : Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 12 with VirtualRouter

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

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final VpcIpAssociationRules vpcip) throws ResourceUnavailableException {
    final VirtualRouter router = vpcip.getRouter();
    final Commands cmds = new Commands(Command.OnError.Continue);
    final List<PublicIpAddress> ipsToSend = vpcip.getIpsToSend();
    if (!ipsToSend.isEmpty()) {
        final List<Ip> ipsToExclude = new ArrayList<>();
        _commandSetupHelper.findIpsToExclude(ipsToSend, ipsToExclude);
        final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), ipsToExclude, new ArrayList<>(), null, null);
        final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
        updateNetworkOverviewCommand.setPlugNics(true);
        cmds.addCommand(updateNetworkOverviewCommand);
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else {
        return true;
    }
}
Also used : PublicIpAddress(com.cloud.network.PublicIpAddress) Ip(com.cloud.utils.net.Ip) Commands(com.cloud.agent.manager.Commands) ArrayList(java.util.ArrayList) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) UpdateNetworkOverviewCommand(com.cloud.agent.api.UpdateNetworkOverviewCommand) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 13 with VirtualRouter

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

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final StaticRoutesRules staticRoutesRules) throws ResourceUnavailableException {
    final VirtualRouter router = staticRoutesRules.getRouter();
    final Commands cmds = new Commands(Command.OnError.Continue);
    final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null);
    final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
    cmds.addCommand(updateNetworkOverviewCommand);
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) UpdateNetworkOverviewCommand(com.cloud.agent.api.UpdateNetworkOverviewCommand) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 14 with VirtualRouter

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

the class BasicNetworkTopology method applyRules.

@Override
public boolean applyRules(final Network network, final VirtualRouter router, final String typeString, final boolean isPodLevelException, final Long podId, final boolean failWhenDisconnect, final RuleApplierWrapper<RuleApplier> ruleApplierWrapper) throws ResourceUnavailableException {
    if (router == null) {
        s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
        throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
    }
    final RuleApplier ruleApplier = ruleApplierWrapper.getRuleType();
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
    // isPodLevelException and podId is only used for basic zone
    assert !(!isZoneBasic && isPodLevelException || isZoneBasic && isPodLevelException && podId == null);
    final List<VirtualRouter> connectedRouters = new ArrayList<>();
    final List<VirtualRouter> disconnectedRouters = new ArrayList<>();
    boolean result = true;
    final String msg = "Unable to apply " + typeString + " on disconnected router ";
    if (router.getState() == State.Running) {
        s_logger.debug("Applying " + typeString + " in network " + network);
        if (router.isStopPending()) {
            if (_hostDao.findById(router.getHostId()).getState() == Status.Up) {
                throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
            }
            s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
            return false;
        }
        try {
            result = ruleApplier.accept(getVisitor(), router);
            connectedRouters.add(router);
        } catch (final AgentUnavailableException e) {
            s_logger.warn(msg + router.getInstanceName(), e);
            disconnectedRouters.add(router);
        }
        // disconnection, no need to proceed with the rest
        if (!result) {
            if (isZoneBasic && isPodLevelException) {
                throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId);
            }
            throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterId());
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend");
    } else {
        s_logger.warn("Unable to apply " + typeString + ", virtual router is not in the right state " + router.getState());
        if (isZoneBasic && isPodLevelException) {
            throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
        }
        throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    if (!connectedRouters.isEmpty()) {
        // Shouldn't we include this check inside the method?
        if (!isZoneBasic && !disconnectedRouters.isEmpty()) {
            // now, stop them for synchronization
            for (final VirtualRouter virtualRouter : disconnectedRouters) {
                // If we have at least 1 disconnected redundant router, callhandleSingleWorkingRedundantRouter().
                if (virtualRouter.getIsRedundantRouter()) {
                    _networkHelper.handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
                    break;
                }
            }
        }
    } else if (!disconnectedRouters.isEmpty()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
        }
        if (isZoneBasic && isPodLevelException) {
            throw new ResourceUnavailableException(msg, Pod.class, podId);
        }
        throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
    }
    result = true;
    if (failWhenDisconnect) {
        result = !connectedRouters.isEmpty();
    }
    return result;
}
Also used : DataCenter(com.cloud.dc.DataCenter) Pod(com.cloud.dc.Pod) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) RuleApplier(com.cloud.network.rules.RuleApplier) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ArrayList(java.util.ArrayList) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 15 with VirtualRouter

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

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException {
    final VirtualRouter router = userdata.getRouter();
    final Commands commands = new Commands(Command.OnError.Stop);
    final VirtualMachineProfile profile = userdata.getProfile();
    final NicVO nicVO = userdata.getNicVo();
    final DeployDestination destination = userdata.getDestination();
    if (router.getPodIdToDeployIn() == destination.getPod().getId()) {
        _commandSetupHelper.createPasswordCommand(router, profile, nicVO, commands);
        final VMOverviewTO vmOverview = _commandSetupHelper.createVmOverviewFromRouter(router);
        final UpdateVmOverviewCommand updateVmOverviewCommand = _commandSetupHelper.createUpdateVmOverviewCommand(router, vmOverview);
        commands.addCommand(updateVmOverviewCommand);
        return _networkGeneralHelper.sendCommandsToRouter(router, commands);
    }
    return true;
}
Also used : DeployDestination(com.cloud.deploy.DeployDestination) VMOverviewTO(com.cloud.agent.api.to.overviews.VMOverviewTO) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter) UpdateVmOverviewCommand(com.cloud.agent.api.UpdateVmOverviewCommand)

Aggregations

VirtualRouter (com.cloud.network.router.VirtualRouter)72 Commands (com.cloud.agent.manager.Commands)34 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)11 NicVO (com.cloud.vm.NicVO)11 ServerApiException (com.cloud.api.ServerApiException)10 UserVmVO (com.cloud.vm.UserVmVO)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 ArrayList (java.util.ArrayList)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 DataCenter (com.cloud.dc.DataCenter)8 Network (com.cloud.network.Network)8 DomainRouterResponse (org.apache.cloudstack.api.response.DomainRouterResponse)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 UpdateVmOverviewCommand (com.cloud.agent.api.UpdateVmOverviewCommand)5 VMOverviewTO (com.cloud.agent.api.to.overviews.VMOverviewTO)5 UpdateNetworkOverviewCommand (com.cloud.agent.api.UpdateNetworkOverviewCommand)4 NetworkOverviewTO (com.cloud.agent.api.to.overviews.NetworkOverviewTO)4 DeployDestination (com.cloud.deploy.DeployDestination)4 PvlanSetupCommand (com.cloud.agent.api.PvlanSetupCommand)2