also needn't call int() on value from optparse
svn path=/trunk/packages/invirt-database/; revision=2198
invirt-quota:
* refactor code that sets values
* print full help on no arguments
invirt-quota:
* refactor code that sets values
* print full help on no arguments
- -- Greg Price <price@mit.edu> Thu, 26 Feb 2009 22:51:43 -0500
+ -- Greg Price <price@mit.edu> Fri, 27 Feb 2009 02:16:28 -0500
invirt-database (0.1.7) unstable; urgency=low
invirt-database (0.1.7) unstable; urgency=low
that owner. Setting a parameter to -1 restores the default.
"""
that owner. Setting a parameter to -1 restores the default.
"""
-from invirt.database import *
-from sys import argv, exit, stderr, stdout
-from optparse import OptionParser
+import sys
+import optparse
+
+from invirt import database
- parser = OptionParser(usage = '%prog <owner> [options]',
+ parser = optparse.OptionParser(usage = '%prog <owner> [options]',
description = __doc__.strip())
parser.add_option('-m', '--ram-total',
type = 'int',
description = __doc__.strip())
parser.add_option('-m', '--ram-total',
type = 'int',
opts, args = parser.parse_args()
if len(args) != 1:
opts, args = parser.parse_args()
if len(args) != 1:
- parser.print_help(stderr)
+ parser.print_help(sys.stderr)
- connect()
- session.begin()
+ database.connect()
+ database.session.begin()
- x = Owner.query().filter_by(owner_id=owner).first()
+ x = database.Owner.query().filter_by(owner_id=owner).first()
- x = Owner(owner_id=owner)
+ x = database.Owner(owner_id=owner)
for resource, scope in [('ram', 'total'), ('ram', 'single'),
('disk', 'total'), ('disk', 'single'),
('vms', 'total'), ('vms', 'active')]:
for resource, scope in [('ram', 'total'), ('ram', 'single'),
('disk', 'total'), ('disk', 'single'),
('vms', 'total'), ('vms', 'active')]:
- opt = getattr(opts, resource+scope)
- if opt is not None:
- val = int(opt)
+ val = getattr(opts, resource+scope)
+ if val is not None:
setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)
setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)
+ database.session.commit()
print str(x)
return 0
if __name__ == '__main__':
print str(x)
return 0
if __name__ == '__main__':
+ sys.exit(main(sys.argv))