Search in sources :

Example 1 with NiciraNvpUtilities

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);
    }
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NiciraNvpUtilities(com.cloud.network.resource.NiciraNvpUtilities) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) TransportZoneBinding(com.cloud.network.nicira.TransportZoneBinding) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) ArrayList(java.util.ArrayList) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 2 with NiciraNvpUtilities

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);
    }
}
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 NiciraNvpUtilities

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);
    }
}
Also used : NiciraNvpVxlanTransport(com.cloud.network.nicira.NiciraNvpVxlanTransport) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NiciraNvpUtilities(com.cloud.network.resource.NiciraNvpUtilities) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) ArrayList(java.util.ArrayList) TransportZoneBinding(com.cloud.network.nicira.TransportZoneBinding) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpBindingConfig(com.cloud.network.nicira.NiciraNvpBindingConfig) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 4 with NiciraNvpUtilities

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);
    }
}
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 5 with NiciraNvpUtilities

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);
    }
}
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)6 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)6 NiciraNvpUtilities (com.cloud.network.resource.NiciraNvpUtilities)6 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)6 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)4 VifAttachment (com.cloud.network.nicira.VifAttachment)4 ArrayList (java.util.ArrayList)4 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)2 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)2 UpdateLogicalSwitchPortAnswer (com.cloud.agent.api.UpdateLogicalSwitchPortAnswer)2 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)2 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)2 TransportZoneBinding (com.cloud.network.nicira.TransportZoneBinding)2 NiciraNvpBindingConfig (com.cloud.network.nicira.NiciraNvpBindingConfig)1 NiciraNvpVxlanTransport (com.cloud.network.nicira.NiciraNvpVxlanTransport)1