Search in sources :

Example 6 with LogicalSwitchPort

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

the class NiciraNvpResourceTest method testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort.

@Test
public void testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalRouter lrc = mock(LogicalRouter.class);
    final LogicalRouterPort lrp = mock(LogicalRouterPort.class);
    final LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
    when(lrc.getUuid()).thenReturn("ccccc");
    when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
    when(lsp.getUuid()).thenReturn("fffff");
    when(nvpApi.createLogicalRouter((LogicalRouter) any())).thenReturn(lrc);
    when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort) any())).thenReturn(lrp);
    when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort) any())).thenReturn(lsp);
    when(nvpApi.createLogicalRouterNatRule((String) any(), (NatRule) any())).thenThrow(new NiciraNvpApiException());
    final CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
    final CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
    assertFalse(clra.getResult());
    verify(nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
    verify(nvpApi, atLeast(1)).deleteLogicalSwitchPort(eq("bbbbb"), eq("fffff"));
}
Also used : CreateLogicalRouterCommand(com.cloud.agent.api.CreateLogicalRouterCommand) LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) LogicalRouter(com.cloud.network.nicira.LogicalRouter) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalRouterAnswer(com.cloud.agent.api.CreateLogicalRouterAnswer) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) Test(org.junit.Test)

Example 7 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)

Example 8 with LogicalSwitchPort

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

the class NiciraNvpResourceTest method testCreateLogicalRouter.

@Test
public void testCreateLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalRouter lrc = mock(LogicalRouter.class);
    final LogicalRouterPort lrp = mock(LogicalRouterPort.class);
    final LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
    when(lrc.getUuid()).thenReturn("ccccc");
    when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
    when(lsp.getUuid()).thenReturn("fffff");
    when(nvpApi.createLogicalRouter((LogicalRouter) any())).thenReturn(lrc);
    when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort) any())).thenReturn(lrp);
    when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort) any())).thenReturn(lsp);
    final CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
    final CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
    assertTrue(clra.getResult());
    assertTrue("ccccc".equals(clra.getLogicalRouterUuid()));
    verify(nvpApi, atLeast(1)).createLogicalRouterNatRule((String) any(), (NatRule) any());
}
Also used : CreateLogicalRouterCommand(com.cloud.agent.api.CreateLogicalRouterCommand) LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) LogicalRouter(com.cloud.network.nicira.LogicalRouter) CreateLogicalRouterAnswer(com.cloud.agent.api.CreateLogicalRouterAnswer) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) Test(org.junit.Test)

Example 9 with LogicalSwitchPort

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

the class NiciraNvpConfigureSharedNetworkUuidCommandWrapper method execute.

@Override
public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalRouterUuid = command.getLogicalRouterUuid();
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String portIpAddress = command.getPortIpAddress();
    final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
    tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
    final long networkId = command.getNetworkId();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Attaching Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
    //Step 1: Get lSwitch displayName
    s_logger.info("Looking for Logical Switch " + logicalSwitchUuid + " display name");
    String logicalSwitchDisplayName;
    try {
        List<LogicalSwitch> lSwitchList = niciraNvpApi.findLogicalSwitch(logicalSwitchUuid);
        if (lSwitchList != null) {
            if (lSwitchList.size() == 1) {
                logicalSwitchDisplayName = lSwitchList.get(0).getDisplayName();
            } else {
                s_logger.error("More than one Logical Switch found with uuid " + logicalSwitchUuid);
                throw new CloudRuntimeException("More than one Logical Switch found with uuid=" + logicalSwitchUuid);
            }
        } else {
            s_logger.error("Logical Switch " + logicalSwitchUuid + " not found");
            throw new CloudRuntimeException("Logical Switch " + logicalSwitchUuid + " not found");
        }
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Logical Switch " + logicalSwitchUuid + " not found, retrying");
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e);
    } catch (CloudRuntimeException e) {
        s_logger.info("Shared network UUID vlan id failed due to : " + e.getMessage());
        return new ConfigureSharedNetworkUuidAnswer(command, false, e.getMessage());
    }
    s_logger.info("Found display name " + logicalSwitchDisplayName + " for Logical Switch " + logicalSwitchUuid);
    //Step 2: Create lRouterPort
    s_logger.debug("Creating Logical Router Port in Logical Router " + logicalRouterUuid);
    LogicalRouterPort lRouterPort = null;
    try {
        lRouterPort = new LogicalRouterPort();
        lRouterPort.setAdminStatusEnabled(true);
        lRouterPort.setDisplayName(niciraNvpResource.truncate(logicalSwitchDisplayName + "-uplink", NAME_MAX_LEN));
        lRouterPort.setTags(tags);
        final List<String> ipAddresses = new ArrayList<String>();
        ipAddresses.add(portIpAddress);
        lRouterPort.setIpAddresses(ipAddresses);
        lRouterPort = niciraNvpApi.createLogicalRouterPort(logicalRouterUuid, lRouterPort);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not create Logical Router Port on Logical Router " + logicalRouterUuid + " due to: " + e.getMessage() + ", retrying");
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully created in Logical Router " + logicalRouterUuid);
    //Step 3: Create lSwitchPort
    s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")");
    LogicalSwitchPort lSwitchPort = null;
    try {
        lSwitchPort = new LogicalSwitchPort(niciraNvpResource.truncate("lrouter-uplink", NAME_MAX_LEN), tags, true);
        lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")  due to: " + e.getMessage());
        cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")");
    //Step 4: Attach lRouterPort to lSwitchPort with a PatchAttachment
    s_logger.debug("Attaching Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment");
    try {
        niciraNvpApi.updateLogicalRouterPortAttachment(logicalRouterUuid, lRouterPort.getUuid(), new PatchAttachment(lSwitchPort.getUuid()));
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not attach Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
        cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
        cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully attached to to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment");
    //Step 5: Attach lSwitchPort to lRouterPort with a PatchAttachment
    s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment");
    try {
        niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), new PatchAttachment(lRouterPort.getUuid()));
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
        cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
        cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached to to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment");
    s_logger.info("Successfully attached Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
    return new ConfigureSharedNetworkUuidAnswer(command, true, "OK");
}
Also used : ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) ArrayList(java.util.ArrayList) PatchAttachment(com.cloud.network.nicira.PatchAttachment) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Example 10 with LogicalSwitchPort

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

the class NiciraNvpFindLogicalSwitchPortCommandWrapper method execute.

@Override
public Answer execute(final FindLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String logicalSwitchPortUuid = command.getLogicalSwitchPortUuid();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    try {
        final List<LogicalSwitchPort> ports = niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid);
        if (ports.size() == 0) {
            return new FindLogicalSwitchPortAnswer(command, false, "Logical switchport " + logicalSwitchPortUuid + " not found", null);
        } else {
            return new FindLogicalSwitchPortAnswer(command, true, "Logical switchport " + logicalSwitchPortUuid + " found", logicalSwitchPortUuid);
        }
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, FindLogicalSwitchPortAnswer.class, e);
    }
}
Also used : FindLogicalSwitchPortAnswer(com.cloud.agent.api.FindLogicalSwitchPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Aggregations

LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)13 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)8 Test (org.junit.Test)7 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)5 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)4 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)4 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)4 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)4 ArrayList (java.util.ArrayList)4 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)3 CreateLogicalSwitchPortCommand (com.cloud.agent.api.CreateLogicalSwitchPortCommand)3 FindLogicalSwitchPortAnswer (com.cloud.agent.api.FindLogicalSwitchPortAnswer)3 LogicalRouter (com.cloud.network.nicira.LogicalRouter)3 CreateLogicalRouterCommand (com.cloud.agent.api.CreateLogicalRouterCommand)2 FindLogicalSwitchPortCommand (com.cloud.agent.api.FindLogicalSwitchPortCommand)2 PatchAttachment (com.cloud.network.nicira.PatchAttachment)2 ConfigureSharedNetworkUuidAnswer (com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer)1 ConfigureSharedNetworkVlanIdAnswer (com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer)1 L2GatewayAttachment (com.cloud.network.nicira.L2GatewayAttachment)1 L3GatewayAttachment (com.cloud.network.nicira.L3GatewayAttachment)1