summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMonsyne Dragon <mdragon@rackspace.com>2011-06-28 20:53:45 +0000
committerTarmac <>2011-06-28 20:53:45 +0000
commit9ae4fbdef0a5f4c925c7e3d546edea06e608e39b (patch)
treefe74a3bfa56acfc637db95773d25782cb3e41148 /nova/utils.py
parent0bfa9aad9c1f74ca962351d90265e5fb56156841 (diff)
parent498f2d671573fc19d551516f7ead5da8d052ee18 (diff)
downloadnova-9ae4fbdef0a5f4c925c7e3d546edea06e608e39b.tar.gz
nova-9ae4fbdef0a5f4c925c7e3d546edea06e608e39b.tar.xz
nova-9ae4fbdef0a5f4c925c7e3d546edea06e608e39b.zip
This adds system usage notifications using the notifications framework.
These are designed to feed an external billing or similar system that subscribes to the nova feed and does the analysis.
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 918541224..510cdd9f6 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -282,6 +282,22 @@ EASIER_PASSWORD_SYMBOLS = ('23456789' # Removed: 0, 1
'ABCDEFGHJKLMNPQRSTUVWXYZ') # Removed: I, O
+def usage_from_instance(instance_ref, **kw):
+ usage_info = dict(
+ tenant_id=instance_ref['project_id'],
+ user_id=instance_ref['user_id'],
+ instance_id=instance_ref['id'],
+ instance_type=instance_ref['instance_type']['name'],
+ instance_type_id=instance_ref['instance_type_id'],
+ display_name=instance_ref['display_name'],
+ created_at=str(instance_ref['created_at']),
+ launched_at=str(instance_ref['launched_at']) \
+ if instance_ref['launched_at'] else '',
+ image_ref=instance_ref['image_ref'])
+ usage_info.update(kw)
+ return usage_info
+
+
def generate_password(length=20, symbols=DEFAULT_PASSWORD_SYMBOLS):
"""Generate a random password from the supplied symbols.