Search in sources :

Example 6 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.

@Override
public boolean startRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, final List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
    if (routers == null || routers.isEmpty()) {
        s_logger.warn("Failed to start remote access VPN: no router found for account and zone");
        throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", DataCenter.class, network.getDataCenterId());
    }
    for (final VirtualRouter router : routers) {
        if (router.getState() != VirtualMachine.State.Running) {
            s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
            throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
        }
        final Commands cmds = new Commands(Command.OnError.Stop);
        _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
        if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
            throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId());
        }
        Answer answer = cmds.getAnswer("users");
        if (!answer.getResult()) {
            s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
            throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
        }
        answer = cmds.getAnswer("startVpn");
        if (!answer.getResult()) {
            s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
            throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
        }
    }
    return true;
}
Also used : NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 7 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method deleteRemoteAccessVpn.

@Override
public boolean deleteRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, final List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
    if (routers == null || routers.isEmpty()) {
        s_logger.warn("Failed to delete remote access VPN: no router found for account and zone");
        throw new ResourceUnavailableException("Failed to delete remote access VPN", DataCenter.class, network.getDataCenterId());
    }
    boolean result = true;
    for (final VirtualRouter router : routers) {
        if (router.getState() == VirtualMachine.State.Running) {
            final Commands cmds = new Commands(Command.OnError.Continue);
            _commandSetupHelper.createApplyVpnCommands(false, vpn, router, cmds);
            result = result && _nwHelper.sendCommandsToRouter(router, cmds);
        } else if (router.getState() == VirtualMachine.State.Stopped) {
            s_logger.debug("Router " + router + " is in Stopped state, not sending deleteRemoteAccessVpn command to it");
            continue;
        } else {
            s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState());
            throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
        }
    }
    return result;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 8 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method stopRemoteAccessVpn.

@Override
public boolean stopRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException {
    boolean result = true;
    if (router.getState() == State.Running) {
        final Commands cmds = new Commands(Command.OnError.Continue);
        _commandSetupHelper.createApplyVpnCommands(false, vpn, router, cmds);
        result = result && _nwHelper.sendCommandsToRouter(router, cmds);
    } else if (router.getState() == State.Stopped) {
        s_logger.debug("Router " + router + " is in Stopped state, not sending deleteRemoteAccessVpn command to it");
    } else {
        s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState());
        throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 9 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.

@Override
public boolean startRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException {
    if (router.getState() != State.Running) {
        s_logger.warn("Unable to apply remote access VPN configuration, virtual router is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to apply remote access VPN configuration," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    final Commands cmds = new Commands(Command.OnError.Stop);
    _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
    try {
        _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.debug("Failed to start remote access VPN: ", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e);
    }
    Answer answer = cmds.getAnswer("users");
    if (!answer.getResult()) {
        s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
        throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
    }
    answer = cmds.getAnswer("startVpn");
    if (!answer.getResult()) {
        s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
        throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 10 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method applySite2SiteVpn.

protected boolean applySite2SiteVpn(final boolean isCreate, final VirtualRouter router, final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
    final Commands cmds = new Commands(Command.OnError.Continue);
    _commandSetupHelper.createSite2SiteVpnCfgCommands(conn, isCreate, router, cmds);
    return _nwHelper.sendCommandsToRouter(router, cmds);
}
Also used : Commands(com.cloud.agent.manager.Commands)

Aggregations

Commands (com.cloud.agent.manager.Commands)64 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)22 VirtualRouter (com.cloud.network.router.VirtualRouter)19 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 Answer (com.cloud.agent.api.Answer)16 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)13 Network (com.cloud.network.Network)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 NicVO (com.cloud.vm.NicVO)10 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)9 ArrayList (java.util.ArrayList)9 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)8 UserVmVO (com.cloud.vm.UserVmVO)8 DataCenter (com.cloud.dc.DataCenter)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)7 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)6 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)6 StartAnswer (com.cloud.agent.api.StartAnswer)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6