network: floating IP account in Quantum

Change-Id: I0e4a8245bd524dd2073f52f7a808e9456816c4df
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2012-10-25 12:16:41 +02:00
parent 16c892bbfa
commit 55d52bab01
4 changed files with 73 additions and 12 deletions

View File

@ -71,7 +71,9 @@ class NetworkNotificationBase(plugin.NotificationBase):
LOG.info('network notification %r', message)
message['payload'] = message['payload'][self.resource_name]
metadata = self.notification_to_metadata(message)
yield counter.Counter(name=self.resource_name,
counter_name = getattr(self, "counter_name", self.resource_name)
yield counter.Counter(name=counter_name,
type=counter.TYPE_GAUGE,
volume=1,
user_id=message['_context_user_id'],
@ -81,9 +83,10 @@ class NetworkNotificationBase(plugin.NotificationBase):
resource_metadata=metadata,
)
network_counter_name = message['event_type'].rpartition('.')[0]
if network_counter_name != self.resource_name:
yield counter.Counter(name=network_counter_name,
event_type_split = message['event_type'].split('.')
if len(event_type_split) > 2:
yield counter.Counter(name=counter_name
+ "." + event_type_split[1],
type=counter.TYPE_DELTA,
volume=1,
user_id=message['_context_user_id'],
@ -167,3 +170,21 @@ class Router(NetworkNotificationBase):
]
resource_name = 'router'
class FloatingIP(NetworkNotificationBase):
"""Listen for Quantum notifications in order to mediate with the
metering framework.
"""
metadata_keys = [
"router_id",
"floating_network_id",
"fixed_ip_address",
"floating_ip_address",
"port_id",
]
resource_name = 'floatingip'
counter_name = 'ip.floating'

View File

@ -77,6 +77,8 @@ router Gauge 1 rtr ID Duration of router
router.create Delta request rtr ID Creation requests for this router
router.update Delta request rtr ID Update requests for this router
ip.floating Gauge 1 ip ID Duration of floating ip
ip.floating.create Delta 1 ip ID Creation requests for this floating ip
ip.floating.update Delta 1 ip ID Update requests for this floating ip
======================== ========== ======= ======== =======================================================
Image (Glance)

View File

@ -95,6 +95,7 @@ setuptools.setup(
subnet = ceilometer.network.notifications:Subnet
port = ceilometer.network.notifications:Port
router = ceilometer.network.notifications:Router
floatingip = ceilometer.network.notifications:FloatingIP
[ceilometer.poll.compute]
libvirt_diskio = ceilometer.compute.libvirt:DiskIOPollster

View File

@ -180,26 +180,54 @@ NOTIFICATION_ROUTER_EXISTS = {
u'message_id': u'9e839576-cc47-4c60-a7d8-5743681213b1'}
NOTIFICATION_FLOATINGIP_EXISTS = {
u'_context_roles': [u'anotherrole',
u'Member'],
u'_context_read_deleted': u'no',
u'event_type': u'floatingip.exists',
u'timestamp': u'2012-09-27 14:11:27.086575',
u'_context_tenant_id': u'82ed0c40ebe64d0bb3310027039c8ed2',
u'payload': {u'floatingip':
{'router_id': None,
'tenant_id': u'6e5f9df9b3a249ab834f25fe1b1b81fd',
'floating_network_id':
u'001400f7-1710-4245-98c3-39ba131cc39a',
'fixed_ip_address': None,
'floating_ip_address': u'172.24.4.227',
'port_id': None,
'id': u'2b7cc28c-6f78-4735-9246-257168405de6'}},
u'priority': u'INFO',
u'_context_is_admin': False,
u'_context_timestamp': u'2012-09-27 14:11:26.924779',
u'_context_user_id': u'b44b7ce67fc84414a5c1660a92a1b862',
u'publisher_id': u'network.ubuntu-VirtualBox',
u'message_id': u'9e839576-cc47-4c60-a7d8-5743681213b1'}
class TestNotifications(unittest.TestCase):
def test_network_create(self):
v = notifications.Network()
counters = v.process_notification(NOTIFICATION_NETWORK_CREATE)
self.assertEqual(len(list(counters)), 2)
counters = list(v.process_notification(NOTIFICATION_NETWORK_CREATE))
self.assertEqual(len(counters), 2)
self.assertEqual(counters[1].name, "network.create")
def test_subnet_create(self):
v = notifications.Subnet()
counters = v.process_notification(NOTIFICATION_SUBNET_CREATE)
self.assertEqual(len(list(counters)), 2)
counters = list(v.process_notification(NOTIFICATION_SUBNET_CREATE))
self.assertEqual(len(counters), 2)
self.assertEqual(counters[1].name, "subnet.create")
def test_port_create(self):
v = notifications.Port()
counters = v.process_notification(NOTIFICATION_PORT_CREATE)
self.assertEqual(len(list(counters)), 2)
counters = list(v.process_notification(NOTIFICATION_PORT_CREATE))
self.assertEqual(len(counters), 2)
self.assertEqual(counters[1].name, "port.create")
def test_port_update(self):
v = notifications.Port()
counters = v.process_notification(NOTIFICATION_PORT_UPDATE)
self.assertEqual(len(list(counters)), 2)
counters = list(v.process_notification(NOTIFICATION_PORT_UPDATE))
self.assertEqual(len(counters), 2)
self.assertEqual(counters[1].name, "port.update")
def test_network_exists(self):
v = notifications.Network()
@ -211,6 +239,12 @@ class TestNotifications(unittest.TestCase):
counters = v.process_notification(NOTIFICATION_ROUTER_EXISTS)
self.assertEqual(len(list(counters)), 1)
def test_floatingip_exists(self):
v = notifications.FloatingIP()
counters = list(v.process_notification(NOTIFICATION_FLOATINGIP_EXISTS))
self.assertEqual(len(counters), 1)
self.assertEqual(counters[0].name, "ip.floating")
class TestEventTypes(unittest.TestCase):
@ -231,3 +265,6 @@ class TestEventTypes(unittest.TestCase):
def test_router(self):
assert notifications.Router().get_event_types()
def test_floatingip(self):
assert notifications.FloatingIP().get_event_types()