Search in sources :

Example 1 with OvsSetupBridgeCommand

use of com.cloud.agent.api.OvsSetupBridgeCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testOvsSetupBridgeCommand.

@Test
public void testOvsSetupBridgeCommand() {
    final String name = "Test";
    final Long hostId = 1l;
    final Long networkId = 1l;
    final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
    when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
    when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
    verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) Test(org.junit.Test)

Example 2 with OvsSetupBridgeCommand

use of com.cloud.agent.api.OvsSetupBridgeCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testOvsSetupBridgeCommandFailure2.

@Test
public void testOvsSetupBridgeCommandFailure2() {
    final String name = "Test";
    final Long hostId = 1l;
    final Long networkId = 1l;
    final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
    when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
    when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
    verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) Test(org.junit.Test)

Example 3 with OvsSetupBridgeCommand

use of com.cloud.agent.api.OvsSetupBridgeCommand in project cloudstack by apache.

the class OvsTunnelManagerImpl method checkAndCreateTunnel.

@DB
protected void checkAndCreateTunnel(Network nw, Host host) {
    s_logger.debug("Creating tunnels with OVS tunnel manager");
    long hostId = host.getId();
    int key = getGreKey(nw);
    String bridgeName = generateBridgeName(nw, key);
    List<Long> toHostIds = new ArrayList<Long>();
    List<Long> fromHostIds = new ArrayList<Long>();
    List<Long> networkSpannedHosts = _ovsNetworkToplogyGuru.getNetworkSpanedHosts(nw.getId());
    for (Long rh : networkSpannedHosts) {
        if (rh == hostId) {
            continue;
        }
        OvsTunnelNetworkVO ta = _tunnelNetworkDao.getByFromToNetwork(hostId, rh.longValue(), nw.getId());
        // Try and create the tunnel even if a previous attempt failed
        if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
            s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
            if (ta == null) {
                createTunnelRecord(hostId, rh.longValue(), nw.getId(), key);
            }
            if (!toHostIds.contains(rh)) {
                toHostIds.add(rh);
            }
        }
        ta = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(), hostId, nw.getId());
        // Try and create the tunnel even if a previous attempt failed
        if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
            s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
            if (ta == null) {
                createTunnelRecord(rh.longValue(), hostId, nw.getId(), key);
            }
            if (!fromHostIds.contains(rh)) {
                fromHostIds.add(rh);
            }
        }
    }
    //TODO: Should we propagate the exception here?
    try {
        String myIp = getGreEndpointIP(host, nw);
        if (myIp == null)
            throw new GreTunnelException("Unable to retrieve the source " + "endpoint for the GRE tunnel." + "Failure is on host:" + host.getId());
        boolean noHost = true;
        for (Long i : toHostIds) {
            HostVO rHost = _hostDao.findById(i);
            String otherIp = getGreEndpointIP(rHost, nw);
            if (otherIp == null)
                throw new GreTunnelException("Unable to retrieve the remote " + "endpoint for the GRE tunnel." + "Failure is on host:" + rHost.getId());
            Commands cmds = new Commands(new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, nw.getId(), myIp, bridgeName, nw.getUuid()));
            s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + nw.getId());
            s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleCreateTunnelAnswer(answers);
            noHost = false;
        }
        for (Long i : fromHostIds) {
            HostVO rHost = _hostDao.findById(i);
            String otherIp = getGreEndpointIP(rHost, nw);
            Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), nw.getId(), otherIp, bridgeName, nw.getUuid()));
            s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
            Answer[] answers = _agentMgr.send(i, cmds);
            handleCreateTunnelAnswer(answers);
            noHost = false;
        }
        // anyway. This will ensure VIF rules will be triggered
        if (noHost) {
            Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, nw.getId()));
            s_logger.debug("Ask host " + hostId + " to configure bridge for network:" + nw.getId());
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleSetupBridgeAnswer(answers);
        }
    } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) {
        // I really thing we should do a better handling of these exceptions
        s_logger.warn("Ovs Tunnel network created tunnel failed", e);
    }
}
Also used : OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) DB(com.cloud.utils.db.DB)

Example 4 with OvsSetupBridgeCommand

use of com.cloud.agent.api.OvsSetupBridgeCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testOvsSetupBridgeCommandFailure1.

@Test
public void testOvsSetupBridgeCommandFailure1() {
    final String name = "Test";
    final Long hostId = 1l;
    final Long networkId = 1l;
    final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
    when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
    when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName())).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
    verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) Test(org.junit.Test)

Example 5 with OvsSetupBridgeCommand

use of com.cloud.agent.api.OvsSetupBridgeCommand in project cloudstack by apache.

the class OvsTunnelManagerImpl method checkAndCreateVpcTunnelNetworks.

@DB
protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) {
    long hostId = host.getId();
    String bridgeName = generateBridgeNameForVpc(vpcId);
    List<Long> vmIds = _ovsNetworkToplogyGuru.getActiveVmsInVpcOnHost(vpcId, hostId);
    if (vmIds == null || vmIds.isEmpty()) {
        // since this is the first VM from the VPC being launched on the host, first setup the bridge
        try {
            Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, null));
            s_logger.debug("Ask host " + hostId + " to create bridge for vpc " + vpcId + " and configure the " + " bridge for distributed routing.");
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleSetupBridgeAnswer(answers);
        } catch (OperationTimedoutException | AgentUnavailableException e) {
            s_logger.warn("Ovs Tunnel network created tunnel failed", e);
        }
        // now that bridge is setup, populate network acl's before the VM gets created
        OvsVpcRoutingPolicyConfigCommand cmd = prepareVpcRoutingPolicyUpdate(vpcId);
        cmd.setSequenceNumber(getNextRoutingPolicyUpdateSequenceNumber(vpcId));
        if (!sendVpcRoutingPolicyChangeUpdate(cmd, hostId, bridgeName)) {
            s_logger.debug("Failed to send VPC routing policy change update to host : " + hostId + ". But moving on with sending the updates to the rest of the hosts.");
        }
    }
    List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
    List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
    for (Network vpcNetwork : vpcNetworks) {
        if (vpcNetwork.getState() != Network.State.Implemented && vpcNetwork.getState() != Network.State.Implementing && vpcNetwork.getState() != Network.State.Setup)
            continue;
        int key = getGreKey(vpcNetwork);
        List<Long> toHostIds = new ArrayList<Long>();
        List<Long> fromHostIds = new ArrayList<Long>();
        OvsTunnelNetworkVO tunnelRecord = null;
        for (Long rh : vpcSpannedHostIds) {
            if (rh == hostId) {
                continue;
            }
            tunnelRecord = _tunnelNetworkDao.getByFromToNetwork(hostId, rh.longValue(), vpcNetwork.getId());
            // Try and create the tunnel if does not exit or previous attempt failed
            if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) {
                s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
                if (tunnelRecord == null) {
                    createTunnelRecord(hostId, rh.longValue(), vpcNetwork.getId(), key);
                }
                if (!toHostIds.contains(rh)) {
                    toHostIds.add(rh);
                }
            }
            tunnelRecord = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(), hostId, vpcNetwork.getId());
            // Try and create the tunnel if does not exit or previous attempt failed
            if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) {
                s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
                if (tunnelRecord == null) {
                    createTunnelRecord(rh.longValue(), hostId, vpcNetwork.getId(), key);
                }
                if (!fromHostIds.contains(rh)) {
                    fromHostIds.add(rh);
                }
            }
        }
        try {
            String myIp = getGreEndpointIP(host, vpcNetwork);
            if (myIp == null)
                throw new GreTunnelException("Unable to retrieve the source " + "endpoint for the GRE tunnel." + "Failure is on host:" + host.getId());
            boolean noHost = true;
            for (Long i : toHostIds) {
                HostVO rHost = _hostDao.findById(i);
                String otherIp = getGreEndpointIP(rHost, vpcNetwork);
                if (otherIp == null)
                    throw new GreTunnelException("Unable to retrieve the remote endpoint for the GRE tunnel." + "Failure is on host:" + rHost.getId());
                Commands cmds = new Commands(new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, vpcNetwork.getId(), myIp, bridgeName, vpcNetwork.getUuid()));
                s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + vpcNetwork.getId());
                s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
                Answer[] answers = _agentMgr.send(hostId, cmds);
                handleCreateTunnelAnswer(answers);
            }
            for (Long i : fromHostIds) {
                HostVO rHost = _hostDao.findById(i);
                String otherIp = getGreEndpointIP(rHost, vpcNetwork);
                Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), vpcNetwork.getId(), otherIp, bridgeName, vpcNetwork.getUuid()));
                s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
                Answer[] answers = _agentMgr.send(i, cmds);
                handleCreateTunnelAnswer(answers);
            }
        } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) {
            // I really thing we should do a better handling of these exceptions
            s_logger.warn("Ovs Tunnel network created tunnel failed", e);
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) ArrayList(java.util.ArrayList) OvsVpcRoutingPolicyConfigCommand(com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand) HostVO(com.cloud.host.HostVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) DB(com.cloud.utils.db.DB)

Aggregations

Answer (com.cloud.agent.api.Answer)6 OvsSetupBridgeCommand (com.cloud.agent.api.OvsSetupBridgeCommand)6 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)4 Test (org.junit.Test)4 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)3 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)3 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)2 OvsCreateTunnelCommand (com.cloud.agent.api.OvsCreateTunnelCommand)2 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)2 Commands (com.cloud.agent.manager.Commands)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 HostVO (com.cloud.host.HostVO)2 OvsTunnelNetworkVO (com.cloud.network.ovs.dao.OvsTunnelNetworkVO)2 DB (com.cloud.utils.db.DB)2 ArrayList (java.util.ArrayList)2 OvsVpcRoutingPolicyConfigCommand (com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1 Network (com.cloud.network.Network)1