Search in sources :

Example 11 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeSshAndVersionAndNetworkUsageOnStart.

protected void finalizeSshAndVersionAndNetworkUsageOnStart(final Commands cmds, final VirtualMachineProfile profile, final DomainRouterVO router, final NicProfile controlNic) {
    final DomainRouterVO vr = _routerDao.findById(profile.getId());
    cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIPv4Address(), 3922));
    // Update router template/scripts version
    final GetDomRVersionCmd command = new GetDomRVersionCmd();
    command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlNic.getIPv4Address());
    command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    cmds.addCommand("getDomRVersion", command);
    // Network usage command to create iptables rules
    final boolean forVpc = vr.getVpcId() != null;
    if (!forVpc) {
        cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIPv4Address(), router.getHostName(), "create", forVpc));
    }
}
Also used : CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) GetDomRVersionCmd(com.cloud.agent.api.GetDomRVersionCmd) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 12 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method getRoutersForNetwork.

@Override
public List<VirtualRouter> getRoutersForNetwork(final long networkId) {
    final List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
    final List<VirtualRouter> vrs = new ArrayList<VirtualRouter>(routers.size());
    for (final DomainRouterVO router : routers) {
        vrs.add(router);
    }
    return vrs;
}
Also used : ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 13 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method removeDhcpSupportForSubnet.

@Override
public boolean removeDhcpSupportForSubnet(final Network network, final List<DomainRouterVO> routers) throws ResourceUnavailableException {
    if (routers == null || routers.isEmpty()) {
        s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
        throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + network.getId(), DataCenter.class, network.getDataCenterId());
    }
    for (final DomainRouterVO router : routers) {
        if (router.getState() != VirtualMachine.State.Running) {
            s_logger.warn("Failed to add/remove VPN users: router not in running state");
            throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
        }
        final Commands cmds = new Commands(Command.OnError.Continue);
        final List<NicIpAliasVO> revokedIpAliasVOs = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.State.revoked);
        s_logger.debug("Found" + revokedIpAliasVOs.size() + "ip Aliases to revoke on the router as a part of dhcp configuration");
        final List<IpAliasTO> revokedIpAliasTOs = new ArrayList<IpAliasTO>();
        for (final NicIpAliasVO revokedAliasVO : revokedIpAliasVOs) {
            revokedIpAliasTOs.add(new IpAliasTO(revokedAliasVO.getIp4Address(), revokedAliasVO.getNetmask(), revokedAliasVO.getAliasCount().toString()));
        }
        final List<NicIpAliasVO> aliasVOs = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.State.active);
        s_logger.debug("Found" + aliasVOs.size() + "ip Aliases to apply on the router as a part of dhcp configuration");
        final List<IpAliasTO> activeIpAliasTOs = new ArrayList<IpAliasTO>();
        for (final NicIpAliasVO aliasVO : aliasVOs) {
            activeIpAliasTOs.add(new IpAliasTO(aliasVO.getIp4Address(), aliasVO.getNetmask(), aliasVO.getAliasCount().toString()));
        }
        _commandSetupHelper.createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, network.getId(), cmds);
        _commandSetupHelper.configDnsMasq(router, network, cmds);
        final boolean result = _nwHelper.sendCommandsToRouter(router, cmds);
        if (result) {
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    for (final NicIpAliasVO revokedAliasVO : revokedIpAliasVOs) {
                        _nicIpAliasDao.expunge(revokedAliasVO.getId());
                    }
                }
            });
            return true;
        }
    }
    return false;
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands) ArrayList(java.util.ArrayList) IpAliasTO(com.cloud.agent.api.routing.IpAliasTO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) NicIpAliasVO(com.cloud.vm.dao.NicIpAliasVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 14 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method performRouterHealthChecks.

@Override
public Pair<Boolean, String> performRouterHealthChecks(long routerId) {
    DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new CloudRuntimeException("Unable to find router with id " + routerId);
    }
    if (!RouterHealthChecksEnabled.value()) {
        throw new CloudRuntimeException("Router health checks are not enabled for router: " + router);
    }
    s_logger.info("Running health check results for router " + router.getUuid());
    GetRouterMonitorResultsAnswer answer = null;
    String resultDetails = "";
    boolean success = true;
    // Step 1: Perform basic tests to check the connectivity and file system on router
    answer = performBasicTestsOnRouter(router);
    if (answer == null) {
        s_logger.debug("No results received for the basic tests on router: " + router);
        resultDetails = "Basic tests results unavailable";
        success = false;
    } else if (!answer.getResult()) {
        s_logger.debug("Basic tests failed on router: " + router);
        resultDetails = "Basic tests failed - " + answer.getMonitoringResults();
        success = false;
    } else {
        // Step 2: Update health check data on router and perform and retrieve health checks on router
        if (!updateRouterHealthChecksConfig(router)) {
            s_logger.warn("Unable to update health check config for fresh run successfully for router: " + router + ", so trying to fetch last result.");
            success = false;
            answer = fetchAndUpdateRouterHealthChecks(router, false);
        } else {
            s_logger.info("Successfully updated health check config for fresh run successfully for router: " + router);
            answer = fetchAndUpdateRouterHealthChecks(router, true);
        }
        if (answer == null) {
            resultDetails = "Failed to fetch and update health checks";
            success = false;
        } else if (!answer.getResult()) {
            resultDetails = "Get health checks failed - " + answer.getMonitoringResults();
            success = false;
        }
    }
    // Step 3: Update health checks values in database. We do this irrespective of new health check config.
    List<String> failingChecks = getFailingChecks(router, answer);
    handleFailingChecks(router, failingChecks);
    return new Pair<Boolean, String>(success, resultDetails);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO) Pair(com.cloud.utils.Pair)

Example 15 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    final NicProfile controlNic = getControlNic(profile);
    if (controlNic == null) {
        s_logger.error("Control network doesn't exist for the router " + router);
        return false;
    }
    finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, router, controlNic);
    // restart network if restartNetwork = false is not specified in profile
    // parameters
    boolean reprogramGuestNtwks = true;
    if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
        reprogramGuestNtwks = false;
    }
    final VirtualRouterProvider vrProvider = _vrProviderDao.findById(router.getElementId());
    if (vrProvider == null) {
        throw new CloudRuntimeException("Cannot find related virtual router provider of router: " + router.getHostName());
    }
    final Provider provider = Network.Provider.getProvider(vrProvider.getType().toString());
    if (provider == null) {
        throw new CloudRuntimeException("Cannot find related provider of virtual router provider: " + vrProvider.getType().toString());
    }
    final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
    for (final Long guestNetworkId : routerGuestNtwkIds) {
        final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
        cmds.addCommand(startCmd);
        if (reprogramGuestNtwks) {
            finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId, null);
            finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId);
            finalizeMonitorService(cmds, profile, router, provider, guestNetworkId, true);
        }
        finalizeUserDataAndDhcpOnStart(cmds, router, provider, guestNetworkId);
        final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
        cmds.addCommand(finishCmd);
    }
    return true;
}
Also used : VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)253 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)64 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 DataCenterVO (com.cloud.dc.DataCenterVO)36 Network (com.cloud.network.Network)34 Test (org.junit.Test)32 NicProfile (com.cloud.vm.NicProfile)29 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)28 Zone (com.cloud.db.model.Zone)27 Account (com.cloud.user.Account)27 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 Vpc (com.cloud.network.vpc.Vpc)22 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)17 HashMap (java.util.HashMap)17 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)16 NetworkVO (com.cloud.network.dao.NetworkVO)16 UserVmVO (com.cloud.vm.UserVmVO)15 Answer (com.cloud.agent.api.Answer)14