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
def main(argv):
- parser = OptionParser(usage = '%prog <owner> [options]',
+ parser = optparse.OptionParser(usage = '%prog <owner> [options]',
description = __doc__.strip())
parser.add_option('-m', '--ram-total',
type = 'int',
opts, args = parser.parse_args()
if len(args) != 1:
- parser.print_help(stderr)
+ parser.print_help(sys.stderr)
return 1
- owner = args[0]
- connect()
- session.begin()
+ owner_id = args[0]
+ database.connect()
+ database.session.begin()
- x = Owner.query().filter_by(owner_id=owner).first()
- if x is None:
- x = Owner(owner_id=owner)
+ owner = database.Owner.query().filter_by(owner_id=owner_id).first()
+ if owner is None:
+ owner = database.Owner(owner_id=owner_id)
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)
- setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)
+ val = getattr(opts, resource+scope)
+ if val is not None:
+ setattr(owner, resource+'_quota_'+scope, val if val >= 0 else None)
- session.commit()
- print str(x)
+ database.session.commit()
+ print owner
return 0
if __name__ == '__main__':
- exit(main(argv))
+ sys.exit(main(sys.argv))