Changeset 2198


Ignore:
Timestamp:
Feb 27, 2009, 2:56:41 AM (15 years ago)
Author:
price
Message:

invirt-quota: fix imports EIBTI-style

also needn't call int() on value from optparse

Location:
trunk/packages/invirt-database
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-database/debian/changelog

    r2194 r2198  
    1414  * refactor code that sets values
    1515  * print full help on no arguments
    16 
    17  -- Greg Price <price@mit.edu>  Thu, 26 Feb 2009 22:51:43 -0500
     16  * make EIBTI imports
     17
     18 -- Greg Price <price@mit.edu>  Fri, 27 Feb 2009 02:16:28 -0500
    1819
    1920invirt-database (0.1.7) unstable; urgency=low
  • trunk/packages/invirt-database/scripts/invirt-quota

    r2194 r2198  
    77"""
    88
    9 from invirt.database import *
    10 from sys import argv, exit, stderr, stdout
    11 from optparse import OptionParser
     9import sys
     10import optparse
     11
     12from invirt import database
    1213
    1314def main(argv):
    14     parser = OptionParser(usage = '%prog <owner> [options]',
     15    parser = optparse.OptionParser(usage = '%prog <owner> [options]',
    1516            description = __doc__.strip())
    1617    parser.add_option('-m', '--ram-total',
     
    4142
    4243    if len(args) != 1:
    43         parser.print_help(stderr)
     44        parser.print_help(sys.stderr)
    4445        return 1
    4546    owner = args[0]
    46     connect()
    47     session.begin()
     47    database.connect()
     48    database.session.begin()
    4849   
    49     x = Owner.query().filter_by(owner_id=owner).first()
     50    x = database.Owner.query().filter_by(owner_id=owner).first()
    5051    if x is None:
    51         x = Owner(owner_id=owner)
     52        x = database.Owner(owner_id=owner)
    5253
    5354    for resource, scope in [('ram',  'total'), ('ram',  'single'),
    5455                            ('disk', 'total'), ('disk', 'single'),
    5556                            ('vms',  'total'), ('vms',  'active')]:
    56         opt = getattr(opts, resource+scope)
    57         if opt is not None:
    58             val = int(opt)
     57        val = getattr(opts, resource+scope)
     58        if val is not None:
    5959            setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)
    6060
    61     session.commit()
     61    database.session.commit()
    6262    print str(x)
    6363    return 0
    6464
    6565if __name__ == '__main__':
    66     exit(main(argv))
     66    sys.exit(main(sys.argv))
Note: See TracChangeset for help on using the changeset viewer.