Search in sources :

Example 1 with NeutronPortWrapper

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

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

the class NeutronRestApiIT method neutronListAllPorts.

@Test
public void neutronListAllPorts() throws NeutronRestApiException {
    URL url;
    try {
        url = new URL("http://178.237.34.233:8080");
        NeutronPortsNorthboundAction neutron = new NeutronPortsNorthboundAction(url, "admin", "admin");
        NeutronPortsList<NeutronPortWrapper> results = neutron.listAllPorts();
        Assert.assertNotNull(results);
        List<NeutronPortWrapper> networks = results.getPorts();
        Assert.assertNotNull(networks);
    } catch (MalformedURLException e) {
        Assert.fail("Should not fail here.");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) NeutronPortsNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper) URL(java.net.URL) Test(org.junit.Test)

Example 3 with NeutronPortWrapper

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

the class NeutronPortsNorthboundAction method createNeutronPort.

@SuppressWarnings("unchecked")
public <T> T createNeutronPort(final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException {
    try {
        String uri = NeutronNorthboundEnum.PORTS_URI.getUri();
        StringRequestEntity entity = new StringRequestEntity(gsonNeutronPort.toJson(newPortWrapper), JSON_CONTENT_TYPE, null);
        String bodystring = executePost(uri, entity);
        T result = (T) gsonNeutronPort.fromJson(bodystring, TypeToken.get(NeutronPortWrapper.class).getType());
        return result;
    } catch (UnsupportedEncodingException e) {
        throw new NeutronRestApiException("Failed to encode json request body", e);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)

Example 4 with NeutronPortWrapper

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

the class NeutronPortsNorthboundAction method findPortById.

@SuppressWarnings("unchecked")
public <T> T findPortById(final String portId) throws NeutronRestApiException {
    String uri = NeutronNorthboundEnum.PORTS_PARAM_URI.getUri();
    uri = MessageFormat.format(uri, portId);
    String bodystring = executeGet(uri, Collections.<String, String>emptyMap());
    Type returnType = new TypeToken<NeutronPortWrapper>() {
    }.getType();
    T returnValue = (T) gsonNeutronPort.fromJson(bodystring, returnType);
    return returnValue;
}
Also used : Type(java.lang.reflect.Type) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)

Example 5 with NeutronPortWrapper

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

Aggregations

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