summaryrefslogtreecommitdiffstats
path: root/nova/db
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/db
parent0bfa9aad9c1f74ca962351d90265e5fb56156841 (diff)
parent498f2d671573fc19d551516f7ead5da8d052ee18 (diff)
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/db')
-rw-r--r--nova/db/api.py5
-rw-r--r--nova/db/sqlalchemy/api.py18
2 files changed, 23 insertions, 0 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index eea9a349e..72e967610 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -442,6 +442,11 @@ def instance_get_all(context):
return IMPL.instance_get_all(context)
+def instance_get_active_by_window(context, begin, end=None):
+ """Get instances active during a certain time window."""
+ return IMPL.instance_get_active_by_window(context, begin, end)
+
+
def instance_get_all_by_user(context, user_id):
"""Get all instances."""
return IMPL.instance_get_all_by_user(context, user_id)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 06bb1501f..6bd16d42e 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -956,6 +956,24 @@ def instance_get_all(context):
@require_admin_context
+def instance_get_active_by_window(context, begin, end=None):
+ """Return instances that were continuously active over the given window"""
+ session = get_session()
+ query = session.query(models.Instance).\
+ options(joinedload_all('fixed_ip.floating_ips')).\
+ options(joinedload('security_groups')).\
+ options(joinedload_all('fixed_ip.network')).\
+ options(joinedload('instance_type')).\
+ filter(models.Instance.launched_at < begin)
+ if end:
+ query = query.filter(or_(models.Instance.terminated_at == None,
+ models.Instance.terminated_at > end))
+ else:
+ query = query.filter(models.Instance.terminated_at == None)
+ return query.all()
+
+
+@require_admin_context
def instance_get_all_by_user(context, user_id):
session = get_session()
return session.query(models.Instance).\