4 invirt-quota allows an administrator to set memory, disk, and VM quotas
5 for an owner. Invoking with only an owner name returns the current quotas for
6 that owner. Setting a parameter to -1 restores the default.
9 from invirt.database import *
10 from sys import argv, exit, stderr, stdout
11 from optparse import OptionParser
14 parser = OptionParser(usage = '%prog <owner> [options]',
15 description = __doc__.strip())
16 parser.add_option('-m', '--ram-total',
19 help = 'set total concurrent RAM quota')
20 parser.add_option('-n', '--ram-single',
23 help = 'set single VM RAM quota')
24 parser.add_option('-d', '--disk-total',
27 help = 'set total disk quota')
28 parser.add_option('-e', '--disk-single',
31 help = 'set single VM disk quota')
32 parser.add_option('-v', '--vms-total',
35 help = 'set total VM quota')
36 parser.add_option('-w', '--vms-active',
39 help = 'set active VM quota')
40 opts, args = parser.parse_args()
43 parser.print_help(stderr)
49 x = Owner.query().filter_by(owner_id=owner).first()
51 x = Owner(owner_id=owner)
53 for resource, scope in [('ram', 'total'), ('ram', 'single'),
54 ('disk', 'total'), ('disk', 'single'),
55 ('vms', 'total'), ('vms', 'active')]:
56 opt = getattr(opts, resource+scope)
59 setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)
65 if __name__ == '__main__':