diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-05-10 16:23:50 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-05-10 16:23:50 +0000 |
| commit | 955bfa2c7f1cac4160486f6b083612e15aa7b97d (patch) | |
| tree | 8311cb7c6fe16d2dc370786ba14350808806e6e6 | |
| parent | 31efac3a6e818c36a12e0b480f389c7a5d169462 (diff) | |
| parent | 53adfd289bf7226f1c6f59c17608e42f3083f130 (diff) | |
Merge "Added image metadata to compute.instance.exists"
| -rw-r--r-- | nova/compute/utils.py | 13 | ||||
| -rw-r--r-- | nova/tests/test_compute_utils.py | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 016e4aaed..a975ce77f 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -22,6 +22,7 @@ import nova.context from nova import db from nova import exception from nova import flags +from nova import image from nova import log from nova import network from nova.network import model as network_model @@ -46,6 +47,7 @@ def notify_usage_exists(context, instance_ref, current_period=False, :param ignore_missing_network_data: if True, log any exceptions generated while getting network info; if False, raise the exception. """ + admin_context = nova.context.get_admin_context(read_deleted='yes') begin, end = utils.last_completed_audit_period() bw = {} @@ -86,9 +88,12 @@ def notify_usage_exists(context, instance_ref, current_period=False, bw[label] = dict(bw_in=b.bw_in, bw_out=b.bw_out) + # add image metadata to the notification: + image_meta = _get_image_meta(context, instance_ref) + extra_info = dict(audit_period_beginning=str(audit_start), audit_period_ending=str(audit_end), - bandwidth=bw) + bandwidth=bw, image_meta=image_meta) if extra_usage_info: extra_info.update(extra_usage_info) @@ -97,6 +102,12 @@ def notify_usage_exists(context, instance_ref, current_period=False, context, instance_ref, 'exists', extra_usage_info=extra_info) +def _get_image_meta(context, instance_ref): + image_service, image_id = image.get_image_service(context, + instance_ref["image_ref"]) + return image_service.show(context, image_id) + + def legacy_network_info(network_model): """ Return the legacy network_info representation of the network_model diff --git a/nova/tests/test_compute_utils.py b/nova/tests/test_compute_utils.py index 74e6fc783..f85eb4196 100644 --- a/nova/tests/test_compute_utils.py +++ b/nova/tests/test_compute_utils.py @@ -98,9 +98,10 @@ class UsageInfoTestCase(test.TestCase): for attr in ('display_name', 'created_at', 'launched_at', 'state', 'state_description', 'bandwidth', 'audit_period_beginning', - 'audit_period_ending'): + 'audit_period_ending', 'image_meta'): self.assertTrue(attr in payload, msg="Key %s not in payload" % attr) + self.assertEquals(payload['image_meta']['id'], 1) image_ref_url = "%s/images/1" % utils.generate_glance_url() self.assertEquals(payload['image_ref_url'], image_ref_url) self.compute.terminate_instance(self.context, instance['uuid']) |
