Search in sources :

Example 11 with NiciraNvpApiException

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

the class NiciraNvpResourceTest method testUpdateLogicalSwitchPortException.

@Test
public void testUpdateLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    doThrow(new NiciraNvpApiException()).when(nvpApi).updateLogicalSwitchPortAttachment((String) any(), (String) any(), (Attachment) any());
    final UpdateLogicalSwitchPortAnswer dlspa = (UpdateLogicalSwitchPortAnswer) resource.executeRequest(new UpdateLogicalSwitchPortCommand("aaaa", "bbbb", "cccc", "owner", "nicname"));
    assertFalse(dlspa.getResult());
}
Also used : UpdateLogicalSwitchPortAnswer(com.cloud.agent.api.UpdateLogicalSwitchPortAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) UpdateLogicalSwitchPortCommand(com.cloud.agent.api.UpdateLogicalSwitchPortCommand) Test(org.junit.Test)

Example 12 with NiciraNvpApiException

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

the class NiciraNvpResourceTest method testPingCommandStatusApiException.

@Test
public void testPingCommandStatusApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ControlClusterStatus ccs = mock(ControlClusterStatus.class);
    when(ccs.getClusterStatus()).thenReturn("unstable");
    when(nvpApi.getControlClusterStatus()).thenThrow(new NiciraNvpApiException());
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 13 with NiciraNvpApiException

use of com.cloud.network.nicira.NiciraNvpApiException 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 14 with NiciraNvpApiException

use of com.cloud.network.nicira.NiciraNvpApiException 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 15 with NiciraNvpApiException

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

the class NiciraCheckHealthCommandWrapper method execute.

@Override
public Answer execute(final CheckHealthCommand command, final NiciraNvpResource serverResource) {
    final NiciraNvpApi niciraNvpApi = serverResource.getNiciraNvpApi();
    boolean healthy = true;
    try {
        final ControlClusterStatus clusterStatus = niciraNvpApi.getControlClusterStatus();
        final String status = clusterStatus.getClusterStatus();
        if (clusterIsUnstable(status)) {
            s_logger.warn("Control cluster is not stable. Current status is " + status);
            healthy = false;
        }
    } catch (final NiciraNvpApiException e) {
        s_logger.error("Exception caught while checking control cluster status during health check", e);
        healthy = false;
    }
    return new CheckHealthAnswer(command, healthy);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Aggregations

NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)39 Test (org.junit.Test)23 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)21 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)13 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)8 ArrayList (java.util.ArrayList)8 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)7 Answer (com.cloud.agent.api.Answer)6 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)5 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)5 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)4 NatRule (com.cloud.network.nicira.NatRule)4 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer)3 ConfigurePublicIpsOnLogicalRouterCommand (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand)3 CreateLogicalRouterCommand (com.cloud.agent.api.CreateLogicalRouterCommand)3 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)3 CreateLogicalSwitchCommand (com.cloud.agent.api.CreateLogicalSwitchCommand)3 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)3 ControlClusterStatus (com.cloud.network.nicira.ControlClusterStatus)3 VifAttachment (com.cloud.network.nicira.VifAttachment)3