62880477910e7cbee24ae8056a756961159b66f5
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / NetworkHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.neutron;
11
12 import java.net.HttpURLConnection;
13
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;
18
19 /**
20  * Handle requests for Neutron Network.
21  */
22 public class NetworkHandler extends BaseHandler
23                             implements INeutronNetworkAware {
24     /**
25      * Logger instance.
26      */
27     static final Logger logger = LoggerFactory.getLogger(NetworkHandler.class);
28
29     /**
30      * Invoked when a network creation is requested
31      * to indicate if the specified network can be created.
32      *
33      * @param network  An instance of proposed new Neutron Network object.
34      * @return A HTTP status code to the creation request.
35      */
36     @Override
37     public int canCreateNetwork(NeutronNetwork network) {
38         if (network.isShared()) {
39             logger.error(" Network shared attribute not supported ");
40             return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
41         }
42
43         return HttpURLConnection.HTTP_CREATED;
44     }
45
46     /**
47      * Invoked to take action after a network has been created.
48      *
49      * @param network  An instance of new Neutron Network object.
50      */
51     @Override
52     public void neutronNetworkCreated(NeutronNetwork network) {
53         int result = HttpURLConnection.HTTP_BAD_REQUEST;
54
55         result = canCreateNetwork(network);
56         if (result != HttpURLConnection.HTTP_CREATED) {
57             logger.debug("Network creation failed {} ", result);
58             return;
59         }
60
61     }
62
63     /**
64      * Invoked when a network update is requested
65      * to indicate if the specified network can be changed
66      * using the specified delta.
67      *
68      * @param delta     Updates to the network object using patch semantics.
69      * @param original  An instance of the Neutron Network object
70      *                  to be updated.
71      * @return A HTTP status code to the update request.
72      */
73     @Override
74     public int canUpdateNetwork(NeutronNetwork delta,
75                                 NeutronNetwork original) {
76         return HttpURLConnection.HTTP_OK;
77     }
78
79     /**
80      * Invoked to take action after a network has been updated.
81      *
82      * @param network An instance of modified Neutron Network object.
83      */
84     @Override
85     public void neutronNetworkUpdated(NeutronNetwork network) {
86         return;
87     }
88
89     /**
90      * Invoked when a network deletion is requested
91      * to indicate if the specified network can be deleted.
92      *
93      * @param network  An instance of the Neutron Network object to be deleted.
94      * @return A HTTP status code to the deletion request.
95      */
96     @Override
97     public int canDeleteNetwork(NeutronNetwork network) {
98         return HttpURLConnection.HTTP_OK;
99     }
100
101     /**
102      * Invoked to take action after a network has been deleted.
103      *
104      * @param network  An instance of deleted Neutron Network object.
105      */
106     @Override
107     public void neutronNetworkDeleted(NeutronNetwork network) {
108
109         int result = canDeleteNetwork(network);
110         if  (result != HttpURLConnection.HTTP_OK) {
111             logger.error(" deleteNetwork validation failed for result - {} ",
112                     result);
113             return;
114         }
115         TenantNetworkManager.getManager().networkDeleted(network.getID());
116     }
117 }