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;
13 import org.codehaus.enunciate.jaxrs.ResponseCode;
14 import org.codehaus.enunciate.jaxrs.StatusCodes;
15 import org.opendaylight.neutron.spi.INeutronFirewallCRUD;
16 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
17 import org.opendaylight.neutron.spi.NeutronFirewall;
19 import javax.ws.rs.Consumes;
20 import javax.ws.rs.DELETE;
21 import javax.ws.rs.GET;
22 import javax.ws.rs.POST;
23 import javax.ws.rs.PUT;
24 import javax.ws.rs.Path;
25 import javax.ws.rs.PathParam;
26 import javax.ws.rs.Produces;
27 import javax.ws.rs.QueryParam;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
30 import java.util.ArrayList;
31 import java.util.List;
34 * Neutron Northbound REST APIs for Firewall.<br>
35 * This class provides REST APIs for managing neutron Firewall
39 * Authentication scheme : <b>HTTP Basic</b><br>
40 * Authentication realm : <b>opendaylight</b><br>
41 * Transport : <b>HTTP and HTTPS</b><br>
43 * HTTPS Authentication is disabled by default. Administrator can enable it in
44 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
45 * trusted authority.<br>
47 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
50 @Path("/fw/firewalls")
51 public class NeutronFirewallNorthbound
52 extends AbstractNeutronNorthbound<NeutronFirewall, NeutronFirewallRequest, INeutronFirewallCRUD> {
54 private static final String RESOURCE_NAME = "Firewall";
57 protected String getResourceName() {
62 protected NeutronFirewall extractFields(NeutronFirewall o, List<String> fields) {
63 return o.extractFields(fields);
67 protected NeutronFirewallRequest newNeutronRequest(NeutronFirewall o) {
68 return new NeutronFirewallRequest(o);
72 protected INeutronFirewallCRUD getNeutronCRUD() {
73 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronFirewallCRUD(this);
74 if (answer.getFirewallInterface() == null) {
75 throw new ServiceUnavailableException(serviceUnavailable());
77 return answer.getFirewallInterface();
81 * Returns a list of all Firewalls */
83 @Produces({ MediaType.APPLICATION_JSON })
85 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
86 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
87 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
88 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
90 public Response listGroups(
92 @QueryParam("fields") List<String> fields,
93 // OpenStack firewall attributes
94 @QueryParam("id") String queryFirewallUUID,
95 @QueryParam("tenant_id") String queryFirewallTenantID,
96 @QueryParam("name") String queryFirewallName,
97 @QueryParam("admin_state_up") Boolean queryFirewallAdminStateIsUp,
98 @QueryParam("shared") Boolean queryFirewallIsShared,
99 @QueryParam("firewall_policy_id") String queryFirewallPolicyID,
101 @QueryParam("limit") String limit,
102 @QueryParam("marker") String marker,
103 @QueryParam("page_reverse") String pageReverse
104 // sorting not supported
106 INeutronFirewallCRUD firewallInterface = getNeutronCRUD();
107 List<NeutronFirewall> ans = new ArrayList<NeutronFirewall>();
108 for (NeutronFirewall nsg : firewallInterface.getAllNeutronFirewalls()) {
109 if ((queryFirewallUUID == null ||
110 queryFirewallUUID.equals(nsg.getID())) &&
111 (queryFirewallTenantID == null ||
112 queryFirewallTenantID.equals(nsg.getTenantID())) &&
113 (queryFirewallName == null ||
114 queryFirewallName.equals(nsg.getFirewallName())) &&
115 (queryFirewallAdminStateIsUp == null ||
116 queryFirewallAdminStateIsUp.equals(nsg.getFirewallAdminStateIsUp())) &&
117 (queryFirewallIsShared == null ||
118 queryFirewallIsShared.equals(nsg.getFirewallIsShared())) &&
119 (queryFirewallPolicyID == null ||
120 queryFirewallPolicyID.equals(nsg.getFirewallPolicyID()))) {
121 if (fields.size() > 0) {
122 ans.add(extractFields(nsg,fields));
128 //TODO: apply pagination to results
129 return Response.status(HttpURLConnection.HTTP_OK).entity(
130 new NeutronFirewallRequest(ans)).build();
134 * Returns a specific Firewall */
136 @Path("{firewallUUID}")
138 @Produces({ MediaType.APPLICATION_JSON })
140 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
142 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
143 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
144 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
145 public Response showFirewall(@PathParam("firewallUUID") String firewallUUID,
147 @QueryParam("fields") List<String> fields) {
148 return show(firewallUUID, fields);
152 * Creates new Firewall */
155 @Produces({ MediaType.APPLICATION_JSON })
156 @Consumes({ MediaType.APPLICATION_JSON })
158 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
159 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
160 public Response createFirewalls(final NeutronFirewallRequest input) {
161 return create(input);
165 * Updates a Firewall */
167 @Path("{firewallUUID}")
169 @Produces({ MediaType.APPLICATION_JSON })
170 @Consumes({ MediaType.APPLICATION_JSON })
172 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
173 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
174 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
175 public Response updateFirewall(
176 @PathParam("firewallUUID") String firewallUUID, final NeutronFirewallRequest input) {
177 return update(firewallUUID, input);
181 * Deletes a Firewall */
183 @Path("{firewallUUID}")
186 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
187 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
188 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
189 public Response deleteFirewall(
190 @PathParam("firewallUUID") String firewallUUID) {
191 return delete(firewallUUID);