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.INeutronFloatingIpCRUD;
29 import org.opendaylight.neutron.spi.NeutronFloatingIp;
30 import org.ops4j.pax.cdi.api.OsgiService;
33 * Neutron Northbound REST APIs for managing Neutron Floating IPs.
37 public final class NeutronFloatingIpsNorthbound
38 extends AbstractNeutronNorthbound<NeutronFloatingIp, NeutronFloatingIpRequest, INeutronFloatingIpCRUD> {
40 private static final String RESOURCE_NAME = "Floating IP";
43 public NeutronFloatingIpsNorthbound(@OsgiService INeutronFloatingIpCRUD neutronCRUD) {
48 protected String getResourceName() {
53 * Returns a list of all FloatingIps.
56 @Produces({ MediaType.APPLICATION_JSON })
57 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
58 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
59 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
60 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
61 public Response listFloatingIps(
63 @QueryParam("fields") List<String> fields,
64 // note: openstack isn't clear about filtering on lists, so we aren't handling them
65 @QueryParam("id") String queryID,
66 @QueryParam("floating_network_id") String queryFloatingNetworkId,
67 @QueryParam("port_id") String queryPortId,
68 @QueryParam("fixed_ip_address") String queryFixedIpAddress,
69 @QueryParam("floating_ip_address") String queryFloatingIpAddress,
70 @QueryParam("tenant_id") String queryTenantID,
71 @QueryParam("router_id") String queryRouterID,
72 @QueryParam("status") String queryStatus,
74 @QueryParam("limit") String limit,
75 @QueryParam("marker") String marker,
76 @QueryParam("page_reverse") String pageReverse
77 // sorting not supported
79 INeutronFloatingIpCRUD floatingIpInterface = getNeutronCRUD();
80 List<NeutronFloatingIp> allFloatingIps = floatingIpInterface.getAll();
81 List<NeutronFloatingIp> ans = new ArrayList<>();
82 for (NeutronFloatingIp floatingIp : allFloatingIps) {
83 //match filters: TODO provider extension and router extension
84 if ((queryID == null || queryID.equals(floatingIp.getID()))
85 && (queryFloatingNetworkId == null
86 || queryFloatingNetworkId.equals(floatingIp.getFloatingNetworkUUID()))
87 && (queryPortId == null || queryPortId.equals(floatingIp.getPortUUID()))
88 && (queryFixedIpAddress == null || queryFixedIpAddress.equals(floatingIp.getFixedIpAddress()))
89 && (queryFloatingIpAddress == null
90 || queryFloatingIpAddress.equals(floatingIp.getFloatingIpAddress()))
91 && (queryStatus == null || queryStatus.equals(floatingIp.getStatus()))
92 && (queryRouterID == null || queryRouterID.equals(floatingIp.getRouterUUID()))
93 && (queryTenantID == null || queryTenantID.equals(floatingIp.getTenantID()))) {
94 if (fields.size() > 0) {
95 ans.add(floatingIp.extractFields(fields));
101 //TODO: apply pagination to results
102 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFloatingIpRequest(ans)).build();
106 * Returns a specific FloatingIp.
108 @Path("{floatingipUUID}")
110 @Produces({ MediaType.APPLICATION_JSON })
111 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
112 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
113 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
114 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
115 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
116 public Response showFloatingIp(@PathParam("floatingipUUID") String floatingipUUID,
118 @QueryParam("fields") List<String> fields) {
119 return show(floatingipUUID, fields);
123 * Creates new FloatingIps.
126 @Produces({ MediaType.APPLICATION_JSON })
127 @Consumes({ MediaType.APPLICATION_JSON })
128 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
129 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
130 public Response createFloatingIps(final NeutronFloatingIpRequest input) {
131 return create(input);
135 * Updates a FloatingIp.
137 @Path("{floatingipUUID}")
139 @Produces({ MediaType.APPLICATION_JSON })
140 @Consumes({ MediaType.APPLICATION_JSON })
141 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
142 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
143 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
144 public Response updateFloatingIp(@PathParam("floatingipUUID") String floatingipUUID,
145 NeutronFloatingIpRequest input) {
146 return update(floatingipUUID, input);
150 * Deletes a FloatingIp.
152 @Path("{floatingipUUID}")
154 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
155 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
156 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
157 public Response deleteFloatingIp(@PathParam("floatingipUUID") String floatingipUUID) {
158 return delete(floatingipUUID);