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.INeutronNetworkAware;
15 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Handle requests for Neutron Network.
22 public class NetworkHandler extends BaseHandler
23 implements INeutronNetworkAware {
27 static final Logger logger = LoggerFactory.getLogger(NetworkHandler.class);
30 * Invoked when a network creation is requested
31 * to indicate if the specified network can be created.
33 * @param network An instance of proposed new Neutron Network object.
34 * @return A HTTP status code to the creation request.
37 public int canCreateNetwork(NeutronNetwork network) {
38 if (network.isShared()) {
39 logger.error(" Network shared attribute not supported ");
40 return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
43 return HttpURLConnection.HTTP_CREATED;
47 * Invoked to take action after a network has been created.
49 * @param network An instance of new Neutron Network object.
52 public void neutronNetworkCreated(NeutronNetwork network) {
53 int result = HttpURLConnection.HTTP_BAD_REQUEST;
55 result = canCreateNetwork(network);
56 if (result != HttpURLConnection.HTTP_CREATED) {
57 logger.debug("Network creation failed {} ", result);
61 TenantNetworkManager.getManager().networkCreated(network.getID());
65 * Invoked when a network update is requested
66 * to indicate if the specified network can be changed
67 * using the specified delta.
69 * @param delta Updates to the network object using patch semantics.
70 * @param original An instance of the Neutron Network object
72 * @return A HTTP status code to the update request.
75 public int canUpdateNetwork(NeutronNetwork delta,
76 NeutronNetwork original) {
77 return HttpURLConnection.HTTP_OK;
81 * Invoked to take action after a network has been updated.
83 * @param network An instance of modified Neutron Network object.
86 public void neutronNetworkUpdated(NeutronNetwork network) {
91 * Invoked when a network deletion is requested
92 * to indicate if the specified network can be deleted.
94 * @param network An instance of the Neutron Network object to be deleted.
95 * @return A HTTP status code to the deletion request.
98 public int canDeleteNetwork(NeutronNetwork network) {
99 return HttpURLConnection.HTTP_OK;
103 * Invoked to take action after a network has been deleted.
105 * @param network An instance of deleted Neutron Network object.
108 public void neutronNetworkDeleted(NeutronNetwork network) {
110 int result = canDeleteNetwork(network);
111 if (result != HttpURLConnection.HTTP_OK) {
112 logger.error(" deleteNetwork validation failed for result - {} ",
116 TenantNetworkManager.getManager().networkDeleted(network.getID());