Search in sources :

Example 1 with NeutronNodeWrapper

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

the class OpenDaylightControllerResource method executeRequest.

private Answer executeRequest(AddHypervisorCommand cmd) {
    NeutronNodesNorthboundAction nodeActions = new NeutronNodesNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
    try {
        NeutronNodesList<NeutronNodeWrapper> nodes = nodeActions.listAllNodes();
        if (nodes.getNodes() != null) {
            for (NeutronNodeWrapper nodeWrapper : nodes.getNodes()) {
                NeutronNode node = nodeWrapper.getNode();
                if (node.getId().equals(cmd.getHostId())) {
                    return new AddHypervisorAnswer(cmd, true, "Hypervisor already connected");
                }
            }
        }
        // Not found in the existing node list, add it
        nodeActions.updateNeutronNodeV2("OVS", cmd.getHostId(), cmd.getIpAddress(), 6640);
    } catch (NeutronRestApiException e) {
        s_logger.error("Call to OpenDaylight failed", e);
        return new AddHypervisorAnswer(cmd, e);
    }
    return new AddHypervisorAnswer(cmd, true, "Hypervisor " + cmd.getHostId() + " added");
}
Also used : NeutronNodeWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper) NeutronNode(org.apache.cloudstack.network.opendaylight.api.model.NeutronNode) NeutronNodesNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronNodesNorthboundAction) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) AddHypervisorAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer)

Example 2 with NeutronNodeWrapper

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

the class NeutronNodeAdapterTest method gsonNeutronPortUnmarshalingTest.

@Test
public <T> void gsonNeutronPortUnmarshalingTest() throws NeutronRestApiException {
    NeutronNodeWrapper returnValue = (NeutronNodeWrapper) gsonNeutronNode.fromJson(jsonString, TypeToken.get(NeutronNodeWrapper.class).getType());
    Assert.assertNotNull(returnValue);
    Assert.assertEquals("node-test", returnValue.getNode().getId().toString());
}
Also used : NeutronNodeWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper) Test(org.junit.Test)

Example 3 with NeutronNodeWrapper

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

the class NeutronNodeAdapterTest method gsonNeutronPortUnmarshalingNullTest.

@Test
public <T> void gsonNeutronPortUnmarshalingNullTest() throws NeutronRestApiException {
    String json = null;
    NeutronNodeWrapper returnValue = (NeutronNodeWrapper) gsonNeutronNode.fromJson(json, TypeToken.get(NeutronNodeWrapper.class).getType());
    Assert.assertNull(returnValue);
}
Also used : NeutronNodeWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper) Test(org.junit.Test)

Example 4 with NeutronNodeWrapper

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

the class NeutronNodeAdapterTest method gsonNeutronPortMarshalingTest.

@Test
public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException {
    NeutronNode node = new NeutronNode("node-test", "test");
    NeutronNodeWrapper nodeWrapper = new NeutronNodeWrapper(node);
    StringRequestEntity entity;
    try {
        entity = new StringRequestEntity(gsonNeutronNode.toJson(nodeWrapper), "application/json", null);
        String actual = entity.getContent();
        Assert.assertEquals(jsonString, actual);
    } catch (UnsupportedEncodingException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) NeutronNode(org.apache.cloudstack.network.opendaylight.api.model.NeutronNode) NeutronNodeWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 5 with NeutronNodeWrapper

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

the class NeutronRestApiIT method neutronListAllNodes.

@Test
public void neutronListAllNodes() throws NeutronRestApiException {
    URL url;
    try {
        url = new URL("http://178.237.34.233:8080");
        NeutronNodesNorthboundAction neutron = new NeutronNodesNorthboundAction(url, "admin", "admin");
        NeutronNodesList<NeutronNodeWrapper> results = neutron.listAllNodes();
        Assert.assertNotNull(results);
    } catch (MalformedURLException e) {
        Assert.fail("Should not fail here.");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) NeutronNodeWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper) NeutronNodesNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronNodesNorthboundAction) URL(java.net.URL) Test(org.junit.Test)

Aggregations

NeutronNodeWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper)5 Test (org.junit.Test)4 NeutronNode (org.apache.cloudstack.network.opendaylight.api.model.NeutronNode)2 NeutronNodesNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronNodesNorthboundAction)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 AddHypervisorAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer)1 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1