X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-database.git/blobdiff_plain/f27d53bc4beda55662917856b1b7ca8321f72e3b..6dc450951772a078d728538a24006896112bfefb:/scripts/invirt-quota diff --git a/scripts/invirt-quota b/scripts/invirt-quota index 8a7f67c..22c663a 100755 --- a/scripts/invirt-quota +++ b/scripts/invirt-quota @@ -6,12 +6,13 @@ for an owner. Invoking with only an owner name returns the current quotas for 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 [options]', + parser = optparse.OptionParser(usage = '%prog [options]', description = __doc__.strip()) parser.add_option('-m', '--ram-total', type = 'int', @@ -40,27 +41,26 @@ def main(argv): 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() + database.connect() + database.session.begin() - x = Owner.query().filter_by(owner_id=owner).first() + x = database.Owner.query().filter_by(owner_id=owner).first() if x is None: - 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')]: - 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) - session.commit() + database.session.commit() print str(x) return 0 if __name__ == '__main__': - exit(main(argv)) + sys.exit(main(sys.argv))