Search in sources :

Example 41 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project CloudStack-archive by CloudStack-extras.

the class UpgradeRouterCmd method execute.

@Override
public void execute() {
    VirtualRouter router = _routerService.upgradeRouter(this);
    if (router != null) {
        DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(router);
        routerResponse.setResponseName(getCommandName());
        this.setResponseObject(routerResponse);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upgrade router");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 42 with VirtualRouter

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

the class NetworkOrchestrator method destroyExpendableRouters.

@Override
public void destroyExpendableRouters(final List<? extends VirtualRouter> routers, final ReservationContext context) throws ResourceUnavailableException {
    final List<VirtualRouter> remainingRouters = new ArrayList<>();
    for (final VirtualRouter router : routers) {
        if (router.getState() == VirtualMachine.State.Stopped || router.getState() == VirtualMachine.State.Error || router.getState() == VirtualMachine.State.Shutdown || router.getState() == VirtualMachine.State.Unknown) {
            s_logger.debug("Destroying old router " + router);
            _routerService.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId());
        } else {
            remainingRouters.add(router);
        }
    }
    if (remainingRouters.size() < 2) {
        return;
    }
    VirtualRouter backupRouter = null;
    for (final VirtualRouter router : remainingRouters) {
        if (router.getRedundantState() == VirtualRouter.RedundantState.BACKUP) {
            backupRouter = router;
        }
    }
    if (backupRouter == null) {
        backupRouter = routers.get(routers.size() - 1);
    }
    if (backupRouter != null) {
        _routerService.destroyRouter(backupRouter.getId(), context.getAccount(), context.getCaller().getId());
    }
}
Also used : ArrayList(java.util.ArrayList) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 43 with VirtualRouter

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

the class UserVmDomRInvestigator method isVmAlive.

@Override
public boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM {
    if (vm.getType() != VirtualMachine.Type.User) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Not a User Vm, unable to determine state of " + vm + " returning null");
        }
        throw new UnknownVM();
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("testing if " + vm + " is alive");
    }
    // to verify that the VM is alive, we ask the domR (router) to ping the VM (private IP)
    UserVmVO userVm = _userVmDao.findById(vm.getId());
    List<? extends Nic> nics = _networkMgr.getNicsForTraffic(userVm.getId(), TrafficType.Guest);
    for (Nic nic : nics) {
        if (nic.getIPv4Address() == null) {
            continue;
        }
        List<VirtualRouter> routers = _vnaMgr.getRoutersForNetwork(nic.getNetworkId());
        if (routers == null || routers.isEmpty()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unable to find a router in network " + nic.getNetworkId() + " to ping " + vm);
            }
            continue;
        }
        Boolean result = null;
        for (VirtualRouter router : routers) {
            result = testUserVM(vm, nic, router);
            if (result != null) {
                break;
            }
        }
        if (result == null) {
            continue;
        }
        return result;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Returning null since we're unable to determine state of " + vm);
    }
    throw new UnknownVM();
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Nic(com.cloud.vm.Nic) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 44 with VirtualRouter

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

the class BasicNetworkVisitor method visit.

@SuppressWarnings("unchecked")
@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
    final Network network = firewall.getNetwork();
    final VirtualRouter router = firewall.getRouter();
    final List<? extends FirewallRule> rules = firewall.getRules();
    final List<LoadBalancingRule> loadbalancingRules = firewall.getLoadbalancingRules();
    final Purpose purpose = firewall.getPurpose();
    final Commands cmds = new Commands(Command.OnError.Continue);
    if (purpose == Purpose.LoadBalancing) {
        _commandSetupHelper.createApplyLoadBalancingRulesCommands(loadbalancingRules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.PortForwarding) {
        _commandSetupHelper.createApplyPortForwardingRulesCommands((List<? extends PortForwardingRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.StaticNat) {
        _commandSetupHelper.createApplyStaticNatRulesCommands((List<StaticNatRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.Firewall) {
        _commandSetupHelper.createApplyFirewallRulesCommands(rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    }
    s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
    return false;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) Purpose(com.cloud.network.rules.FirewallRule.Purpose) List(java.util.List) ArrayList(java.util.ArrayList) StaticNatRule(com.cloud.network.rules.StaticNatRule) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 45 with VirtualRouter

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

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final SshKeyToRouterRules sshkey) throws ResourceUnavailableException {
    final VirtualRouter router = sshkey.getRouter();
    final VirtualMachineProfile profile = sshkey.getProfile();
    final String sshKeystr = sshkey.getSshPublicKey();
    final UserVmVO userVM = sshkey.getUserVM();
    final Commands commands = new Commands(Command.OnError.Stop);
    final NicVO nicVo = sshkey.getNicVo();
    final VMTemplateVO template = sshkey.getTemplate();
    if (template != null && template.isEnablePassword()) {
        _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
    }
    _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, sshKeystr, commands);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Commands(com.cloud.agent.manager.Commands) VMTemplateVO(com.cloud.storage.VMTemplateVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

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