2 * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.neutron.northbound.api;
10 import java.net.HttpURLConnection;
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.DELETE;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.POST;
19 import javax.ws.rs.PUT;
20 import javax.ws.rs.Path;
21 import javax.ws.rs.PathParam;
22 import javax.ws.rs.Produces;
23 import javax.ws.rs.QueryParam;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import org.codehaus.enunciate.jaxrs.ResponseCode;
27 import org.codehaus.enunciate.jaxrs.StatusCodes;
28 import org.opendaylight.neutron.spi.INeutronRouterCRUD;
29 import org.opendaylight.neutron.spi.NeutronRouter;
30 import org.opendaylight.neutron.spi.NeutronRouterInterface;
31 import org.ops4j.pax.cdi.api.OsgiService;
34 * Neutron Northbound REST APIs for managing neutron routers.
38 public final class NeutronRoutersNorthbound
39 extends AbstractNeutronNorthbound<NeutronRouter, NeutronRouterRequest, INeutronRouterCRUD> {
41 private static final String RESOURCE_NAME = "Router";
44 public NeutronRoutersNorthbound(@OsgiService INeutronRouterCRUD neutronCRUD) {
49 protected String getResourceName() {
54 * Returns a list of all Routers.
57 @Produces({ MediaType.APPLICATION_JSON })
58 //@TypeHint(OpenStackRouters.class)
59 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
60 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
61 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
62 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
63 public Response listRouters(
65 @QueryParam("fields") List<String> fields,
66 // note: openstack isn't clear about filtering on lists, so we aren't handling them
67 @QueryParam("id") String queryID,
68 @QueryParam("name") String queryName,
69 @QueryParam("admin_state_up") Boolean queryAdminStateUp,
70 @QueryParam("status") String queryStatus,
71 @QueryParam("tenant_id") String queryTenantID,
72 @QueryParam("external_gateway_info") String queryExternalGatewayInfo,
74 @QueryParam("limit") String limit,
75 @QueryParam("marker") String marker,
76 @QueryParam("page_reverse") String pageReverse
77 // sorting not supported
79 INeutronRouterCRUD routerInterface = getNeutronCRUD();
80 List<NeutronRouter> allRouters = routerInterface.getAll();
81 List<NeutronRouter> ans = new ArrayList<>();
82 for (NeutronRouter router : allRouters) {
83 if ((queryID == null || queryID.equals(router.getID()))
84 && (queryName == null || queryName.equals(router.getName()))
85 && (queryAdminStateUp == null || queryAdminStateUp.equals(router.getAdminStateUp()))
86 && (queryStatus == null || queryStatus.equals(router.getStatus()))
87 && (queryTenantID == null || queryTenantID.equals(router.getTenantID()))) {
88 if (fields.size() > 0) {
89 ans.add(router.extractFields(fields));
95 //TODO: apply pagination to results
96 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronRouterRequest(ans)).build();
100 * Returns a specific Router.
102 @Path("{routerUUID}")
104 @Produces({ MediaType.APPLICATION_JSON })
105 //@TypeHint(OpenStackRouters.class)
106 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
107 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
108 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
109 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
110 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
111 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
112 public Response showRouter(@PathParam("routerUUID") String routerUUID,
114 @QueryParam("fields") List<String> fields) {
115 return show(routerUUID, fields);
119 * Creates new Routers.
122 @Produces({ MediaType.APPLICATION_JSON })
123 @Consumes({ MediaType.APPLICATION_JSON })
124 //@TypeHint(OpenStackRouters.class)
125 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
126 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
127 public Response createRouters(final NeutronRouterRequest input) {
128 return create(input);
132 protected void updateDelta(String uuid, NeutronRouter delta, NeutronRouter original) {
134 delta.setTenantID(original.getTenantID());
140 @Path("{routerUUID}")
142 @Produces({ MediaType.APPLICATION_JSON })
143 @Consumes({ MediaType.APPLICATION_JSON })
144 //@TypeHint(OpenStackRouters.class)
145 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
146 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
147 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
148 public Response updateRouter(@PathParam("routerUUID") String routerUUID, NeutronRouterRequest input) {
149 return update(routerUUID, input);
155 @Path("{routerUUID}")
157 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
158 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
159 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
160 public Response deleteRouter(@PathParam("routerUUID") String routerUUID) {
161 return delete(routerUUID);
165 * Adds an interface to a router.
167 @Path("{routerUUID}/add_router_interface")
169 @Produces({ MediaType.APPLICATION_JSON })
170 @Consumes({ MediaType.APPLICATION_JSON })
171 //@TypeHint(OpenStackRouterInterfaces.class)
172 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
173 public Response addRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouterInterface input) {
174 // Do nothing. Keep this interface for compatibility
175 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
178 @Path("{routerUUID}/remove_router_interface")
180 @Produces({ MediaType.APPLICATION_JSON })
181 @Consumes({ MediaType.APPLICATION_JSON })
182 //@TypeHint(OpenStackRouterInterfaces.class)
183 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
184 public Response removeRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouterInterface input) {
185 // Do nothing. Keep this interface for compatibility
186 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();