1 package org.opendaylight.ovsdb.neutron;
3 import java.net.HttpURLConnection;
6 import org.opendaylight.controller.containermanager.ContainerConfig;
7 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
8 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
13 * Handle requests for Neutron Network.
15 public class NetworkHandler extends BaseHandler
16 implements INeutronNetworkAware {
20 static final Logger logger = LoggerFactory.getLogger(NetworkHandler.class);
23 * Invoked when a network creation is requested
24 * to indicate if the specified network can be created.
26 * @param network An instance of proposed new Neutron Network object.
27 * @return A HTTP status code to the creation request.
30 public int canCreateNetwork(NeutronNetwork network) {
31 if (network.isShared()) {
32 logger.error(" Network shared attribute not supported ");
33 return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
36 String networkID = convertNeutronIDToKey(network.getID());
38 List<String> containers = containerManager.getContainerNames();
39 if (containers.contains(networkID)) {
40 logger.debug("Container with name {} exists", networkID);
41 return HttpURLConnection.HTTP_CONFLICT;
44 return HttpURLConnection.HTTP_CREATED;
48 * Invoked to take action after a network has been created.
50 * @param network An instance of new Neutron Network object.
53 public void neutronNetworkCreated(NeutronNetwork network) {
54 int result = HttpURLConnection.HTTP_BAD_REQUEST;
56 result = canCreateNetwork(network);
57 if (result != HttpURLConnection.HTTP_CREATED) {
58 logger.debug("Network creation failed {} ", result);
61 String networkId = convertNeutronIDToKey(network.getID());
62 result = TenantNetworkManager.getManager().networkCreated(networkId);
63 logger.debug("Neutron Network {} Created with Internal Vlan : {}", network.toString(), result);
67 * Invoked when a network update is requested
68 * to indicate if the specified network can be changed
69 * using the specified delta.
71 * @param delta Updates to the network object using patch semantics.
72 * @param original An instance of the Neutron Network object
74 * @return A HTTP status code to the update request.
77 public int canUpdateNetwork(NeutronNetwork delta,
78 NeutronNetwork original) {
79 return HttpURLConnection.HTTP_OK;
83 * Invoked to take action after a network has been updated.
85 * @param network An instance of modified Neutron Network object.
88 public void neutronNetworkUpdated(NeutronNetwork network) {
93 * Invoked when a network deletion is requested
94 * to indicate if the specified network can be deleted.
96 * @param network An instance of the Neutron Network object to be deleted.
97 * @return A HTTP status code to the deletion request.
100 public int canDeleteNetwork(NeutronNetwork network) {
101 return HttpURLConnection.HTTP_OK;
105 * Invoked to take action after a network has been deleted.
107 * @param network An instance of deleted Neutron Network object.
110 public void neutronNetworkDeleted(NeutronNetwork network) {
112 int result = canDeleteNetwork(network);
113 if (result != HttpURLConnection.HTTP_OK) {
114 logger.error(" deleteNetwork validation failed for result - {} ",
118 String networkID = convertNeutronIDToKey(network.getID());
120 ContainerConfig config = new ContainerConfig();
121 config.setContainer(networkID);
122 containerManager.removeContainer(config);