Search in sources :

Example 1 with NeutronRouter

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

the class OpenstackRouterWebResource method updateRouter.

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

Example 2 with NeutronRouter

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

the class OpenstackRouterWebResource method createRouter.

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

Aggregations

Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 NeutronRouter (org.openstack4j.openstack.networking.domain.NeutronRouter)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