source: trunk/packages/invirt-base/scripts/invirt-setquota @ 2132

Last change on this file since 2132 was 2132, checked in by iannucci, 16 years ago

RAM quotas at remctl; RAM quota exception script, table, and usage in -web and -remote-create; /etc/nocreate support

  • Property svn:executable set to *
File size: 1.8 KB
RevLine 
[2132]1#!/usr/bin/env python
2
3"""
4invirt-setquota allows an administrator to set the RAM quotas for an owner.
5Invoking with only an owner name returns the current quotas for that owner.
6Setting a parameter to -1 restores the default.
7
8Examples:
9
10    invirt-setquota joeuser -t 512 -s None
11"""
12
13from invirt.database import *
14from sys import argv, exit, stderr, stdout
15from optparse import OptionParser
16
17class invirt_exception(Exception): pass
18
19def main(argv):
20    try:
21        parser = OptionParser(usage = '%prog owner [options]',
22                description = __doc__.strip().split('\n\n')[0])
23        parser.add_option('-t', '--total',
24                type = 'int',
25                dest = 'total',
26                help = 'set the total concurrent RAM quota')
27        parser.add_option('-s', '--single',
28                type = 'int',
29                dest = 'single',
30                help = 'set the single VM RAM quota')
31        opts, args = parser.parse_args()
32
33        if len(args) != 1:
34            raise invirt_exception(__doc__.strip())
35        owner = args[0]
36        connect()
37        session.begin()
38       
39        x = Owner.query().filter_by(owner_id=owner).first()
40
41        edited = False
42        if opts.total != None:
43            total = int(opts.total)
44            if total == -1:
45                x.ram_quota_total = None
46            else:
47                x.ram_quota_total = total
48            edited = True
49
50        if opts.single != None:
51            single = int(opts.single)
52            if single == -1:
53                x.ram_quota_single = None
54            else:
55                x.ram_quota_single = single
56            edited = True
57
58        if edited:
59            session.commit()
60        print str(x)
61
62    except invirt_exception, ex:
63        print >> stderr, ex
64        return 1
65
66if __name__ == '__main__':
67    exit(main(argv))
Note: See TracBrowser for help on using the repository browser.