summaryrefslogtreecommitdiffstats
path: root/nova/notifications.py
diff options
context:
space:
mode:
authorAlex Meade <alex.meade@rackspace.com>2012-07-05 14:27:33 -0400
committerAlex Meade <alex.meade@rackspace.com>2012-07-05 14:30:54 -0400
commit4cdc30796c7c76068898cd9e9280e8d7a11a57cb (patch)
treeb5ef6bb8d1a0c35801de8a1bf2e97dd463207664 /nova/notifications.py
parente883e9756c779793ca071ee3f052f5d13610a9ac (diff)
downloadnova-4cdc30796c7c76068898cd9e9280e8d7a11a57cb.tar.gz
nova-4cdc30796c7c76068898cd9e9280e8d7a11a57cb.tar.xz
nova-4cdc30796c7c76068898cd9e9280e8d7a11a57cb.zip
Add checks for retrieving deleted instance metadata for notification events.
This enables metadata for a deleted instance to be reported in usage notifications. However, deleted metadata for a nondeleted instance will not be shown. Fixes bug 1021430. Change-Id: I7ce5c720c7705be34724679bb4ff99fb8ba37a27
Diffstat (limited to 'nova/notifications.py')
-rw-r--r--nova/notifications.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/nova/notifications.py b/nova/notifications.py
index 998abee65..933af1f20 100644
--- a/nova/notifications.py
+++ b/nova/notifications.py
@@ -109,16 +109,6 @@ def _send_instance_update_notification(context, instance, old_vm_state,
bw = bandwidth_usage(instance, audit_start)
payload["bandwidth"] = bw
- try:
- system_metadata = db.instance_system_metadata_get(
- context, instance.uuid)
- except exception.NotFound:
- system_metadata = {}
-
- # add image metadata
- image_meta_props = image_meta(system_metadata)
- payload["image_meta"] = image_meta_props
-
# if the service name (e.g. api/scheduler/compute) is not provided, default
# to "compute"
if not service:
@@ -222,6 +212,19 @@ def usage_from_instance(context, instance_ref, network_info,
instance_type_name = instance_ref.get('instance_type', {}).get('name', '')
+ if system_metadata is None:
+ try:
+ if instance_ref.get('deleted'):
+ with utils.temporary_mutation(context, read_deleted='yes'):
+ system_metadata = db.instance_system_metadata_get(
+ context, instance_ref['uuid'])
+ else:
+ system_metadata = db.instance_system_metadata_get(
+ context, instance_ref['uuid'])
+
+ except exception.NotFound:
+ system_metadata = {}
+
usage_info = dict(
# Owner properties
tenant_id=instance_ref['project_id'],
@@ -273,5 +276,9 @@ def usage_from_instance(context, instance_ref, network_info,
if network_info is not None:
usage_info['fixed_ips'] = network_info.fixed_ips()
+ # add image metadata
+ image_meta_props = image_meta(system_metadata)
+ usage_info["image_meta"] = image_meta_props
+
usage_info.update(kw)
return usage_info