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.
12 from invirt import database
15 parser = optparse.OptionParser(usage = '%prog <owner> [options]',
16 description = __doc__.strip())
17 parser.add_option('-m', '--ram-total',
20 help = 'set total concurrent RAM quota')
21 parser.add_option('-n', '--ram-single',
24 help = 'set single VM RAM quota')
25 parser.add_option('-d', '--disk-total',
28 help = 'set total disk quota')
29 parser.add_option('-e', '--disk-single',
32 help = 'set single VM disk quota')
33 parser.add_option('-v', '--vms-total',
36 help = 'set total VM quota')
37 parser.add_option('-w', '--vms-active',
40 help = 'set active VM quota')
41 opts, args = parser.parse_args()
44 parser.print_help(sys.stderr)
48 database.session.begin()
50 owner = database.Owner.query().filter_by(owner_id=owner_id).first()
52 owner = database.Owner(owner_id=owner_id)
54 for resource, scope in [('ram', 'total'), ('ram', 'single'),
55 ('disk', 'total'), ('disk', 'single'),
56 ('vms', 'total'), ('vms', 'active')]:
57 val = getattr(opts, resource+scope)
59 setattr(owner, resource+'_quota_'+scope, val if val >= 0 else None)
61 database.session.commit()
65 if __name__ == '__main__':
66 sys.exit(main(sys.argv))