Search in sources :

Example 16 with LogicalSwitchPort

use of com.cloud.network.nicira.LogicalSwitchPort in project cloudstack by apache.

the class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper method execute.

@Override
public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String l2GatewayServiceUuid = command.getL2GatewayServiceUuid();
    long vlanId = command.getVlanId();
    final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
    tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
    final long networkId = command.getNetworkId();
    s_logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId);
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid);
    LogicalSwitchPort lSwitchPort = null;
    try {
        lSwitchPort = new LogicalSwitchPort();
        lSwitchPort.setAdminStatusEnabled(true);
        lSwitchPort.setDisplayName(niciraNvpResource.truncate(networkId + "-l2Gateway-port", NAME_MAX_LEN));
        lSwitchPort.setTags(tags);
        lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " due to: " + e.getMessage() + ", retrying");
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid);
    s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
    try {
        final L2GatewayAttachment attachment = new L2GatewayAttachment(l2GatewayServiceUuid);
        if (command.getVlanId() != 0) {
            attachment.setVlanId(command.getVlanId());
        }
        niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), attachment);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " + e.getErrorCode());
        cleanup(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
    s_logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId + ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ")");
    return new ConfigureSharedNetworkVlanIdAnswer(command, true, "OK");
}
Also used : NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) ArrayList(java.util.ArrayList) L2GatewayAttachment(com.cloud.network.nicira.L2GatewayAttachment) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Example 17 with LogicalSwitchPort

use of com.cloud.network.nicira.LogicalSwitchPort in project cloudstack by apache.

the class NiciraNvpCreateLogicalSwitchPortCommandWrapper method execute.

@Override
public Answer execute(final CreateLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
    final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String attachmentUuid = command.getAttachmentUuid();
    try {
        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
        final LogicalSwitchPort logicalSwitchPort = niciraNvpUtilities.createLogicalSwitchPort(command);
        final LogicalSwitchPort newPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
        try {
            niciraNvpApi.updateLogicalSwitchPortAttachment(command.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
        } catch (final NiciraNvpApiException ex) {
            s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport");
            niciraNvpApi.deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), newPort.getUuid());
            // Rethrow the original exception
            throw ex;
        }
        return new CreateLogicalSwitchPortAnswer(command, true, "Logical switch port " + newPort.getUuid() + " created", newPort.getUuid());
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, CreateLogicalSwitchPortAnswer.class, e);
    }
}
Also used : NiciraNvpUtilities(com.cloud.network.resource.NiciraNvpUtilities) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CreateLogicalSwitchPortAnswer(com.cloud.agent.api.CreateLogicalSwitchPortAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) VifAttachment(com.cloud.network.nicira.VifAttachment)

Example 18 with LogicalSwitchPort

use of com.cloud.network.nicira.LogicalSwitchPort in project cloudstack by apache.

the class NiciraNvpResourceTest method testFindLogicalSwitchPort.

@Test
public void testFindLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final List<LogicalSwitchPort> lspl = Arrays.asList(new LogicalSwitchPort());
    when(nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenReturn(lspl);
    final FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
    assertTrue(flspa.getResult());
}
Also used : FindLogicalSwitchPortAnswer(com.cloud.agent.api.FindLogicalSwitchPortAnswer) FindLogicalSwitchPortCommand(com.cloud.agent.api.FindLogicalSwitchPortCommand) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) Test(org.junit.Test)

Example 19 with LogicalSwitchPort

use of com.cloud.network.nicira.LogicalSwitchPort in project cloudstack by apache.

the class NiciraNvpResourceTest method testCreateLogicalSwitchPortApiExceptionInModify.

@Test
public void testCreateLogicalSwitchPortApiExceptionInModify() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
    when(lsp.getUuid()).thenReturn("eeee");
    when(nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp);
    doThrow(new NiciraNvpApiException()).when(nvpApi).updateLogicalSwitchPortAttachment((String) any(), (String) any(), (Attachment) any());
    final CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
    final CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
    assertFalse(clspa.getResult());
    verify(nvpApi, atLeastOnce()).deleteLogicalSwitchPort((String) any(), (String) any());
}
Also used : CreateLogicalSwitchPortAnswer(com.cloud.agent.api.CreateLogicalSwitchPortAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchPortCommand(com.cloud.agent.api.CreateLogicalSwitchPortCommand) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) Test(org.junit.Test)

Example 20 with LogicalSwitchPort

use of com.cloud.network.nicira.LogicalSwitchPort in project cloudstack by apache.

the class NiciraNvpResourceTest method testFindLogicalSwitchPortNotFound.

@Test
public void testFindLogicalSwitchPortNotFound() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    @SuppressWarnings("unchecked") final List<LogicalSwitchPort> lspl = Collections.EMPTY_LIST;
    when(nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenReturn(lspl);
    final FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
    assertFalse(flspa.getResult());
}
Also used : FindLogicalSwitchPortAnswer(com.cloud.agent.api.FindLogicalSwitchPortAnswer) FindLogicalSwitchPortCommand(com.cloud.agent.api.FindLogicalSwitchPortCommand) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) Test(org.junit.Test)

Aggregations

LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)24 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)14 Test (org.junit.Test)14 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)8 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)8 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)7 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)7 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)6 CreateLogicalSwitchPortCommand (com.cloud.agent.api.CreateLogicalSwitchPortCommand)6 FindLogicalSwitchPortAnswer (com.cloud.agent.api.FindLogicalSwitchPortAnswer)6 LogicalRouter (com.cloud.network.nicira.LogicalRouter)6 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)6 ArrayList (java.util.ArrayList)6 CreateLogicalRouterCommand (com.cloud.agent.api.CreateLogicalRouterCommand)4 FindLogicalSwitchPortCommand (com.cloud.agent.api.FindLogicalSwitchPortCommand)4 PatchAttachment (com.cloud.network.nicira.PatchAttachment)3 L3GatewayAttachment (com.cloud.network.nicira.L3GatewayAttachment)2 Match (com.cloud.network.nicira.Match)2 RouterNextHop (com.cloud.network.nicira.RouterNextHop)2 SingleDefaultRouteImplicitRoutingConfig (com.cloud.network.nicira.SingleDefaultRouteImplicitRoutingConfig)2