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.INeutronFloatingIPCRUD;
28 import org.opendaylight.neutron.spi.NeutronFloatingIP;
31 * Neutron Northbound REST APIs.<br>
32 * This class provides REST APIs for managing Neutron Floating IPs
36 * Authentication scheme : <b>HTTP Basic</b><br>
37 * Authentication realm : <b>opendaylight</b><br>
38 * Transport : <b>HTTP and HTTPS</b><br>
40 * HTTPS Authentication is disabled by default. Administrator can enable it in
41 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
42 * trusted authority.<br>
44 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
49 public final class NeutronFloatingIPsNorthbound
50 extends AbstractNeutronNorthbound<NeutronFloatingIP, NeutronFloatingIPRequest, INeutronFloatingIPCRUD> {
51 private static final String RESOURCE_NAME = "Floating IP";
54 protected String getResourceName() {
59 * Returns a list of all FloatingIPs.
63 @Produces({ MediaType.APPLICATION_JSON })
64 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
65 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
66 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
67 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
68 public Response listFloatingIPs(
70 @QueryParam("fields") List<String> fields,
71 // note: openstack isn't clear about filtering on lists, so we aren't handling them
72 @QueryParam("id") String queryID,
73 @QueryParam("floating_network_id") String queryFloatingNetworkId,
74 @QueryParam("port_id") String queryPortId,
75 @QueryParam("fixed_ip_address") String queryFixedIPAddress,
76 @QueryParam("floating_ip_address") String queryFloatingIPAddress,
77 @QueryParam("tenant_id") String queryTenantID,
78 @QueryParam("router_id") String queryRouterID,
79 @QueryParam("status") String queryStatus,
81 @QueryParam("limit") String limit,
82 @QueryParam("marker") String marker,
83 @QueryParam("page_reverse") String pageReverse
84 // sorting not supported
86 INeutronFloatingIPCRUD floatingIPInterface = getNeutronCRUD();
87 List<NeutronFloatingIP> allFloatingIPs = floatingIPInterface.getAll();
88 List<NeutronFloatingIP> ans = new ArrayList<>();
89 for (NeutronFloatingIP floatingIp : allFloatingIPs) {
90 //match filters: TODO provider extension and router extension
91 if ((queryID == null || queryID.equals(floatingIp.getID()))
92 && (queryFloatingNetworkId == null
93 || queryFloatingNetworkId.equals(floatingIp.getFloatingNetworkUUID()))
94 && (queryPortId == null || queryPortId.equals(floatingIp.getPortUUID()))
95 && (queryFixedIPAddress == null || queryFixedIPAddress.equals(floatingIp.getFixedIPAddress()))
96 && (queryFloatingIPAddress == null
97 || queryFloatingIPAddress.equals(floatingIp.getFloatingIPAddress()))
98 && (queryStatus == null || queryStatus.equals(floatingIp.getStatus()))
99 && (queryRouterID == null || queryRouterID.equals(floatingIp.getRouterUUID()))
100 && (queryTenantID == null || queryTenantID.equals(floatingIp.getTenantID()))) {
101 if (fields.size() > 0) {
102 ans.add(floatingIp.extractFields(fields));
108 //TODO: apply pagination to results
109 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFloatingIPRequest(ans)).build();
113 * Returns a specific FloatingIP.
116 @Path("{floatingipUUID}")
118 @Produces({ MediaType.APPLICATION_JSON })
119 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
121 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
122 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
123 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
124 public Response showFloatingIP(@PathParam("floatingipUUID") String floatingipUUID,
126 @QueryParam("fields") List<String> fields) {
127 return show(floatingipUUID, fields);
131 * Creates new FloatingIPs.
135 @Produces({ MediaType.APPLICATION_JSON })
136 @Consumes({ MediaType.APPLICATION_JSON })
137 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
139 public Response createFloatingIPs(final NeutronFloatingIPRequest input) {
140 return create(input);
144 * Updates a FloatingIP.
147 @Path("{floatingipUUID}")
149 @Produces({ MediaType.APPLICATION_JSON })
150 @Consumes({ MediaType.APPLICATION_JSON })
151 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
152 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
153 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
154 public Response updateFloatingIP(@PathParam("floatingipUUID") String floatingipUUID,
155 NeutronFloatingIPRequest input) {
156 return update(floatingipUUID, input);
160 * Deletes a FloatingIP.
163 @Path("{floatingipUUID}")
165 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
166 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
167 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
168 public Response deleteFloatingIP(@PathParam("floatingipUUID") String floatingipUUID) {
169 return delete(floatingipUUID);