Changeset 2198 for trunk/packages/invirt-database/scripts
- Timestamp:
- Feb 27, 2009, 2:56:41 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-database/scripts/invirt-quota
r2194 r2198 7 7 """ 8 8 9 from invirt.database import * 10 from sys import argv, exit, stderr, stdout 11 from optparse import OptionParser 9 import sys 10 import optparse 11 12 from invirt import database 12 13 13 14 def main(argv): 14 parser = OptionParser(usage = '%prog <owner> [options]',15 parser = optparse.OptionParser(usage = '%prog <owner> [options]', 15 16 description = __doc__.strip()) 16 17 parser.add_option('-m', '--ram-total', … … 41 42 42 43 if len(args) != 1: 43 parser.print_help(s tderr)44 parser.print_help(sys.stderr) 44 45 return 1 45 46 owner = args[0] 46 connect()47 session.begin()47 database.connect() 48 database.session.begin() 48 49 49 x = Owner.query().filter_by(owner_id=owner).first()50 x = database.Owner.query().filter_by(owner_id=owner).first() 50 51 if x is None: 51 x = Owner(owner_id=owner)52 x = database.Owner(owner_id=owner) 52 53 53 54 for resource, scope in [('ram', 'total'), ('ram', 'single'), 54 55 ('disk', 'total'), ('disk', 'single'), 55 56 ('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: 59 59 setattr(x, resource+'_quota_'+scope, val if val >= 0 else None) 60 60 61 session.commit()61 database.session.commit() 62 62 print str(x) 63 63 return 0 64 64 65 65 if __name__ == '__main__': 66 exit(main(argv))66 sys.exit(main(sys.argv))
Note: See TracChangeset
for help on using the changeset viewer.