Search in sources :

Example 1 with NeutronNode

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNode 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 NeutronNode

use of org.apache.cloudstack.network.opendaylight.api.model.NeutronNode 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)

Aggregations

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