Search in sources :

Example 1 with PvlanSetupCommand

use of com.cloud.legacymodel.communication.command.PvlanSetupCommand in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final DhcpPvlanRules dhcp) throws ResourceUnavailableException {
    final VirtualRouter router = dhcp.getRouter();
    final PvlanSetupCommand setupCommand = dhcp.getSetupCommand();
    // In fact we send command to the host of router, we're not programming
    // router but the host
    final Commands cmds = new Commands(Command.OnError.Stop);
    cmds.addCommand(setupCommand);
    try {
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } catch (final ResourceUnavailableException e) {
        s_logger.warn("Timed Out", e);
        return false;
    }
}
Also used : Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 2 with PvlanSetupCommand

use of com.cloud.legacymodel.communication.command.PvlanSetupCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPvlanSetupCommandVm.

@Test
public void testPvlanSetupCommandVm() {
    final String op = "add";
    final URI uri = URI.create("http://localhost");
    final String networkTag = "/105";
    final String vmMac = "00:00:00:00";
    final PvlanSetupCommand command = PvlanSetupCommand.createVmSetup(op, uri, networkTag, vmMac);
    final String guestBridgeName = "br0";
    when(this.libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
    final int timeout = 0;
    when(this.libvirtComputingResource.getScriptsTimeout()).thenReturn(timeout);
    final String ovsPvlanVmPath = "/pvlan";
    when(this.libvirtComputingResource.getOvsPvlanVmPath()).thenReturn(ovsPvlanVmPath);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) URI(java.net.URI) Test(org.junit.Test)

Example 3 with PvlanSetupCommand

use of com.cloud.legacymodel.communication.command.PvlanSetupCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPvlanSetupCommandDhcpException.

@Test
public void testPvlanSetupCommandDhcpException() {
    final String op = "add";
    final URI uri = URI.create("http://localhost");
    final String networkTag = "/105";
    final String dhcpName = "dhcp";
    final String dhcpMac = "00:00:00:00";
    final String dhcpIp = "127.0.0.1";
    final PvlanSetupCommand command = PvlanSetupCommand.createDhcpSetup(op, uri, networkTag, dhcpName, dhcpMac, dhcpIp);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String guestBridgeName = "br0";
    when(this.libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
    final int timeout = 0;
    when(this.libvirtComputingResource.getScriptsTimeout()).thenReturn(timeout);
    final String ovsPvlanDhcpHostPath = "/pvlan";
    when(this.libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(dhcpName)).thenThrow(LibvirtException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(dhcpName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) URI(java.net.URI) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 4 with PvlanSetupCommand

use of com.cloud.legacymodel.communication.command.PvlanSetupCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPvlanSetupCommandDhcpDelete.

@Test
public void testPvlanSetupCommandDhcpDelete() {
    final String op = "delete";
    final URI uri = URI.create("http://localhost");
    final String networkTag = "/105";
    final String dhcpName = "dhcp";
    final String dhcpMac = "00:00:00:00";
    final String dhcpIp = "127.0.0.1";
    final PvlanSetupCommand command = PvlanSetupCommand.createDhcpSetup(op, uri, networkTag, dhcpName, dhcpMac, dhcpIp);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String guestBridgeName = "br0";
    when(this.libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
    final int timeout = 0;
    when(this.libvirtComputingResource.getScriptsTimeout()).thenReturn(timeout);
    final String ovsPvlanDhcpHostPath = "/pvlan";
    when(this.libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) URI(java.net.URI) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 5 with PvlanSetupCommand

use of com.cloud.legacymodel.communication.command.PvlanSetupCommand in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method setupVmForPvlan.

@Override
public boolean setupVmForPvlan(final boolean add, final Long hostId, final NicProfile nic) {
    if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
        return false;
    }
    String op = "add";
    if (!add) {
        op = "delete";
    }
    final Network network = _networkDao.findById(nic.getNetworkId());
    final Host host = _hostDao.findById(hostId);
    final String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
    final PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress());
    final Answer answer;
    try {
        answer = _agentMgr.send(hostId, cmd);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Timed Out", e);
        return false;
    } catch (final AgentUnavailableException e) {
        s_logger.warn("Agent Unavailable ", e);
        return false;
    }
    boolean result = true;
    if (answer == null || !answer.getResult()) {
        result = false;
    }
    return result;
}
Also used : GetVmDiskStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmDiskStatsAnswer) GetVmStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmStatsAnswer) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) StartAnswer(com.cloud.legacymodel.communication.answer.StartAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) Host(com.cloud.legacymodel.dc.Host) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand)

Aggregations

PvlanSetupCommand (com.cloud.legacymodel.communication.command.PvlanSetupCommand)10 Answer (com.cloud.legacymodel.communication.answer.Answer)9 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)8 Test (org.junit.Test)8 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)4 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)4 Connection (com.xensource.xenapi.Connection)4 Network (com.xensource.xenapi.Network)4 XenAPIException (com.xensource.xenapi.Types.XenAPIException)4 URI (java.net.URI)4 XmlRpcException (org.apache.xmlrpc.XmlRpcException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)3 LibvirtException (org.libvirt.LibvirtException)2 Commands (com.cloud.agent.manager.Commands)1 InterfaceDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef)1 GetVmDiskStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmDiskStatsAnswer)1