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
This commit is contained in:
Doug Hellmann 2012-06-18 12:28:06 -04:00
parent d9faf1c204
commit bf555549df
3 changed files with 92 additions and 15 deletions

View File

@ -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),
)

View File

@ -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',

View File

@ -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',