From bf555549df9bb668d0a049d333a0e36994847a1b Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 18 Jun 2012 12:28:06 -0400 Subject: [PATCH] Add instance metadata from notification events bug 1006120 This change depends on a change to nova to include the extra data in the outgoing notifications. Change-Id: Ieaee00f5f6c0a9f6d00843adbcc2cd995334bbd1 --- ceilometer/compute/notifications.py | 51 ++++++++++++++++++++++------- tests/collector/test_dispatcher.py | 14 +++++++- tests/compute/test_notifications.py | 42 ++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 15 deletions(-) diff --git a/ceilometer/compute/notifications.py b/ceilometer/compute/notifications.py index b7b1664b..bf7e9a05 100644 --- a/ceilometer/compute/notifications.py +++ b/ceilometer/compute/notifications.py @@ -18,8 +18,45 @@ """Converters for producing compute counter messages from notification events. """ -from .. import counter -from .. import plugin +from ceilometer import counter +from ceilometer import plugin + +INSTANCE_PROPERTIES = [ + # Identity properties + 'display_name', + 'reservation_id', + # Type properties + 'architecture' + # Location properties + 'availability_zone', + # Image properties + 'image_ref', + 'image_ref_url', + 'kernel_id', + 'os_type', + 'ramdisk_id', + # Capacity properties + 'disk_gb', + 'ephemeral_gb', + 'memory_mb', + 'root_gb', + 'vcpus', + ] + + +def get_instance_metadata_from_event(body): + """Return a metadata dictionary for the instance mentioned in the + notification event. + """ + instance = body['payload'] + metadata = { + 'event_type': body['event_type'], + 'instance_type': instance['instance_type_id'], + 'host': body['publisher_id'], + } + for name in INSTANCE_PROPERTIES: + metadata[name] = instance.get(name, u'') + return metadata def c1(body): @@ -34,15 +71,7 @@ def c1(body): resource_id=body['payload']['instance_id'], timestamp=body['timestamp'], duration=0, - resource_metadata={ - 'display_name': body['payload']['display_name'], - 'instance_type': body['payload']['instance_type_id'], - 'image_ref_url': body['payload']['image_ref_url'], - 'disk_gb': body['payload']['disk_gb'], - 'memory_mb': body['payload']['memory_mb'], - 'host': body['publisher_id'], - 'event_type': body['event_type'], - }, + resource_metadata=get_instance_metadata_from_event(body), ) diff --git a/tests/collector/test_dispatcher.py b/tests/collector/test_dispatcher.py index b1f796d4..c6ad502d 100644 --- a/tests/collector/test_dispatcher.py +++ b/tests/collector/test_dispatcher.py @@ -60,7 +60,19 @@ TEST_NOTICE = { u'state': u'active', u'state_description': u'', u'tenant_id': u'7c150a59fe714e6f9263774af9688f0e', - u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'}, + u'user_id': u'1e3ce043029547f1a61c1996d1a531a2', + u'reservation_id': u'1e3ce043029547f1a61c1996d1a531a3', + u'vcpus': 1, + u'root_gb': 0, + u'ephemeral_gb': 0, + u'host': u'compute-host-name', + u'availability_zone': u'1e3ce043029547f1a61c1996d1a531a4', + u'os_type': u'linux?', + u'architecture': u'x86', + u'image_ref': u'UUID', + u'kernel_id': u'1e3ce043029547f1a61c1996d1a531a5', + u'ramdisk_id': u'1e3ce043029547f1a61c1996d1a531a6', + }, u'priority': u'INFO', u'publisher_id': u'compute.vagrant-precise', u'timestamp': u'2012-05-08 20:23:48.028195', diff --git a/tests/compute/test_notifications.py b/tests/compute/test_notifications.py index 98e633d1..3c5f1c59 100644 --- a/tests/compute/test_notifications.py +++ b/tests/compute/test_notifications.py @@ -53,7 +53,19 @@ INSTANCE_CREATE_END = { u'state': u'active', u'state_description': u'', u'tenant_id': u'7c150a59fe714e6f9263774af9688f0e', - u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'}, + u'user_id': u'1e3ce043029547f1a61c1996d1a531a2', + u'reservation_id': u'1e3ce043029547f1a61c1996d1a531a3', + u'vcpus': 1, + u'root_gb': 0, + u'ephemeral_gb': 0, + u'host': u'compute-host-name', + u'availability_zone': u'1e3ce043029547f1a61c1996d1a531a4', + u'os_type': u'linux?', + u'architecture': u'x86', + u'image_ref': u'UUID', + u'kernel_id': u'1e3ce043029547f1a61c1996d1a531a5', + u'ramdisk_id': u'1e3ce043029547f1a61c1996d1a531a6', + }, u'priority': u'INFO', u'publisher_id': u'compute.vagrant-precise', u'timestamp': u'2012-05-08 20:23:48.028195', @@ -85,7 +97,19 @@ INSTANCE_DELETE_START = { u'state': u'active', u'state_description': u'deleting', u'tenant_id': u'7c150a59fe714e6f9263774af9688f0e', - u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'}, + u'user_id': u'1e3ce043029547f1a61c1996d1a531a2', + u'reservation_id': u'1e3ce043029547f1a61c1996d1a531a3', + u'vcpus': 1, + u'root_gb': 0, + u'ephemeral_gb': 0, + u'host': u'compute-host-name', + u'availability_zone': u'1e3ce043029547f1a61c1996d1a531a4', + u'os_type': u'linux?', + u'architecture': u'x86', + u'image_ref': u'UUID', + u'kernel_id': u'1e3ce043029547f1a61c1996d1a531a5', + u'ramdisk_id': u'1e3ce043029547f1a61c1996d1a531a6', + }, u'priority': u'INFO', u'publisher_id': u'compute.vagrant-precise', u'timestamp': u'2012-05-08 20:24:14.824743', @@ -120,7 +144,19 @@ INSTANCE_EXISTS = { u'state': u'active', u'state_description': u'', u'tenant_id': u'7c150a59fe714e6f9263774af9688f0e', - u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'}, + u'user_id': u'1e3ce043029547f1a61c1996d1a531a2', + u'reservation_id': u'1e3ce043029547f1a61c1996d1a531a3', + u'vcpus': 1, + u'root_gb': 0, + u'ephemeral_gb': 0, + u'host': u'compute-host-name', + u'availability_zone': u'1e3ce043029547f1a61c1996d1a531a4', + u'os_type': u'linux?', + u'architecture': u'x86', + u'image_ref': u'UUID', + u'kernel_id': u'1e3ce043029547f1a61c1996d1a531a5', + u'ramdisk_id': u'1e3ce043029547f1a61c1996d1a531a6', + }, u'priority': u'INFO', u'publisher_id': u'compute.vagrant-precise', u'timestamp': u'2012-05-08 16:03:44.122481',