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
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.DefaultValue;
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.Context;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import javax.ws.rs.core.UriInfo;
28 import org.codehaus.enunciate.jaxrs.ResponseCode;
29 import org.codehaus.enunciate.jaxrs.StatusCodes;
30 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
31 import org.opendaylight.neutron.spi.NeutronSubnet;
34 * Neutron Northbound REST APIs for Subnets.<br>
35 * This class provides REST APIs for managing neutron Subnets
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
52 public final class NeutronSubnetsNorthbound
53 extends AbstractNeutronNorthbound<NeutronSubnet, NeutronSubnetRequest, INeutronSubnetCRUD> {
54 private static final String RESOURCE_NAME = "Subnet";
57 protected String getResourceName() {
65 * Returns a list of all Subnets.
68 @Produces({ MediaType.APPLICATION_JSON })
69 //@TypeHint(OpenStackSubnets.class)
70 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
71 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
72 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
73 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
74 public Response listSubnets(
76 @QueryParam("fields") List<String> fields,
77 // note: openstack isn't clear about filtering on lists, so we aren't handling them
78 @QueryParam("id") String queryID,
79 @QueryParam("network_id") String queryNetworkID,
80 @QueryParam("name") String queryName,
81 @QueryParam("ip_version") Integer queryIPVersion,
82 @QueryParam("cidr") String queryCIDR,
83 @QueryParam("gateway_ip") String queryGatewayIp,
84 @QueryParam("enable_dhcp") Boolean queryEnableDHCP,
85 @QueryParam("tenant_id") String queryTenantID,
86 @QueryParam("ipv6_address_mode") String queryIpV6AddressMode,
87 @QueryParam("ipv6_ra_mode") String queryIpV6RaMode,
89 @QueryParam("limit") Integer limit,
90 @QueryParam("marker") String marker,
91 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
92 // sorting not supported
94 INeutronSubnetCRUD subnetInterface = getNeutronCRUD();
95 List<NeutronSubnet> allSubnets = subnetInterface.getAll();
96 List<NeutronSubnet> ans = new ArrayList<>();
97 for (NeutronSubnet subnet : allSubnets) {
98 if ((queryID == null || queryID.equals(subnet.getID()))
99 && (queryNetworkID == null || queryNetworkID.equals(subnet.getNetworkUUID()))
100 && (queryName == null || queryName.equals(subnet.getName()))
101 && (queryIPVersion == null || queryIPVersion.equals(subnet.getIpVersion()))
102 && (queryCIDR == null || queryCIDR.equals(subnet.getCidr()))
103 && (queryGatewayIp == null || queryGatewayIp.equals(subnet.getGatewayIp()))
104 && (queryEnableDHCP == null || queryEnableDHCP.equals(subnet.getEnableDHCP()))
105 && (queryTenantID == null || queryTenantID.equals(subnet.getTenantID()))
106 && (queryIpV6AddressMode == null || queryIpV6AddressMode.equals(subnet.getIpV6AddressMode()))
107 && (queryIpV6RaMode == null || queryIpV6RaMode.equals(subnet.getIpV6RaMode()))) {
108 if (fields.size() > 0) {
109 ans.add(subnet.extractFields(fields));
116 if (limit != null && ans.size() > 1) {
117 // Return a paginated request
118 NeutronSubnetRequest request = (NeutronSubnetRequest) PaginatedRequestFactory.createRequest(limit, marker,
119 pageReverse, uriInfo, ans, NeutronSubnet.class);
120 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
123 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSubnetRequest(ans)).build();
127 * Returns a specific Subnet.
130 @Path("{subnetUUID}")
132 @Produces({ MediaType.APPLICATION_JSON })
133 //@TypeHint(OpenStackSubnets.class)
134 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
135 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
136 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
137 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
139 public Response showSubnet(@PathParam("subnetUUID") String subnetUUID,
141 @QueryParam("fields") List<String> fields) {
142 return show(subnetUUID, fields);
146 * Creates new Subnets.
150 @Produces({ MediaType.APPLICATION_JSON })
151 @Consumes({ MediaType.APPLICATION_JSON })
152 //@TypeHint(OpenStackSubnets.class)
153 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
154 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
155 public Response createSubnets(final NeutronSubnetRequest input) {
156 return create(input);
160 protected void updateDelta(String uuid, NeutronSubnet delta, NeutronSubnet original) {
162 * note: what we get appears to not be a delta, but rather a
163 * complete updated object. So, that needs to be sent down to
168 delta.setNetworkUUID(original.getNetworkUUID());
169 delta.setTenantID(original.getTenantID());
170 delta.setIpVersion(original.getIpVersion());
171 delta.setCidr(original.getCidr());
178 @Path("{subnetUUID}")
180 @Produces({ MediaType.APPLICATION_JSON })
181 @Consumes({ MediaType.APPLICATION_JSON })
182 //@TypeHint(OpenStackSubnets.class)
183 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
184 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
185 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
186 public Response updateSubnet(@PathParam("subnetUUID") String subnetUUID, final NeutronSubnetRequest input) {
187 return update(subnetUUID, input);
194 @Path("{subnetUUID}")
196 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
197 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
198 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
199 public Response deleteSubnet(@PathParam("subnetUUID") String subnetUUID) {
200 return delete(subnetUUID);