Search in sources :

Example 1 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpConfigurePublicIpsCommandWrapper method execute.

@Override
public Answer execute(final ConfigurePublicIpsOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) {
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    try {
        final List<LogicalRouterPort> ports = niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(command.getLogicalRouterUuid(), command.getL3GatewayServiceUuid());
        if (ports.size() != 1) {
            return new ConfigurePublicIpsOnLogicalRouterAnswer(command, false, "No logical router ports found, unable to set ip addresses");
        }
        final LogicalRouterPort lrp = ports.get(0);
        lrp.setIpAddresses(command.getPublicCidrs());
        niciraNvpApi.updateLogicalRouterPort(command.getLogicalRouterUuid(), lrp);
        return new ConfigurePublicIpsOnLogicalRouterAnswer(command, true, "Configured " + command.getPublicCidrs().size() + " ip addresses on logical router uuid " + command.getLogicalRouterUuid());
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, ConfigurePublicIpsOnLogicalRouterAnswer.class, e);
    }
}
Also used : LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 2 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpCreateLogicalRouterCommandWrapper method execute.

@Override
public Answer execute(final CreateLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) {
    final String routerName = command.getName();
    final String gatewayServiceUuid = command.getGatewayServiceUuid();
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
    tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
    final String publicNetworkNextHopIp = command.getPublicNextHop();
    final String publicNetworkIpAddress = command.getPublicIpCidr();
    final String internalNetworkAddress = command.getInternalIpCidr();
    s_logger.debug("Creating a logical router with external ip " + publicNetworkIpAddress + " and internal ip " + internalNetworkAddress + "on gateway service " + gatewayServiceUuid);
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    try {
        // Create the Router
        LogicalRouter lrc = new LogicalRouter();
        lrc.setDisplayName(niciraNvpResource.truncate(routerName, NAME_MAX_LEN));
        lrc.setTags(tags);
        lrc.setRoutingConfig(new SingleDefaultRouteImplicitRoutingConfig(new RouterNextHop(publicNetworkNextHopIp)));
        lrc = niciraNvpApi.createLogicalRouter(lrc);
        // store the switchport for rollback
        LogicalSwitchPort lsp = null;
        try {
            // Create the outside port for the router
            LogicalRouterPort lrpo = new LogicalRouterPort();
            lrpo.setAdminStatusEnabled(true);
            lrpo.setDisplayName(niciraNvpResource.truncate(routerName + "-outside-port", NAME_MAX_LEN));
            lrpo.setTags(tags);
            final List<String> outsideIpAddresses = new ArrayList<String>();
            outsideIpAddresses.add(publicNetworkIpAddress);
            lrpo.setIpAddresses(outsideIpAddresses);
            lrpo = niciraNvpApi.createLogicalRouterPort(lrc.getUuid(), lrpo);
            // Attach the outside port to the gateway service on the correct VLAN
            final L3GatewayAttachment attachment = new L3GatewayAttachment(gatewayServiceUuid);
            if (command.getVlanId() != 0) {
                attachment.setVlanId(command.getVlanId());
            }
            niciraNvpApi.updateLogicalRouterPortAttachment(lrc.getUuid(), lrpo.getUuid(), attachment);
            // Create the inside port for the router
            LogicalRouterPort lrpi = new LogicalRouterPort();
            lrpi.setAdminStatusEnabled(true);
            lrpi.setDisplayName(niciraNvpResource.truncate(routerName + "-inside-port", NAME_MAX_LEN));
            lrpi.setTags(tags);
            final List<String> insideIpAddresses = new ArrayList<String>();
            insideIpAddresses.add(internalNetworkAddress);
            lrpi.setIpAddresses(insideIpAddresses);
            lrpi = niciraNvpApi.createLogicalRouterPort(lrc.getUuid(), lrpi);
            // Create the inside port on the lswitch
            lsp = new LogicalSwitchPort(niciraNvpResource.truncate(routerName + "-inside-port", NAME_MAX_LEN), tags, true);
            lsp = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp);
            // Attach the inside router port to the lswitch port with a PatchAttachment
            niciraNvpApi.updateLogicalRouterPortAttachment(lrc.getUuid(), lrpi.getUuid(), new PatchAttachment(lsp.getUuid()));
            // Attach the inside lswitch port to the router with a PatchAttachment
            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lsp.getUuid(), new PatchAttachment(lrpi.getUuid()));
            // Setup the source nat rule
            final SourceNatRule snr = new SourceNatRule();
            snr.setToSourceIpAddressMin(publicNetworkIpAddress.split("/")[0]);
            snr.setToSourceIpAddressMax(publicNetworkIpAddress.split("/")[0]);
            final Match match = new Match();
            match.setSourceIpAddresses(internalNetworkAddress);
            snr.setMatch(match);
            snr.setOrder(200);
            niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr);
        } catch (final NiciraNvpApiException e) {
            // this will also take care of any router ports and rules
            try {
                niciraNvpApi.deleteLogicalRouter(lrc.getUuid());
                if (lsp != null) {
                    niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lsp.getUuid());
                }
            } catch (final NiciraNvpApiException ex) {
            }
            throw e;
        }
        return new CreateLogicalRouterAnswer(command, true, "Logical Router created (uuid " + lrc.getUuid() + ")", lrc.getUuid());
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, CreateLogicalRouterAnswer.class, e);
    }
}
Also used : LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) ArrayList(java.util.ArrayList) LogicalRouter(com.cloud.network.nicira.LogicalRouter) RouterNextHop(com.cloud.network.nicira.RouterNextHop) L3GatewayAttachment(com.cloud.network.nicira.L3GatewayAttachment) CreateLogicalRouterAnswer(com.cloud.agent.api.CreateLogicalRouterAnswer) SingleDefaultRouteImplicitRoutingConfig(com.cloud.network.nicira.SingleDefaultRouteImplicitRoutingConfig) Match(com.cloud.network.nicira.Match) PatchAttachment(com.cloud.network.nicira.PatchAttachment) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) SourceNatRule(com.cloud.network.nicira.SourceNatRule) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Example 3 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpDeleteLogicalRouterPortCommandWrapper method execute.

@Override
public Answer execute(DeleteLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalRouterUuid = command.getLogicalRouterUuid();
    final String logicalRouterPortUuid = command.getLogicalRouterPortUuid();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Deleting Logical Router Port " + logicalRouterPortUuid + " in Logical Router " + logicalRouterUuid);
    try {
        niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, logicalRouterPortUuid);
        return new DeleteLogicalRouterPortAnswer(command, true, "Logical Router Port " + logicalRouterPortUuid + " deleted");
    } catch (NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, DeleteLogicalRouterPortAnswer.class, e);
    }
}
Also used : DeleteLogicalRouterPortAnswer(com.cloud.agent.api.DeleteLogicalRouterPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 4 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility 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 5 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpDeleteLogicalSwitchCommandWrapper method execute.

@Override
public Answer execute(final DeleteLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) {
    try {
        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
        niciraNvpApi.deleteLogicalSwitch(command.getLogicalSwitchUuid());
        return new DeleteLogicalSwitchAnswer(command, true, "Logicalswitch " + command.getLogicalSwitchUuid() + " deleted");
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, DeleteLogicalSwitchAnswer.class, e);
    }
}
Also used : NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Aggregations

CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)25 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)23 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)23 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)7 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)7 ArrayList (java.util.ArrayList)7 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)6 NiciraNvpUtilities (com.cloud.network.resource.NiciraNvpUtilities)6 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)4 NatRule (com.cloud.network.nicira.NatRule)4 VifAttachment (com.cloud.network.nicira.VifAttachment)4 PatchAttachment (com.cloud.network.nicira.PatchAttachment)3 ConfigurePortForwardingRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer)2 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer)2 ConfigureSharedNetworkUuidAnswer (com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer)2 ConfigureStaticNatRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)2 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)2 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)2 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)2 DeleteLogicalSwitchAnswer (com.cloud.agent.api.DeleteLogicalSwitchAnswer)2