2 * Copyright (c) 2014, 2015 Red Hat, Inc. 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.INeutronFirewallCRUD;
28 import org.opendaylight.neutron.spi.NeutronFirewall;
31 * Neutron Northbound REST APIs for Firewall.<br>
32 * This class provides REST APIs for managing neutron Firewall
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
47 @Path("/fw/firewalls")
48 public final class NeutronFirewallNorthbound
49 extends AbstractNeutronNorthbound<NeutronFirewall, NeutronFirewallRequest, INeutronFirewallCRUD> {
51 private static final String RESOURCE_NAME = "Firewall";
54 protected String getResourceName() {
59 * Returns a list of all Firewalls.
62 @Produces({ MediaType.APPLICATION_JSON })
63 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
64 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
65 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
66 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
68 public Response listGroups(
70 @QueryParam("fields") List<String> fields,
71 // OpenStack firewall attributes
72 @QueryParam("id") String queryFirewallUUID,
73 @QueryParam("tenant_id") String queryFirewallTenantID,
74 @QueryParam("name") String queryFirewallName,
75 @QueryParam("admin_state_up") Boolean queryFirewallAdminStateIsUp,
76 @QueryParam("shared") Boolean queryFirewallIsShared,
77 @QueryParam("firewall_policy_id") String queryFirewallPolicyID,
79 @QueryParam("limit") String limit,
80 @QueryParam("marker") String marker,
81 @QueryParam("page_reverse") String pageReverse
82 // sorting not supported
84 INeutronFirewallCRUD firewallInterface = getNeutronCRUD();
85 List<NeutronFirewall> ans = new ArrayList<>();
86 for (NeutronFirewall nsg : firewallInterface.getAll()) {
87 if ((queryFirewallUUID == null || queryFirewallUUID.equals(nsg.getID()))
88 && (queryFirewallTenantID == null || queryFirewallTenantID.equals(nsg.getTenantID()))
89 && (queryFirewallName == null || queryFirewallName.equals(nsg.getName()))
90 && (queryFirewallAdminStateIsUp == null
91 || queryFirewallAdminStateIsUp.equals(nsg.getFirewallAdminStateIsUp()))
92 && (queryFirewallIsShared == null || queryFirewallIsShared.equals(nsg.getFirewallIsShared()))
93 && (queryFirewallPolicyID == null || queryFirewallPolicyID.equals(nsg.getFirewallPolicyID()))) {
94 if (fields.size() > 0) {
95 ans.add(nsg.extractFields(fields));
101 //TODO: apply pagination to results
102 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallRequest(ans)).build();
106 * Returns a specific Firewall.
109 @Path("{firewallUUID}")
111 @Produces({ MediaType.APPLICATION_JSON })
112 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
113 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
114 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
115 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
116 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
117 public Response showFirewall(@PathParam("firewallUUID") String firewallUUID,
119 @QueryParam("fields") List<String> fields) {
120 return show(firewallUUID, fields);
124 * Creates new Firewall.
128 @Produces({ MediaType.APPLICATION_JSON })
129 @Consumes({ MediaType.APPLICATION_JSON })
130 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
131 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
132 public Response createFirewalls(final NeutronFirewallRequest input) {
133 return create(input);
137 * Updates a Firewall.
140 @Path("{firewallUUID}")
142 @Produces({ MediaType.APPLICATION_JSON })
143 @Consumes({ MediaType.APPLICATION_JSON })
144 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
145 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
146 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
147 public Response updateFirewall(@PathParam("firewallUUID") String firewallUUID, final NeutronFirewallRequest input) {
148 return update(firewallUUID, input);
152 * Deletes a Firewall.
155 @Path("{firewallUUID}")
157 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
158 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
159 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
160 public Response deleteFirewall(@PathParam("firewallUUID") String firewallUUID) {
161 return delete(firewallUUID);