Search in sources :

Example 1 with VifAttachment

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

the class NiciraNvpRequestWrapperTest method testUpdateLogicalSwitchPortCommand.

@Test
public void testUpdateLogicalSwitchPortCommand() {
    final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
    final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
    final VifAttachment vifAttachment = Mockito.mock(VifAttachment.class);
    final String logicalSwitchPortUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String logicalSwitchUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String attachmentUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String ownerName = "admin";
    final String nicName = "eth0";
    final UpdateLogicalSwitchPortCommand command = new UpdateLogicalSwitchPortCommand(logicalSwitchPortUuid, logicalSwitchUuid, attachmentUuid, ownerName, nicName);
    when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
    when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
    try {
        when(niciraNvpUtilities.createVifAttachment(attachmentUuid)).thenReturn(vifAttachment);
        doNothing().when(niciraNvpApi).updateLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, vifAttachment);
    } 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.agent.api.Answer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) UpdateLogicalSwitchPortCommand(com.cloud.agent.api.UpdateLogicalSwitchPortCommand) VifAttachment(com.cloud.network.nicira.VifAttachment) Test(org.junit.Test)

Example 2 with VifAttachment

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

the class NiciraNvpUpdateLogicalSwitchPortCommandWrapper method execute.

@Override
public Answer execute(final UpdateLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
    final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String logicalSwitchPortUuid = command.getLogicalSwitchPortUuid();
    final String attachmentUuid = command.getAttachmentUuid();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    try {
        // Tags set to scope cs_account and account name
        final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
        tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
        final VifAttachment vifAttachment = niciraNvpUtilities.createVifAttachment(attachmentUuid);
        niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, vifAttachment);
        return new UpdateLogicalSwitchPortAnswer(command, true, "Attachment for  " + logicalSwitchPortUuid + " updated", logicalSwitchPortUuid);
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, UpdateLogicalSwitchPortAnswer.class, e);
    }
}
Also used : NiciraNvpUtilities(com.cloud.network.resource.NiciraNvpUtilities) UpdateLogicalSwitchPortAnswer(com.cloud.agent.api.UpdateLogicalSwitchPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) ArrayList(java.util.ArrayList) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) VifAttachment(com.cloud.network.nicira.VifAttachment)

Example 3 with VifAttachment

use of com.cloud.network.nicira.VifAttachment 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)

Aggregations

NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)3 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)3 VifAttachment (com.cloud.network.nicira.VifAttachment)3 NiciraNvpUtilities (com.cloud.network.resource.NiciraNvpUtilities)2 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)2 Answer (com.cloud.agent.api.Answer)1 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)1 UpdateLogicalSwitchPortAnswer (com.cloud.agent.api.UpdateLogicalSwitchPortAnswer)1 UpdateLogicalSwitchPortCommand (com.cloud.agent.api.UpdateLogicalSwitchPortCommand)1 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)1 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1