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;
}
}
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());
}
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());
}
}
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());
}
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;
}
Aggregations