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.Iterator;
14 import java.util.List;
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.NeutronRouter_Interface;
33 * Neutron Northbound REST APIs.<br>
34 * This class provides REST APIs for managing neutron routers
38 * Authentication scheme : <b>HTTP Basic</b><br>
39 * Authentication realm : <b>opendaylight</b><br>
40 * Transport : <b>HTTP and HTTPS</b><br>
42 * HTTPS Authentication is disabled by default. Administrator can enable it in
43 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
44 * trusted authority.<br>
46 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
51 public final class NeutronRoutersNorthbound
52 extends AbstractNeutronNorthbound<NeutronRouter, NeutronRouterRequest, INeutronRouterCRUD> {
53 static final String ROUTER_INTERFACE_STR = "network:router_interface";
54 static final String ROUTER_GATEWAY_STR = "network:router_gateway";
55 private static final String RESOURCE_NAME = "Router";
58 protected String getResourceName() {
63 * 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 Iterator<NeutronRouter> i = allRouters.iterator();
96 NeutronRouter oSS = i.next();
97 if ((queryID == null || queryID.equals(oSS.getID()))
98 && (queryName == null || queryName.equals(oSS.getName()))
99 && (queryAdminStateUp == null || queryAdminStateUp.equals(oSS.getAdminStateUp()))
100 && (queryStatus == null || queryStatus.equals(oSS.getStatus()))
101 && (queryExternalGatewayInfo == null
102 || queryExternalGatewayInfo.equals(oSS.getExternalGatewayInfo()))
103 && (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {
104 if (fields.size() > 0) {
105 ans.add(oSS.extractFields(fields));
111 //TODO: apply pagination to results
112 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronRouterRequest(ans)).build();
116 * Returns a specific Router */
118 @Path("{routerUUID}")
120 @Produces({ MediaType.APPLICATION_JSON })
121 //@TypeHint(OpenStackRouters.class)
122 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
123 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
124 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
125 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
126 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
127 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
128 public Response showRouter(@PathParam("routerUUID") String routerUUID,
130 @QueryParam("fields") List<String> fields) {
131 return show(routerUUID, fields);
135 * Creates new Routers */
138 @Produces({ MediaType.APPLICATION_JSON })
139 @Consumes({ MediaType.APPLICATION_JSON })
140 //@TypeHint(OpenStackRouters.class)
141 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
142 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
143 public Response createRouters(final NeutronRouterRequest input) {
144 return create(input);
148 protected void updateDelta(String uuid, NeutronRouter delta, NeutronRouter original) {
150 delta.setTenantID(original.getTenantID());
154 * Updates a Router */
156 @Path("{routerUUID}")
158 @Produces({ MediaType.APPLICATION_JSON })
159 @Consumes({ MediaType.APPLICATION_JSON })
160 //@TypeHint(OpenStackRouters.class)
161 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
162 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
163 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
164 public Response updateRouter(@PathParam("routerUUID") String routerUUID, NeutronRouterRequest input) {
165 return update(routerUUID, input);
169 * Deletes a Router */
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 */
183 @Path("{routerUUID}/add_router_interface")
185 @Produces({ MediaType.APPLICATION_JSON })
186 @Consumes({ MediaType.APPLICATION_JSON })
187 //@TypeHint(OpenStackRouterInterfaces.class)
188 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
189 public Response addRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouter_Interface input) {
190 // Do nothing. Keep this interface for compatibility
191 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
194 @Path("{routerUUID}/remove_router_interface")
196 @Produces({ MediaType.APPLICATION_JSON })
197 @Consumes({ MediaType.APPLICATION_JSON })
198 //@TypeHint(OpenStackRouterInterfaces.class)
199 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
200 public Response removeRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouter_Interface input) {
201 // Do nothing. Keep this interface for compatibility
202 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();