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.INeutronFirewallPolicyCRUD;
28 import org.opendaylight.neutron.spi.NeutronFirewallPolicy;
31 * Neutron Northbound REST APIs for Firewall Policies.<br>
32 * This class provides REST APIs for managing neutron Firewall Policies
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/firewall_policies")
48 public final class NeutronFirewallPolicyNorthbound extends
49 AbstractNeutronNorthbound<NeutronFirewallPolicy, NeutronFirewallPolicyRequest, INeutronFirewallPolicyCRUD> {
51 private static final String RESOURCE_NAME = "Firewall Policy";
54 protected String getResourceName() {
59 * Returns a list of all Firewall Policies.
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 Policy attributes
72 @QueryParam("id") String queryFirewallPolicyUUID,
73 @QueryParam("tenant_id") String queryFirewallPolicyTenantID,
74 @QueryParam("name") String queryFirewallPolicyName,
75 @QueryParam("shared") Boolean querySecurityPolicyIsShared,
76 @QueryParam("audited") Boolean querySecurityPolicyIsAudited,
78 @QueryParam("limit") String limit,
79 @QueryParam("marker") String marker,
80 @QueryParam("page_reverse") String pageReverse
81 // sorting not supported
83 INeutronFirewallPolicyCRUD firewallPolicyInterface = getNeutronCRUD();
84 List<NeutronFirewallPolicy> ans = new ArrayList<>();
85 for (NeutronFirewallPolicy nsg : firewallPolicyInterface.getAll()) {
86 if ((queryFirewallPolicyUUID == null || queryFirewallPolicyUUID.equals(nsg.getID()))
87 && (queryFirewallPolicyTenantID == null || queryFirewallPolicyTenantID.equals(nsg.getTenantID()))
88 && (queryFirewallPolicyName == null || queryFirewallPolicyName.equals(nsg.getName()))
89 && (querySecurityPolicyIsShared == null
90 || querySecurityPolicyIsShared.equals(nsg.getFirewallPolicyIsShared()))
91 && (querySecurityPolicyIsAudited == null
92 || querySecurityPolicyIsAudited.equals(nsg.getFirewallPolicyIsAudited()))) {
93 if (fields.size() > 0) {
94 ans.add(nsg.extractFields(fields));
100 //TODO: apply pagination to results
101 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallPolicyRequest(ans)).build();
105 * Returns a specific Firewall Policy.
108 @Path("{firewallPolicyUUID}")
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 showFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID,
118 @QueryParam("fields") List<String> fields) {
119 return show(firewallPolicyUUID, fields);
123 * Creates new Firewall Policy.
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 createFirewallPolicies(final NeutronFirewallPolicyRequest input) {
131 return create(input);
135 * Updates a Firewall Policy.
137 @Path("{firewallPolicyUUID}")
139 @Produces({ MediaType.APPLICATION_JSON })
140 @Consumes({ MediaType.APPLICATION_JSON })
141 //@TypeHint(OpenStackSubnets.class)
142 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
143 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
144 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
145 public Response updateFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID,
146 final NeutronFirewallPolicyRequest input) {
147 return update(firewallPolicyUUID, input);
151 * Deletes a Firewall Policy.
154 @Path("{firewallPolicyUUID}")
156 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
157 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
158 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
159 public Response deleteFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID) {
160 return delete(firewallPolicyUUID);