Search in sources :

Example 11 with NeutronRestApiException

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

the class NeutronNetworksNorthboundAction method createNeutronNetwork.

@SuppressWarnings("unchecked")
public <T> T createNeutronNetwork(final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException {
    try {
        String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri();
        StringRequestEntity entity = new StringRequestEntity(gsonNeutronNetwork.toJson(newNetworkWrapper), JSON_CONTENT_TYPE, null);
        String bodystring = executePost(uri, entity);
        T result = (T) gsonNeutronNetwork.fromJson(bodystring, TypeToken.get(NeutronNetworkWrapper.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) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)

Example 12 with NeutronRestApiException

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

NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)12 NeutronInvalidCredentialsException (org.apache.cloudstack.network.opendaylight.api.NeutronInvalidCredentialsException)5 NeutronRestApi (org.apache.cloudstack.network.opendaylight.api.NeutronRestApi)5 NeutronRestFactory (org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)4 IOException (java.io.IOException)3 NeutronNetworkWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)2 NeutronPortWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)2 PutMethod (org.apache.commons.httpclient.methods.PutMethod)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 AddHypervisorAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer)1 ConfigureNetworkAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer)1 ConfigurePortAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer)1 NeutronNetwork (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork)1 NeutronNode (org.apache.cloudstack.network.opendaylight.api.model.NeutronNode)1 NeutronNodeWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper)1 NeutronPort (org.apache.cloudstack.network.opendaylight.api.model.NeutronPort)1 NeutronNetworksNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction)1