Search in sources :

Example 1 with NeutronNetwork

use of org.openstack4j.openstack.networking.domain.NeutronNetwork in project onos by opennetworkinglab.

the class OpenstackNetworkWebResource method createNetwork.

/**
 * Creates a network from the JSON input stream.
 *
 * @param input network JSON input stream
 * @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is invalid or duplicated network already exists
 * @throws IOException exception
 * @onos.rsModel NeutronNetwork
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNetwork(InputStream input) throws IOException {
    log.trace(String.format(MESSAGE, "CREATE"));
    String inputStr = IOUtils.toString(input, REST_UTF8);
    if (!haService.isActive() && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
        return syncPost(haService, NETWORKS, inputStr);
    }
    final NeutronNetwork net = (NeutronNetwork) jsonToModelEntity(inputStr, NeutronNetwork.class);
    adminService.createNetwork(net);
    UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(NETWORKS).path(net.getId());
    return created(locationBuilder.build()).build();
}
Also used : NeutronNetwork(org.openstack4j.openstack.networking.domain.NeutronNetwork) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with NeutronNetwork

use of org.openstack4j.openstack.networking.domain.NeutronNetwork in project onos by opennetworkinglab.

the class OpenstackNetworkWebResource method updateNetwork.

/**
 * Updates the network with the specified identifier.
 *
 * @param id network identifier
 * @param input network JSON input stream
 * @return 200 OK with the updated network, 400 BAD_REQUEST if the requested
 * network does not exist
 * @throws IOException exception
 * @onos.rsModel NeutronNetwork
 */
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNetwork(@PathParam("id") String id, InputStream input) throws IOException {
    log.trace(String.format(MESSAGE, "UPDATE " + id));
    String inputStr = IOUtils.toString(input, REST_UTF8);
    if (!haService.isActive() && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
        return syncPut(haService, NETWORKS, id, inputStr);
    }
    final NeutronNetwork net = (NeutronNetwork) jsonToModelEntity(inputStr, NeutronNetwork.class);
    adminService.updateNetwork(net);
    return status(Response.Status.OK).build();
}
Also used : NeutronNetwork(org.openstack4j.openstack.networking.domain.NeutronNetwork) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 NeutronNetwork (org.openstack4j.openstack.networking.domain.NeutronNetwork)2 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 UriBuilder (javax.ws.rs.core.UriBuilder)1