~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to bin/nova-volume-usage-audit

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
 
 
4
 
# Copyright (c) 2011 OpenStack, LLC.
5
 
# All Rights Reserved.
6
 
#
7
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
8
 
#    not use this file except in compliance with the License. You may obtain
9
 
#    a copy of the License at
10
 
#
11
 
#         http://www.apache.org/licenses/LICENSE-2.0
12
 
#
13
 
#    Unless required by applicable law or agreed to in writing, software
14
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
 
#    License for the specific language governing permissions and limitations
17
 
#    under the License.
18
 
 
19
 
"""Cron script to generate usage notifications for volumes existing during
20
 
   the audit period.
21
 
 
22
 
   Together with the notifications generated by volumes
23
 
   create/delete/resize, over that time period, this allows an external
24
 
   system consuming usage notification feeds to calculate volume usage
25
 
   for each tenant.
26
 
 
27
 
   Time periods are specified as 'hour', 'month', 'day' or 'year'
28
 
 
29
 
   hour = previous hour. If run at 9:07am, will generate usage for 8-9am.
30
 
   month = previous month. If the script is run April 1, it will generate
31
 
           usages for March 1 through March 31.
32
 
   day = previous day. if run on July 4th, it generates usages for July 3rd.
33
 
   year = previous year. If run on Jan 1, it generates usages for
34
 
        Jan 1 through Dec 31 of the previous year.
35
 
"""
36
 
 
37
 
import datetime
38
 
import gettext
39
 
import os
40
 
import sys
41
 
import time
42
 
import traceback
43
 
 
44
 
# If ../nova/__init__.py exists, add ../ to Python search path, so that
45
 
# it will override what happens to be installed in /usr/(local/)lib/python...
46
 
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
47
 
                                   os.pardir,
48
 
                                   os.pardir))
49
 
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
50
 
    sys.path.insert(0, POSSIBLE_TOPDIR)
51
 
 
52
 
gettext.install('nova', unicode=1)
53
 
from nova import context
54
 
from nova import db
55
 
from nova import exception
56
 
from nova import flags
57
 
from nova.openstack.common import log as logging
58
 
from nova.openstack.common import rpc
59
 
from nova import utils
60
 
from nova.volume import utils as volume_utils
61
 
 
62
 
FLAGS = flags.FLAGS
63
 
 
64
 
if __name__ == '__main__':
65
 
    admin_context = context.get_admin_context()
66
 
    utils.default_cfgfile()
67
 
    flags.FLAGS(sys.argv)
68
 
    logging.setup("nova")
69
 
    begin, end = utils.last_completed_audit_period()
70
 
    print "Starting volume usage audit"
71
 
    print "Creating usages for %s until %s" % (str(begin), str(end))
72
 
    volumes = db.volume_get_active_by_window(admin_context,
73
 
                                             begin,
74
 
                                             end)
75
 
    print "Found %d volumes" % len(volumes)
76
 
    for volume_ref in volumes:
77
 
        try:
78
 
            volume_utils.notify_usage_exists(
79
 
                    admin_context, volume_ref)
80
 
        except Exception, e:
81
 
            print traceback.format_exc(e)
82
 
    print "Volume usage audit completed"