Search in sources :

Example 1 with NeutronNetwork

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork in project cloudstack by apache.

the class OpenDaylightControllerResource method executeRequest.

private Answer executeRequest(ConfigureNetworkCommand cmd) {
    NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
    // Find free gre key
    int gre_key = -1;
    Random keyGenerator = new Random(System.currentTimeMillis());
    try {
        NeutronNetworksList<NeutronNetwork> networks = configureNetwork.listAllNetworks();
        while (true) {
            int i = keyGenerator.nextInt();
            for (NeutronNetwork network : networks.getNetworks()) {
                if (network.getSegmentationId() == i) {
                    continue;
                }
            }
            gre_key = i;
            break;
        }
    } catch (NeutronRestApiException e) {
        s_logger.error("Failed to list existing networks on the ODL Controller", e);
        return new ConfigureNetworkAnswer(cmd, e);
    }
    NeutronNetwork newNetwork = new NeutronNetwork();
    // Configuration from the command
    newNetwork.setName(cmd.getName());
    newNetwork.setTenantId(cmd.getTenantId());
    // Static configuation
    newNetwork.setNetworkType("gre");
    newNetwork.setShared(false);
    newNetwork.setSegmentationId(gre_key);
    newNetwork.setId(UUID.randomUUID());
    NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();
    wrapper.setNetwork(newNetwork);
    try {
        wrapper = configureNetwork.createNeutronNetwork(wrapper);
    } catch (NeutronRestApiException e) {
        s_logger.error("createNeutronNetwork failed", e);
        return new ConfigureNetworkAnswer(cmd, e);
    }
    return new ConfigureNetworkAnswer(cmd, true, null, wrapper.getNetwork().getId().toString());
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) Random(java.util.Random) ConfigureNetworkAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) NeutronNetworksNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction)

Example 2 with NeutronNetwork

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork in project cloudstack by apache.

the class NeutronNetworkAdapterTest method gsonNeutronNetworkMarshalingTest.

@Test
public void gsonNeutronNetworkMarshalingTest() throws NeutronRestApiException {
    NeutronNetwork network = new NeutronNetwork();
    network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    network.setName("test_gre");
    network.setNetworkType("test");
    network.setSegmentationId(1001);
    network.setShared(true);
    network.setTenantId("wilder");
    NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper();
    networkWrapper.setNetwork(network);
    StringRequestEntity entity;
    try {
        entity = new StringRequestEntity(gsonNeutronNetwork.toJson(networkWrapper), "application/json", null);
        String actual = entity.getContent();
        Assert.assertEquals(jsonString, actual);
    } catch (UnsupportedEncodingException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) Test(org.junit.Test)

Example 3 with NeutronNetwork

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork in project cloudstack by apache.

the class NeutronRestApiMock method neutronHTTPPostMethod.

/*
     * Test fails because there is no controller. It's used only to test that
     * the HTTP methods are correct.
     */
@Test(expected = NeutronRestApiException.class)
public void neutronHTTPPostMethod() throws NeutronRestApiException {
    URL url;
    try {
        url = new URL("http://localhost:8080");
        NeutronNetwork network = new NeutronNetwork();
        network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
        network.setName("test_gre");
        network.setNetworkType("test");
        network.setSegmentationId(1001);
        network.setShared(true);
        network.setTenantId("wilder");
        NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper();
        networkWrapper.setNetwork(network);
        NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin");
        neutron.createNeutronNetwork(networkWrapper);
    } catch (MalformedURLException e) {
        Assert.fail("Should not fail here.");
    }
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) MalformedURLException(java.net.MalformedURLException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) URL(java.net.URL) NeutronNetworksNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction) Test(org.junit.Test)

Example 4 with NeutronNetwork

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork in project cloudstack by apache.

the class NeutronRestApiMock method neutronHTTPPutMethod.

/*
     * Test fails because there is no controller. It's used only to test that
     * the HTTP methods are correct.
     */
@Test(expected = NeutronRestApiException.class)
public void neutronHTTPPutMethod() throws NeutronRestApiException {
    URL url;
    try {
        url = new URL("http://localhost:8080");
        NeutronNetwork network = new NeutronNetwork();
        network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
        network.setName("test_gre");
        network.setNetworkType("test");
        network.setSegmentationId(1001);
        network.setShared(true);
        network.setTenantId("wilder");
        NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper();
        networkWrapper.setNetwork(network);
        NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin");
        neutron.updateNeutronNetwork("ca31aa7f-84c7-416d-bc00-1f84927367e0", networkWrapper);
    } catch (MalformedURLException e) {
        Assert.fail("Should not fail here.");
    }
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) MalformedURLException(java.net.MalformedURLException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) URL(java.net.URL) NeutronNetworksNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction) Test(org.junit.Test)

Example 5 with NeutronNetwork

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork in project cloudstack by apache.

the class NeutronNetworkAdapterTest method gsonNeutronNetworkUnmarshalingTest.

@Test
public <T> void gsonNeutronNetworkUnmarshalingTest() throws NeutronRestApiException {
    NeutronNetwork network = new NeutronNetwork();
    network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    network.setName("test_gre");
    network.setNetworkType("test");
    network.setSegmentationId(1001);
    network.setShared(true);
    network.setTenantId("wilder");
    NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper();
    networkWrapper.setNetwork(network);
    NeutronNetworkWrapper returnValue = (NeutronNetworkWrapper) gsonNeutronNetwork.fromJson(jsonString, TypeToken.get(networkWrapper.getClass()).getType());
    Assert.assertNotNull(returnValue);
    Assert.assertEquals("test_gre", returnValue.getNetwork().getName());
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) Test(org.junit.Test)

Aggregations

NeutronNetwork (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork)5 NeutronNetworkWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)5 Test (org.junit.Test)4 NeutronNetworksNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Random (java.util.Random)1 ConfigureNetworkAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer)1 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1