Search in sources :

Example 1 with OvsFetchInterfaceCommand

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

the class LibvirtComputingResourceTest method testOvsFetchInterfaceCommand.

@Test
public void testOvsFetchInterfaceCommand() {
    final String label = "eth0";
    final OvsFetchInterfaceCommand command = new OvsFetchInterfaceCommand(label);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) 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) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with OvsFetchInterfaceCommand

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

the class NotAValidCommand method testOvsFetchInterfaceCommand.

@Test
public void testOvsFetchInterfaceCommand() {
    final String label = "[abc]";
    final String uuid = "befc4dcd-f5c6-4015-8791-3c18622b7c7f";
    final Connection conn = Mockito.mock(Connection.class);
    final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
    final Network network2 = Mockito.mock(Network.class);
    final PIF pif = Mockito.mock(PIF.class);
    final PIF.Record pifRec = Mockito.mock(PIF.Record.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final OvsFetchInterfaceCommand fetchInterCommand = new OvsFetchInterfaceCommand(label);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.isXcp()).thenReturn(true);
    when(citrixResourceBase.getLabel()).thenReturn("[abc]");
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.getHost()).thenReturn(xsHost);
    try {
        when(network.getNetwork()).thenReturn(network2);
        when(network.getPif(conn)).thenReturn(pif);
        when(network.getPif(conn)).thenReturn(pif);
        when(pif.getRecord(conn)).thenReturn(pifRec);
        when(network.getNetwork().getUuid(conn)).thenReturn(uuid);
        when(citrixResourceBase.getNetworkByName(conn, label)).thenReturn(network);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(fetchInterCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PIF(com.xensource.xenapi.PIF) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with OvsFetchInterfaceCommand

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

the class OvsTunnelManagerImpl method getGreEndpointIP.

private String getGreEndpointIP(Host host, Network nw) throws AgentUnavailableException, OperationTimedoutException {
    String endpointIp = null;
    // Fetch fefault name for network label from configuration
    String physNetLabel = _configDao.getValue(Config.OvsTunnelNetworkDefaultLabel.key());
    Long physNetId = nw.getPhysicalNetworkId();
    PhysicalNetworkTrafficType physNetTT = _physNetTTDao.findBy(physNetId, TrafficType.Guest);
    HypervisorType hvType = host.getHypervisorType();
    String label = null;
    switch(hvType) {
        case XenServer:
            label = physNetTT.getXenNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        case KVM:
            label = physNetTT.getKvmNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        default:
            throw new CloudRuntimeException("Hypervisor " + hvType.toString() + " unsupported by OVS Tunnel Manager");
    }
    // Try to fetch GRE endpoint IP address for cloud db
    // If not found, then find it on the hypervisor
    OvsTunnelInterfaceVO tunnelIface = _tunnelInterfaceDao.getByHostAndLabel(host.getId(), physNetLabel);
    if (tunnelIface == null) {
        // Now find and fetch configuration for physical interface
        // for network with label on target host
        Commands fetchIfaceCmds = new Commands(new OvsFetchInterfaceCommand(physNetLabel));
        s_logger.debug("Ask host " + host.getId() + " to retrieve interface for phy net with label:" + physNetLabel);
        Answer[] fetchIfaceAnswers = _agentMgr.send(host.getId(), fetchIfaceCmds);
        // And finally save it for future use
        endpointIp = handleFetchInterfaceAnswer(fetchIfaceAnswers, host.getId());
    } else {
        endpointIp = tunnelIface.getIp();
    }
    return endpointIp;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) OvsTunnelInterfaceVO(com.cloud.network.ovs.dao.OvsTunnelInterfaceVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Commands(com.cloud.agent.manager.Commands) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Aggregations

Answer (com.cloud.agent.api.Answer)3 OvsFetchInterfaceCommand (com.cloud.agent.api.OvsFetchInterfaceCommand)3 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)1 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1 Commands (com.cloud.agent.manager.Commands)1 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)1 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)1 PhysicalNetworkTrafficType (com.cloud.network.PhysicalNetworkTrafficType)1 OvsTunnelInterfaceVO (com.cloud.network.ovs.dao.OvsTunnelInterfaceVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Connection (com.xensource.xenapi.Connection)1