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
9 package org.opendaylight.neutron.northbound.api;
11 import java.net.HttpURLConnection;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.opendaylight.neutron.spi.INeutronRouterCRUD;
28 import org.opendaylight.neutron.spi.NeutronRouter;
29 import org.opendaylight.neutron.spi.NeutronRouterInterface;
32 * Neutron Northbound REST APIs.<br>
33 * This class provides REST APIs for managing neutron routers
37 * Authentication scheme : <b>HTTP Basic</b><br>
38 * Authentication realm : <b>opendaylight</b><br>
39 * Transport : <b>HTTP and HTTPS</b><br>
41 * HTTPS Authentication is disabled by default. Administrator can enable it in
42 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43 * trusted authority.<br>
45 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
50 public final class NeutronRoutersNorthbound
51 extends AbstractNeutronNorthbound<NeutronRouter, NeutronRouterRequest, INeutronRouterCRUD> {
52 static final String ROUTER_INTERFACE_STR = "network:router_interface";
53 static final String ROUTER_GATEWAY_STR = "network:router_gateway";
54 private static final String RESOURCE_NAME = "Router";
57 protected String getResourceName() {
62 * Returns a list of all Routers.
66 @Produces({ MediaType.APPLICATION_JSON })
67 //@TypeHint(OpenStackRouters.class)
68 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
69 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
70 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
71 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
72 public Response listRouters(
74 @QueryParam("fields") List<String> fields,
75 // note: openstack isn't clear about filtering on lists, so we aren't handling them
76 @QueryParam("id") String queryID,
77 @QueryParam("name") String queryName,
78 @QueryParam("admin_state_up") Boolean queryAdminStateUp,
79 @QueryParam("status") String queryStatus,
80 @QueryParam("tenant_id") String queryTenantID,
81 @QueryParam("external_gateway_info") String queryExternalGatewayInfo,
83 @QueryParam("limit") String limit,
84 @QueryParam("marker") String marker,
85 @QueryParam("page_reverse") String pageReverse
86 // sorting not supported
88 INeutronRouterCRUD routerInterface = getNeutronCRUD();
89 if (routerInterface == null) {
90 throw new ServiceUnavailableException(serviceUnavailable());
92 List<NeutronRouter> allRouters = routerInterface.getAll();
93 List<NeutronRouter> ans = new ArrayList<>();
94 for (NeutronRouter router : allRouters) {
95 if ((queryID == null || queryID.equals(router.getID()))
96 && (queryName == null || queryName.equals(router.getName()))
97 && (queryAdminStateUp == null || queryAdminStateUp.equals(router.getAdminStateUp()))
98 && (queryStatus == null || queryStatus.equals(router.getStatus()))
99 && (queryTenantID == null || queryTenantID.equals(router.getTenantID()))) {
100 if (fields.size() > 0) {
101 ans.add(router.extractFields(fields));
107 //TODO: apply pagination to results
108 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronRouterRequest(ans)).build();
112 * Returns a specific Router.
115 @Path("{routerUUID}")
117 @Produces({ MediaType.APPLICATION_JSON })
118 //@TypeHint(OpenStackRouters.class)
119 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
121 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
122 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
123 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
124 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
125 public Response showRouter(@PathParam("routerUUID") String routerUUID,
127 @QueryParam("fields") List<String> fields) {
128 return show(routerUUID, fields);
132 * Creates new Routers.
136 @Produces({ MediaType.APPLICATION_JSON })
137 @Consumes({ MediaType.APPLICATION_JSON })
138 //@TypeHint(OpenStackRouters.class)
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
140 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
141 public Response createRouters(final NeutronRouterRequest input) {
142 return create(input);
146 protected void updateDelta(String uuid, NeutronRouter delta, NeutronRouter original) {
148 delta.setTenantID(original.getTenantID());
155 @Path("{routerUUID}")
157 @Produces({ MediaType.APPLICATION_JSON })
158 @Consumes({ MediaType.APPLICATION_JSON })
159 //@TypeHint(OpenStackRouters.class)
160 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
161 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
162 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
163 public Response updateRouter(@PathParam("routerUUID") String routerUUID, NeutronRouterRequest input) {
164 return update(routerUUID, input);
171 @Path("{routerUUID}")
173 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
174 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
175 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
176 public Response deleteRouter(@PathParam("routerUUID") String routerUUID) {
177 return delete(routerUUID);
181 * Adds an interface to a router.
184 @Path("{routerUUID}/add_router_interface")
186 @Produces({ MediaType.APPLICATION_JSON })
187 @Consumes({ MediaType.APPLICATION_JSON })
188 //@TypeHint(OpenStackRouterInterfaces.class)
189 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
190 public Response addRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouterInterface input) {
191 // Do nothing. Keep this interface for compatibility
192 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
195 @Path("{routerUUID}/remove_router_interface")
197 @Produces({ MediaType.APPLICATION_JSON })
198 @Consumes({ MediaType.APPLICATION_JSON })
199 //@TypeHint(OpenStackRouterInterfaces.class)
200 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
201 public Response removeRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouterInterface input) {
202 // Do nothing. Keep this interface for compatibility
203 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();