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