blob: 7683b0ca36e50c1e0c5f54955b87fc573b0b0dd7 [file] [log] [blame]
sanghoshin94872a12015-10-16 18:04:34 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
sanghoshin94872a12015-10-16 18:04:34 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
sangho0c2a3da2016-02-16 13:39:07 +090016package org.onosproject.openstacknetworking.web;
sanghoshin94872a12015-10-16 18:04:34 +090017
sanghoc853a722016-07-04 21:10:42 +090018import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.openstackinterface.OpenstackPort;
21import org.onosproject.openstackinterface.web.OpenstackPortCodec;
Hyunsun Moon05400872017-02-07 17:11:25 +090022import org.onosproject.openstacknetworking.api.OpenstackSecurityGroupService;
sanghoshin94872a12015-10-16 18:04:34 +090023import org.onosproject.rest.AbstractWebResource;
sanghoc853a722016-07-04 21:10:42 +090024import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
sanghoshin94872a12015-10-16 18:04:34 +090026
27import javax.ws.rs.Consumes;
28import javax.ws.rs.DELETE;
29import javax.ws.rs.POST;
30import javax.ws.rs.PUT;
31import javax.ws.rs.Path;
sanghoshin65723ae2015-11-17 22:07:21 +090032import javax.ws.rs.PathParam;
sanghoshin94872a12015-10-16 18:04:34 +090033import javax.ws.rs.Produces;
34import javax.ws.rs.core.MediaType;
35import javax.ws.rs.core.Response;
sanghoc853a722016-07-04 21:10:42 +090036import java.io.IOException;
sanghoshin94872a12015-10-16 18:04:34 +090037import java.io.InputStream;
38
sanghoc853a722016-07-04 21:10:42 +090039import static com.google.common.base.Preconditions.checkNotNull;
40
sanghoshinf25d2e02015-11-11 23:07:17 +090041/**
42 * Handles Rest API call from Neutron ML2 plugin.
43 */
sanghoshin94872a12015-10-16 18:04:34 +090044@Path("ports")
45public class OpenstackPortWebResource extends AbstractWebResource {
sanghoc853a722016-07-04 21:10:42 +090046 private final Logger log = LoggerFactory.getLogger(getClass());
47
48 private static final OpenstackPortCodec PORT_CODEC
49 = new OpenstackPortCodec();
sanghoshin94872a12015-10-16 18:04:34 +090050
sanghoshin94872a12015-10-16 18:04:34 +090051 @POST
52 @Consumes(MediaType.APPLICATION_JSON)
53 @Produces(MediaType.APPLICATION_JSON)
54 public Response createPorts(InputStream input) {
Hyunsun Moonb974fca2016-06-30 21:20:39 -070055 return Response.status(Response.Status.OK).build();
sanghoshin94872a12015-10-16 18:04:34 +090056 }
57
sanghoshin65723ae2015-11-17 22:07:21 +090058 @Path("{portUUID}")
sanghoshin94872a12015-10-16 18:04:34 +090059 @DELETE
jskim3d66aca2016-09-22 16:45:10 +090060 @Consumes(MediaType.APPLICATION_JSON)
sanghoshin65723ae2015-11-17 22:07:21 +090061 public Response deletePorts(@PathParam("portUUID") String id) {
Jian Lic2a542b2016-05-10 11:48:19 -070062 return Response.noContent().build();
sanghoshin94872a12015-10-16 18:04:34 +090063 }
64
65 @PUT
66 @Path("{id}")
67 @Consumes(MediaType.APPLICATION_JSON)
68 @Produces(MediaType.APPLICATION_JSON)
sanghoc853a722016-07-04 21:10:42 +090069 public Response updatePorts(@PathParam("id") String id, InputStream input) {
70 checkNotNull(input);
71 checkNotNull(id);
72
73 try {
74 ObjectMapper mapper = new ObjectMapper();
75 ObjectNode portNode = (ObjectNode) mapper.readTree(input);
76 OpenstackPort osPort = PORT_CODEC.decode(portNode, this);
77
78 OpenstackSecurityGroupService sgService
79 = getService(OpenstackSecurityGroupService.class);
80 sgService.updateSecurityGroup(osPort);
81
82 return Response.status(Response.Status.OK).build();
sanghoc853a722016-07-04 21:10:42 +090083 } catch (IOException e) {
84 log.error("UpdatePort post process failed due to {}", e.getMessage());
85
86 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
87 .build();
88 }
sanghoshin94872a12015-10-16 18:04:34 +090089 }
90}