summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaguang Tang <heut2008@gmail.com>2012-05-06 17:54:45 +0800
committerVishvananda Ishaya <vishvananda@gmail.com>2012-05-09 12:49:57 -0700
commit7b641e9c07a0dc1a1f0312dc8b96c8f14b501633 (patch)
treea21648f76ed83bfa6625804189122eb75d834dfa
parent113300f024d83ed07d1920d5ba0c518a5550e49e (diff)
implement blueprint floating-ip-notification.
add floating ip alloate/disalloate, associate/disassocaite notify events.change releative tests to make changes pass through. Change-Id: I77257528cd87da44ace896d65a4268a066ed888e
-rw-r--r--nova/network/manager.py27
-rw-r--r--nova/tests/network/test_manager.py8
2 files changed, 31 insertions, 4 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py
index e37d2649c..0e652c610 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -62,6 +62,7 @@ from nova import log as logging
from nova import manager
from nova.network import api as network_api
from nova.network import model as network_model
+from nova.notifier import api as notifier
from nova.openstack.common import cfg
from nova.openstack.common import importutils
import nova.policy
@@ -402,9 +403,16 @@ class FloatingIP(object):
context.project_id)
raise exception.QuotaError(code='AddressLimitExceeded')
pool = pool or FLAGS.default_floating_pool
- return self.db.floating_ip_allocate_address(context,
+
+ floating_ip = self.db.floating_ip_allocate_address(context,
project_id,
pool)
+ payload = dict(project_id=project_id, floating_ip=floating_ip)
+ notifier.notify(context,
+ notifier.publisher_id("network"),
+ 'network.floating_ip.allocate',
+ notifier.INFO, payload)
+ return floating_ip
@wrap_check_policy
def deallocate_floating_ip(self, context, address,
@@ -427,6 +435,12 @@ class FloatingIP(object):
# clean up any associated DNS entries
self._delete_all_entries_for_ip(context,
floating_ip['address'])
+ payload = dict(project_id=floating_ip['project_id'],
+ floating_ip=floating_ip['address'])
+ notifier.notify(context,
+ notifier.publisher_id("network"),
+ 'network.floating_ip.deallocate',
+ notifier.INFO, payload=payload)
self.db.floating_ip_deallocate(context, address)
@@ -494,6 +508,12 @@ class FloatingIP(object):
if "Cannot find device" in str(e):
LOG.error(_('Interface %(interface)s not found'), locals())
raise exception.NoFloatingIpInterface(interface=interface)
+ payload = dict(project_id=context.project_id,
+ floating_ip=floating_address)
+ notifier.notify(context,
+ notifier.publisher_id("network"),
+ 'network.floating_ip.associate',
+ notifier.INFO, payload=payload)
@wrap_check_policy
def disassociate_floating_ip(self, context, address,
@@ -546,6 +566,11 @@ class FloatingIP(object):
# go go driver time
self.l3driver.remove_floating_ip(address, fixed_address, interface)
+ payload = dict(project_id=context.project_id, floating_ip=address)
+ notifier.notify(context,
+ notifier.publisher_id("network"),
+ 'network.floating_ip.disassociate',
+ notifier.INFO, payload=payload)
@wrap_check_policy
def get_floating_ip(self, context, id):
diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py
index c8d1851d6..de8779be1 100644
--- a/nova/tests/network/test_manager.py
+++ b/nova/tests/network/test_manager.py
@@ -552,7 +552,7 @@ class VlanNetworkTestCase(test.TestCase):
is_admin=False)
def fake1(*args, **kwargs):
- return {'address': '10.0.0.1'}
+ return {'address': '10.0.0.1', 'project_id': ctxt.project_id}
def fake2(*args, **kwargs):
return 25
@@ -584,7 +584,8 @@ class VlanNetworkTestCase(test.TestCase):
return {'address': '10.0.0.1', 'fixed_ip_id': 1}
def fake3(*args, **kwargs):
- return {'address': '10.0.0.1', 'fixed_ip_id': None}
+ return {'address': '10.0.0.1', 'fixed_ip_id': None,
+ 'project_id': ctxt.project_id}
self.stubs.Set(self.network.db, 'floating_ip_deallocate', fake1)
self.stubs.Set(self.network, '_floating_ip_owned_by_project', fake1)
@@ -740,7 +741,8 @@ class VlanNetworkTestCase(test.TestCase):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
- 'fixed_ip_id': 1}
+ 'fixed_ip_id': 1,
+ 'project_id': ctxt.project_id}
# fixed ip with remote host
def fake4(*args, **kwargs):