Search in sources :

Example 16 with NiciraNvpApiException

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

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

the class NiciraNvpResource method getCurrentStatus.

@Override
public PingCommand getCurrentStatus(final long id) {
    try {
        final ControlClusterStatus ccs = niciraNvpApi.getControlClusterStatus();
        getApiProviderMajorityVersion(ccs);
        if (!"stable".equals(ccs.getClusterStatus())) {
            s_logger.error("ControlCluster state is not stable: " + ccs.getClusterStatus());
            return null;
        }
    } catch (final NiciraNvpApiException e) {
        s_logger.error("getControlClusterStatus failed", e);
        return null;
    }
    return new PingCommand(Host.Type.L2Networking, id);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) PingCommand(com.cloud.agent.api.PingCommand)

Example 18 with NiciraNvpApiException

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

the class NiciraNvpResourceTest method testFindLogicalSwitchPortApiException.

@Test
public void testFindLogicalSwitchPortApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    when(nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenThrow(new NiciraNvpApiException());
    final FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
    assertFalse(flspa.getResult());
}
Also used : FindLogicalSwitchPortAnswer(com.cloud.agent.api.FindLogicalSwitchPortAnswer) FindLogicalSwitchPortCommand(com.cloud.agent.api.FindLogicalSwitchPortCommand) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Example 19 with NiciraNvpApiException

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

the class NiciraNvpResourceTest method testCreateLogicalSwitchPortApiExceptionInCreate.

@Test
public void testCreateLogicalSwitchPortApiExceptionInCreate() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
    when(lsp.getUuid()).thenReturn("eeee");
    when(nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenThrow(new NiciraNvpApiException());
    final CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
    final CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
    assertFalse(clspa.getResult());
}
Also used : CreateLogicalSwitchPortAnswer(com.cloud.agent.api.CreateLogicalSwitchPortAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchPortCommand(com.cloud.agent.api.CreateLogicalSwitchPortCommand) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) Test(org.junit.Test)

Example 20 with NiciraNvpApiException

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

the class NiciraNvpResourceTest method testRetries.

@Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner");
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

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