source: trunk/packages/invirt-base/scripts/invirt-setquotas @ 2144

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

Made some changes requested by Broder.

  • Property svn:executable set to *
File size: 3.0 KB
RevLine 
[2132]1#!/usr/bin/env python
2
3"""
[2134]4invirt-setquota allows an administrator to set memory, disk, and VM quotas
5for an owner.  Invoking with only an owner name returns the current quotas for
6that owner.  Setting a parameter to -1 restores the default.
[2132]7
8Examples:
9
[2135]10    invirt-setquota joeuser -mt 512 -ms -1
[2132]11"""
12
13from invirt.database import *
14from sys import argv, exit, stderr, stdout
15from optparse import OptionParser
16
17def main(argv):
[2135]18    parser = OptionParser(usage = '%prog owner [options]',
19            description = __doc__.strip().split('\n\n')[0])
20    parser.add_option('-m', '--mem-total',
21            type = 'int',
22            dest = 'memtotal',
23            help = 'set total concurrent RAM quota')
24    parser.add_option('-n', '--mem-single',
25            type = 'int',
26            dest = 'memsingle',
27            help = 'set single VM RAM quota')
28    parser.add_option('-d', '--disk-total',
29            type = 'int',
30            dest = 'disktotal',
31            help = 'set total disk quota')
32    parser.add_option('-e', '--disk-single',
33            type = 'int',
34            dest = 'disksingle',
35            help = 'set single VM disk quota')
36    parser.add_option('-v', '--vms-total',
37            type = 'int',
38            dest = 'vmstotal',
39            help = 'set total VM quota')
40    parser.add_option('-w', '--vms-active',
41            type = 'int',
42            dest = 'vmsactive',
43            help = 'set active VM quota')
44    opts, args = parser.parse_args()
[2132]45
[2135]46    if len(args) != 1:
47        print >> stderr, __doc__.strip()
48        return 1
49    owner = args[0]
50    connect()
51    session.begin()
52   
53    x = Owner.query().filter_by(owner_id=owner).first()
54    if x == None:
55        x = Owner(owner_id=owner, ram_quota_total=None, ram_quota_single=None,
56                  disk_quota_total=None, disk_quota_single=None,
57                  vms_quota_total=None, vms_quota_active)
[2132]58
[2135]59    if opts.memtotal != None:
60        total = int(opts.memtotal)
61        if total == -1:
62            x.ram_quota_total = None
63        else:
64            x.ram_quota_total = total
[2132]65
[2135]66    if opts.memsingle != None:
67        single = int(opts.memsingle)
68        if single == -1:
69            x.ram_quota_single = None
70        else:
71            x.ram_quota_single = single
[2132]72
[2135]73    if opts.disktotal != None:
74        total = int(opts.disktotal)
75        if total == -1:
76            x.disk_quota_total = None
77        else:
78            x.disk_quota_total = total
[2134]79
[2135]80    if opts.disksingle != None:
81        single = int(opts.disksingle)
82        if single == -1:
83            x.disk_quota_single = None
84        else:
85            x.disk_quota_single = single
[2134]86
[2135]87    if opts.vmstotal != None:
88        total = int(opts.vmstotal)
89        if total == -1:
90            x.vms_quota_total = None
91        else:
92            x.vms_quota_total = total
[2134]93
[2135]94    if opts.vmsactive != None:
95        active = int(opts.vmsactive)
96        if active == -1:
97            x.vms_quota_active = None
98        else:
99            x.vms_quota_active = active
[2134]100
[2135]101    session.commit()
102    print str(x)
103    return 0
[2132]104
105if __name__ == '__main__':
106    exit(main(argv))
Note: See TracBrowser for help on using the repository browser.