Search in sources :

Example 1 with CreateLogicalSwitchCommand

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

the class NiciraNvpResourceTest method testRetries.

@Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.legacymodel.communication.command.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 2 with CreateLogicalSwitchCommand

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

the class NiciraNvpGuestNetworkGuru method implement.

@Override
public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert network.getState() == Network.State.Implementing : "Why are we implementing " + network;
    final long zoneId = dest.getZone().getId();
    Long physicalNetworkId = network.getPhysicalNetworkId();
    // physical network id can be null in Guest Network in Basic zone, so locate the physical network
    if (physicalNetworkId == null) {
        physicalNetworkId = networkModel.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
    }
    final NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), Network.State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = network.getUuid();
    }
    if (name.length() > MAX_NAME_LENGTH) {
        name = name.substring(0, MAX_NAME_LENGTH - 1);
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
        return null;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
    final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
    final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-" + context.getAccount().getAccountName(), network.getId());
    final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("CreateLogicalSwitchCommand failed");
        return null;
    }
    try {
        implemented.setBroadcastUri(new URI("lswitch", answer.getLogicalSwitchUuid(), null));
        implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch);
        s_logger.info("Implemented OK, network linked to  = " + implemented.getBroadcastUri().toString());
    } catch (final URISyntaxException e) {
        s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
        return null;
    }
    return implemented;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CreateLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.CreateLogicalSwitchAnswer) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalSwitchCommand(com.cloud.legacymodel.communication.command.CreateLogicalSwitchCommand) URI(java.net.URI) HostVO(com.cloud.host.HostVO)

Example 3 with CreateLogicalSwitchCommand

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

the class NiciraNvpRequestWrapperTest method testCreateLogicalSwitchCommandWrapper.

@Test
public void testCreateLogicalSwitchCommandWrapper() {
    final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
    final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
    final LogicalSwitch logicalSwitch = Mockito.mock(LogicalSwitch.class);
    final String transportUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String transportType = "stt";
    final String name = "logicalswitch";
    final String ownerName = "owner";
    final CreateLogicalSwitchCommand command = new CreateLogicalSwitchCommand(transportUuid, transportType, name, ownerName, null);
    final String truncated = "lswitch-" + command.getName();
    when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
    when(niciraNvpUtilities.createLogicalSwitch()).thenReturn(logicalSwitch);
    when(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN)).thenReturn(truncated);
    when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
    try {
        when(niciraNvpApi.createLogicalSwitch(logicalSwitch)).thenReturn(logicalSwitch);
        when(logicalSwitch.getUuid()).thenReturn(transportUuid);
    } catch (final NiciraNvpApiException e) {
        fail(e.getMessage());
    }
    final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, niciraNvpResource);
    assertTrue(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.legacymodel.communication.command.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 4 with CreateLogicalSwitchCommand

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

the class NiciraNvpResourceTest method testCreateLogicalSwitch.

@Test
public void testCreateLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
    assertTrue("cccc".equals(clsa.getLogicalSwitchUuid()));
}
Also used : CreateLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) CreateLogicalSwitchCommand(com.cloud.legacymodel.communication.command.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 5 with CreateLogicalSwitchCommand

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

the class NiciraNvpResourceTest method testCreateLogicalSwitchApiException.

@Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertFalse(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.legacymodel.communication.command.CreateLogicalSwitchCommand) Test(org.junit.Test)

Aggregations

CreateLogicalSwitchCommand (com.cloud.legacymodel.communication.command.CreateLogicalSwitchCommand)5 CreateLogicalSwitchAnswer (com.cloud.legacymodel.communication.answer.CreateLogicalSwitchAnswer)4 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)4 Test (org.junit.Test)4 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)3 HostVO (com.cloud.host.HostVO)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1