Search in sources :

Example 1 with Commands

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

the class ElasticLoadBalancerManagerImpl method applyLBRules.

protected boolean applyLBRules(DomainRouterVO elbVm, List<LoadBalancingRule> rules, long guestNetworkId) throws ResourceUnavailableException {
    Commands cmds = new Commands(Command.OnError.Continue);
    createApplyLoadBalancingRulesCommands(rules, elbVm, cmds, guestNetworkId);
    // Send commands to elbVm
    return sendCommandsToRouter(elbVm, cmds);
}
Also used : Commands(com.cloud.agent.manager.Commands)

Example 2 with Commands

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

the class ElasticLoadBalancerManagerImplTest method testFinalizeStartWhenCmdsAnswerIsNull.

@Test
public void testFinalizeStartWhenCmdsAnswerIsNull() throws Exception {
    VirtualMachineProfile profileMock = mock(VirtualMachineProfile.class);
    long hostId = 1L;
    Commands cmds = mock(Commands.class);
    when(cmds.getAnswer("checkSsh")).thenReturn(null);
    ReservationContext context = mock(ReservationContext.class);
    boolean expected = false;
    boolean actual = elasticLoadBalancerManagerImpl.finalizeStart(profileMock, hostId, cmds, context);
    assertEquals(expected, actual);
}
Also used : Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 3 with Commands

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

the class VpcVirtualNetworkApplianceManagerImpl method setupVpcGuestNetwork.

protected boolean setupVpcGuestNetwork(final Network network, final VirtualRouter router, final boolean add, final NicProfile guestNic) throws ConcurrentOperationException, ResourceUnavailableException {
    boolean result = true;
    if (router.getState() == State.Running) {
        final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand((DomainRouterVO) router, add, guestNic);
        final Commands cmds = new Commands(Command.OnError.Stop);
        cmds.addCommand("setupguestnetwork", setupCmd);
        _nwHelper.sendCommandsToRouter(router, cmds);
        final Answer setupAnswer = cmds.getAnswer("setupguestnetwork");
        final String setup = add ? "set" : "destroy";
        if (!(setupAnswer != null && setupAnswer.getResult())) {
            s_logger.warn("Unable to " + setup + " guest network on router " + router);
            result = false;
        }
        return result;
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup guest network command to the backend");
        return true;
    } else {
        s_logger.warn("Unable to setup guest network on virtual router " + router + " is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to setup guest network on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand)

Example 4 with Commands

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

the class VpcVirtualNetworkApplianceManagerImpl method setupVpcPrivateNetwork.

/**
     * @param router
     * @param add
     * @param privateNic
     * @return
     * @throws ResourceUnavailableException
     */
protected boolean setupVpcPrivateNetwork(final VirtualRouter router, final boolean add, final NicProfile privateNic) throws ResourceUnavailableException {
    if (router.getState() == State.Running) {
        final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIPv4Address());
        final Network network = _networkDao.findById(privateNic.getNetworkId());
        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, privateNic.getMacAddress());
        final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
        privateIps.add(ip);
        final Commands cmds = new Commands(Command.OnError.Stop);
        _commandSetupHelper.createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add);
        try {
            if (_nwHelper.sendCommandsToRouter(router, cmds)) {
                s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc network " + network);
                return true;
            } else {
                s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network);
                return false;
            }
        } catch (final Exception ex) {
            s_logger.warn("Failed to send  " + (add ? "add " : "delete ") + " private network " + network + " commands to rotuer ");
            return false;
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup private network command to the backend");
    } else {
        s_logger.warn("Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with Commands

use of com.cloud.agent.manager.Commands 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)

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