2 * Copyright (C) 2014 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 : Dave Tucker, Flavio Fernandes
10 package org.opendaylight.ovsdb.openstack.netvirt;
12 import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPAware;
13 import org.opendaylight.controller.networkconfig.neutron.NeutronFloatingIP;
14 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
15 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.net.HttpURLConnection;
23 * Handle requests for Neutron Floating IP.
25 public class FloatingIPHandler extends AbstractHandler
26 implements INeutronFloatingIPAware {
31 static final Logger logger = LoggerFactory.getLogger(FloatingIPHandler.class);
33 // The implementation for each of these services is resolved by the OSGi Service Manager
34 private volatile NeutronL3Adapter neutronL3Adapter;
37 * Services provide this interface method to indicate if the specified floatingIP can be created
40 * instance of proposed new Neutron FloatingIP object
42 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
43 * results in the create operation being interrupted and the returned status value reflected in the
47 public int canCreateFloatingIP(NeutronFloatingIP floatingIP) {
48 return HttpURLConnection.HTTP_OK;
53 * Services provide this interface method for taking action after a floatingIP has been created
56 * instance of new Neutron FloatingIP object
59 public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP) {
60 enqueueEvent(new NorthboundEvent(floatingIP, Action.ADD));
64 * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified
68 * updates to the floatingIP object using patch semantics
70 * instance of the Neutron FloatingIP object to be updated
72 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
73 * results in the update operation being interrupted and the returned status value reflected in the
77 public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original) {
78 return HttpURLConnection.HTTP_OK;
82 * Services provide this interface method for taking action after a floatingIP has been updated
85 * instance of modified Neutron FloatingIP object
88 public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP) {
89 enqueueEvent(new NorthboundEvent(floatingIP, Action.UPDATE));
93 * Services provide this interface method to indicate if the specified floatingIP can be deleted
96 * instance of the Neutron FloatingIP object to be deleted
98 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
99 * results in the delete operation being interrupted and the returned status value reflected in the
103 public int canDeleteFloatingIP(NeutronFloatingIP floatingIP) {
104 return HttpURLConnection.HTTP_OK;
108 * Services provide this interface method for taking action after a floatingIP has been deleted
111 * instance of deleted Neutron FloatingIP object
114 public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP) {
115 enqueueEvent(new NorthboundEvent(floatingIP, Action.DELETE));
121 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
122 * @see EventDispatcher
125 public void processEvent(AbstractEvent abstractEvent) {
126 if (!(abstractEvent instanceof NorthboundEvent)) {
127 logger.error("Unable to process abstract event " + abstractEvent);
130 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
131 switch (ev.getAction()) {
137 neutronL3Adapter.handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());
140 logger.warn("Unable to process event action " + ev.getAction());