Search in sources :

Example 1 with NeutronPort

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

the class NeutronPortAdapterTest method gsonNeutronPortMarshalingTest.

@Test
public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException {
    NeutronPort port = new NeutronPort();
    port.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    port.setName("test_gre");
    port.setAdminStateUp(true);
    port.setDeviceId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    port.setMacAddress("ca31aa7f-84c7-416d-bc00-1f84927367e0");
    port.setNetworkId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    port.setStatus("ACTIVE");
    port.setTenantId("wilder");
    NeutronPortWrapper portWrapper = new NeutronPortWrapper();
    portWrapper.setPort(port);
    StringRequestEntity entity;
    try {
        entity = new StringRequestEntity(gsonNeutronPort.toJson(portWrapper), "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) NeutronPort(org.apache.cloudstack.network.opendaylight.api.model.NeutronPort) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper) Test(org.junit.Test)

Example 2 with NeutronPort

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

the class NeutronPortAdapterTest method gsonNeutronPortUnmarshalingTest.

@Test
public <T> void gsonNeutronPortUnmarshalingTest() throws NeutronRestApiException {
    NeutronPort port = new NeutronPort();
    port.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    port.setName("test_gre");
    port.setAdminStateUp(true);
    port.setDeviceId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    port.setMacAddress("ca31aa7f-84c7-416d-bc00-1f84927367e0");
    port.setNetworkId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    port.setStatus("ACTIVE");
    port.setTenantId("wilder");
    NeutronPortWrapper portWrapper = new NeutronPortWrapper();
    portWrapper.setPort(port);
    NeutronPortWrapper returnValue = (NeutronPortWrapper) gsonNeutronPort.fromJson(jsonString, TypeToken.get(portWrapper.getClass()).getType());
    Assert.assertNotNull(returnValue);
    Assert.assertEquals("ca31aa7f-84c7-416d-bc00-1f84927367e0", returnValue.getPort().getMacAddress());
}
Also used : NeutronPort(org.apache.cloudstack.network.opendaylight.api.model.NeutronPort) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper) Test(org.junit.Test)

Example 3 with NeutronPort

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

the class OpenDaylightControllerResource method executeRequest.

private Answer executeRequest(ConfigurePortCommand cmd) {
    NeutronPortsNorthboundAction configurePort = new NeutronPortsNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
    NeutronPort newPort = new NeutronPort();
    // Configuration from the command
    newPort.setId(cmd.getPortId());
    newPort.setTenantId(cmd.getTennantId());
    newPort.setAdminStateUp(true);
    newPort.setName(cmd.getPortId().toString());
    newPort.setNetworkId(cmd.getNetworkId());
    newPort.setMacAddress(cmd.getMacAddress());
    newPort.setDeviceId(UUID.randomUUID());
    // Static valus
    newPort.setStatus("ACTIVE");
    newPort.setFixedIps(Collections.<String>emptyList());
    NeutronPortWrapper portWrapper = new NeutronPortWrapper();
    portWrapper.setPort(newPort);
    try {
        portWrapper = configurePort.createNeutronPort(portWrapper);
    } catch (NeutronRestApiException e) {
        s_logger.error("createPortCommand failed", e);
        return new ConfigurePortAnswer(cmd, e);
    }
    return new ConfigurePortAnswer(cmd, true, "Port " + portWrapper.getPort().getId().toString() + " created");
}
Also used : NeutronPort(org.apache.cloudstack.network.opendaylight.api.model.NeutronPort) NeutronPortsNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) ConfigurePortAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)

Aggregations

NeutronPort (org.apache.cloudstack.network.opendaylight.api.model.NeutronPort)3 NeutronPortWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)3 Test (org.junit.Test)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConfigurePortAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer)1 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)1 NeutronPortsNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1