2 * Copyright (C) 2013 Red Hat, Inc.
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
8 * Authors : Madhu Venugopal, Brent Salisbury
10 package org.opendaylight.ovsdb.neutron;
12 import java.net.HttpURLConnection;
14 import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
15 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Handle requests for Neutron Port.
22 public class PortHandler extends BaseHandler
23 implements INeutronPortAware {
28 static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
31 * Invoked when a port creation is requested
32 * to indicate if the specified port can be created.
34 * @param port An instance of proposed new Port object.
35 * @return A HTTP status code to the creation request.
38 public int canCreatePort(NeutronPort port) {
39 return HttpURLConnection.HTTP_CREATED;
43 * Invoked to take action after a port has been created.
45 * @param port An instance of new Neutron Port object.
48 public void neutronPortCreated(NeutronPort port) {
49 int result = canCreatePort(port);
50 if (result != HttpURLConnection.HTTP_CREATED) {
51 logger.error(" Port create validation failed result - {} ", result);
55 logger.debug(" Port-ADD successful for tenant-id - {}," +
56 " network-id - {}, port-id - {}, result - {} ",
57 port.getTenantID(), port.getNetworkUUID(),
58 port.getID(), result);
62 * Invoked when a port update is requested
63 * to indicate if the specified port can be changed
64 * using the specified delta.
66 * @param delta Updates to the port object using patch semantics.
67 * @param original An instance of the Neutron Port object
69 * @return A HTTP status code to the update request.
72 public int canUpdatePort(NeutronPort delta,
73 NeutronPort original) {
74 int result = HttpURLConnection.HTTP_OK;
76 * To basic validation of the request
79 if ((original == null) || (delta == null)) {
80 logger.error("port object not specified");
81 return HttpURLConnection.HTTP_BAD_REQUEST;
87 * Invoked to take action after a port has been updated.
89 * @param port An instance of modified Neutron Port object.
92 public void neutronPortUpdated(NeutronPort port) {
96 * Invoked when a port deletion is requested
97 * to indicate if the specified port can be deleted.
99 * @param port An instance of the Neutron Port object to be deleted.
100 * @return A HTTP status code to the deletion request.
103 public int canDeletePort(NeutronPort port) {
104 return HttpURLConnection.HTTP_OK;
108 * Invoked to take action after a port has been deleted.
110 * @param port An instance of deleted Neutron Port object.
113 public void neutronPortDeleted(NeutronPort port) {
115 int result = canDeletePort(port);
116 if (result != HttpURLConnection.HTTP_OK) {
117 logger.error(" deletePort validation failed - result {} ", result);
121 logger.debug(" PORT delete successful for tenant-id - {}, " +
122 " network-id - {}, port-id - {}",
123 port.getTenantID(), port.getNetworkUUID(),