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.ws.rs.Consumes;
14 import javax.ws.rs.DELETE;
15 import javax.ws.rs.GET;
16 import javax.ws.rs.POST;
17 import javax.ws.rs.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.opendaylight.neutron.spi.INeutronFloatingIpCRUD;
27 import org.opendaylight.neutron.spi.NeutronFloatingIp;
30 * Neutron Northbound REST APIs for managing Neutron Floating IPs.
33 public final class NeutronFloatingIpsNorthbound
34 extends AbstractNeutronNorthbound<NeutronFloatingIp, NeutronFloatingIpRequest, INeutronFloatingIpCRUD> {
36 private static final String RESOURCE_NAME = "Floating IP";
39 protected String getResourceName() {
44 * Returns a list of all FloatingIps.
47 @Produces({ MediaType.APPLICATION_JSON })
48 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
49 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
50 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
51 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
52 public Response listFloatingIps(
54 @QueryParam("fields") List<String> fields,
55 // note: openstack isn't clear about filtering on lists, so we aren't handling them
56 @QueryParam("id") String queryID,
57 @QueryParam("floating_network_id") String queryFloatingNetworkId,
58 @QueryParam("port_id") String queryPortId,
59 @QueryParam("fixed_ip_address") String queryFixedIpAddress,
60 @QueryParam("floating_ip_address") String queryFloatingIpAddress,
61 @QueryParam("tenant_id") String queryTenantID,
62 @QueryParam("router_id") String queryRouterID,
63 @QueryParam("status") String queryStatus,
65 @QueryParam("limit") String limit,
66 @QueryParam("marker") String marker,
67 @QueryParam("page_reverse") String pageReverse
68 // sorting not supported
70 INeutronFloatingIpCRUD floatingIpInterface = getNeutronCRUD();
71 List<NeutronFloatingIp> allFloatingIps = floatingIpInterface.getAll();
72 List<NeutronFloatingIp> ans = new ArrayList<>();
73 for (NeutronFloatingIp floatingIp : allFloatingIps) {
74 //match filters: TODO provider extension and router extension
75 if ((queryID == null || queryID.equals(floatingIp.getID()))
76 && (queryFloatingNetworkId == null
77 || queryFloatingNetworkId.equals(floatingIp.getFloatingNetworkUUID()))
78 && (queryPortId == null || queryPortId.equals(floatingIp.getPortUUID()))
79 && (queryFixedIpAddress == null || queryFixedIpAddress.equals(floatingIp.getFixedIpAddress()))
80 && (queryFloatingIpAddress == null
81 || queryFloatingIpAddress.equals(floatingIp.getFloatingIpAddress()))
82 && (queryStatus == null || queryStatus.equals(floatingIp.getStatus()))
83 && (queryRouterID == null || queryRouterID.equals(floatingIp.getRouterUUID()))
84 && (queryTenantID == null || queryTenantID.equals(floatingIp.getTenantID()))) {
85 if (fields.size() > 0) {
86 ans.add(floatingIp.extractFields(fields));
92 //TODO: apply pagination to results
93 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFloatingIpRequest(ans)).build();
97 * Returns a specific FloatingIp.
99 @Path("{floatingipUUID}")
101 @Produces({ MediaType.APPLICATION_JSON })
102 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
103 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
104 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
105 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
106 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
107 public Response showFloatingIp(@PathParam("floatingipUUID") String floatingipUUID,
109 @QueryParam("fields") List<String> fields) {
110 return show(floatingipUUID, fields);
114 * Creates new FloatingIps.
117 @Produces({ MediaType.APPLICATION_JSON })
118 @Consumes({ MediaType.APPLICATION_JSON })
119 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121 public Response createFloatingIps(final NeutronFloatingIpRequest input) {
122 return create(input);
126 * Updates a FloatingIp.
128 @Path("{floatingipUUID}")
130 @Produces({ MediaType.APPLICATION_JSON })
131 @Consumes({ MediaType.APPLICATION_JSON })
132 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
133 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
134 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
135 public Response updateFloatingIp(@PathParam("floatingipUUID") String floatingipUUID,
136 NeutronFloatingIpRequest input) {
137 return update(floatingipUUID, input);
141 * Deletes a FloatingIp.
143 @Path("{floatingipUUID}")
145 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
146 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
147 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
148 public Response deleteFloatingIp(@PathParam("floatingipUUID") String floatingipUUID) {
149 return delete(floatingipUUID);