use of com.cloud.network.resource.NiciraNvpUtilities in project cloudstack by apache.
the class NiciraNvpCreateLogicalSwitchCommandWrapper method execute.
@Override
public Answer execute(final CreateLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) {
final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
LogicalSwitch logicalSwitch = niciraNvpUtilities.createLogicalSwitch();
logicalSwitch.setDisplayName(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN));
logicalSwitch.setPortIsolationEnabled(false);
// Set transport binding
final List<TransportZoneBinding> ltzb = new ArrayList<TransportZoneBinding>();
ltzb.add(new TransportZoneBinding(command.getTransportUuid(), command.getTransportType()));
logicalSwitch.setTransportZones(ltzb);
// Tags set to scope cs_account and account name
final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
logicalSwitch.setTags(tags);
try {
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
logicalSwitch = niciraNvpApi.createLogicalSwitch(logicalSwitch);
final String switchUuid = logicalSwitch.getUuid();
return new CreateLogicalSwitchAnswer(command, true, "Logicalswitch " + switchUuid + " created", switchUuid);
} catch (final NiciraNvpApiException e) {
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
retryUtility.addRetry(command, NUM_RETRIES);
return retryUtility.retry(command, CreateLogicalSwitchAnswer.class, e);
}
}
use of com.cloud.network.resource.NiciraNvpUtilities in project cosmic by MissionCriticalCloud.
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<>();
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.resource.NiciraNvpUtilities in project cosmic by MissionCriticalCloud.
the class NiciraNvpCreateLogicalSwitchCommandWrapper method execute.
@Override
public Answer execute(final CreateLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) {
final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
LogicalSwitch logicalSwitch = niciraNvpUtilities.createLogicalSwitch();
logicalSwitch.setDisplayName(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN));
logicalSwitch.setPortIsolationEnabled(false);
// Set transport binding
final List<TransportZoneBinding> ltzb = new ArrayList<>();
final List<NiciraNvpVxlanTransport> vxlanTransport = new ArrayList<>();
vxlanTransport.add(new NiciraNvpVxlanTransport(command.getVni()));
final NiciraNvpBindingConfig bindingConfig = new NiciraNvpBindingConfig(vxlanTransport);
ltzb.add(new TransportZoneBinding(command.getTransportUuid(), command.getTransportType(), bindingConfig));
logicalSwitch.setTransportZones(ltzb);
// Tags set to scope cs_account and account name
final List<NiciraNvpTag> tags = new ArrayList<>();
tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
logicalSwitch.setTags(tags);
try {
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
logicalSwitch = niciraNvpApi.createLogicalSwitch(logicalSwitch);
final String switchUuid = logicalSwitch.getUuid();
return new CreateLogicalSwitchAnswer(command, true, "Logicalswitch " + switchUuid + " created", switchUuid);
} catch (final NiciraNvpApiException e) {
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
retryUtility.addRetry(command, NUM_RETRIES);
return retryUtility.retry(command, CreateLogicalSwitchAnswer.class, e);
}
}
use of com.cloud.network.resource.NiciraNvpUtilities in project cosmic by MissionCriticalCloud.
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);
// Check if stale Logical Switch Port is present in NSX
final String staleSwitchPortUuid = niciraNvpApi.findLogicalSwitchPortUuidByVifAttachmentUuid(logicalSwitchUuid, attachmentUuid);
if (staleSwitchPortUuid != null) {
niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, staleSwitchPortUuid);
}
// We can't set Mac Learning unless there is an attachment
logicalSwitchPort.setMacLearning(null);
final LogicalSwitchPort newPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
try {
niciraNvpApi.updateLogicalSwitchPortAttachment(command.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
if (command.getMacLearning()) {
s_logger.info("Updating newly created logical switch port: " + newPort.getUuid() + " to enable mac_learning");
newPort.setMacLearning(true);
niciraNvpApi.updateLogicalSwitchPort(logicalSwitchUuid, newPort);
}
} 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);
}
}
use of com.cloud.network.resource.NiciraNvpUtilities 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