summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorCraig Vyvial <cp16net@gmail.com>2012-05-07 14:03:04 -0500
committerCraig Vyvial <cp16net@gmail.com>2012-05-14 16:34:08 -0500
commitfbae8d09fdb9ad370fa827aab0f9bfe0c0c7041f (patch)
treeb84449522d27586243a9994e704ab6bc06d3d0cf /bin
parentb3e2bae38177583201dd7dcdd2d9c16929724573 (diff)
Adding notifications for volumes
Added notifications for volumes have been added with tests. This includes create/delete/exists events for volumes. blueprint nova-notifications Change-Id: I21b74974fac22c3621ccf7564dc5c0d339f8751a
Diffstat (limited to 'bin')
-rwxr-xr-xbin/instance-usage-audit4
-rwxr-xr-xbin/volume-usage-audit84
2 files changed, 86 insertions, 2 deletions
diff --git a/bin/instance-usage-audit b/bin/instance-usage-audit
index 5b30c3586..05f34176f 100755
--- a/bin/instance-usage-audit
+++ b/bin/instance-usage-audit
@@ -16,8 +16,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""Cron script to generate usage notifications for instances neither created
- nor destroyed in a given time period.
+"""Cron script to generate usage notifications for instances existing
+ during the audit period.
Together with the notifications generated by compute on instance
create/delete/resize, over that time period, this allows an external
diff --git a/bin/volume-usage-audit b/bin/volume-usage-audit
new file mode 100755
index 000000000..d8591557c
--- /dev/null
+++ b/bin/volume-usage-audit
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2011 Openstack, LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""Cron script to generate usage notifications for volumes existing during
+ the audit period.
+
+ Together with the notifications generated by volumes
+ create/delete/resize, over that time period, this allows an external
+ system consuming usage notification feeds to calculate volume usage
+ for each tenant.
+
+ Time periods are specified as 'hour', 'month', 'day' or 'year'
+
+ hour = previous hour. If run at 9:07am, will generate usage for 8-9am.
+ month = previous month. If the script is run April 1, it will generate
+ usages for March 1 through March 31.
+ day = previous day. if run on July 4th, it generates usages for July 3rd.
+ year = previous year. If run on Jan 1, it generates usages for
+ Jan 1 through Dec 31 of the previous year.
+"""
+
+import datetime
+import gettext
+import os
+import sys
+import time
+import traceback
+
+# If ../nova/__init__.py exists, add ../ to Python search path, so that
+# it will override what happens to be installed in /usr/(local/)lib/python...
+POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
+ os.pardir,
+ os.pardir))
+if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
+ sys.path.insert(0, POSSIBLE_TOPDIR)
+
+gettext.install('nova', unicode=1)
+from nova import context
+from nova import db
+from nova import exception
+from nova import flags
+from nova import log as logging
+from nova import rpc
+from nova import utils
+import nova.volume.utils
+
+
+FLAGS = flags.FLAGS
+
+if __name__ == '__main__':
+ rpc.register_opts(FLAGS)
+ admin_context = context.get_admin_context()
+ utils.default_flagfile()
+ flags.FLAGS(sys.argv)
+ logging.setup()
+ begin, end = utils.last_completed_audit_period()
+ print "Starting volume usage audit"
+ print "Creating usages for %s until %s" % (str(begin), str(end))
+ volumes = db.volume_get_active_by_window(admin_context,
+ begin,
+ end)
+ print "Found %d volumes" % len(volumes)
+ for volume_ref in volumes:
+ try:
+ nova.volume.utils.notify_usage_exists(
+ admin_context, volume_ref)
+ except Exception, e:
+ print traceback.format_exc(e)
+ print "Volume usage audit completed"