source: trunk/packages/invirt-database/scripts/invirt-quota @ 2180

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

Fixed docstring in invirt-quota script to reflect new name.

  • Property svn:executable set to *
File size: 2.8 KB
RevLine 
[2132]1#!/usr/bin/env python
2
3"""
[2176]4invirt-quota allows an administrator to set memory, disk, and VM quotas
[2134]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
[2176]10    invirt-quota 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:
[2152]55        x = Owner(owner_id=owner)
[2132]56
[2135]57    if opts.memtotal != None:
58        total = int(opts.memtotal)
59        if total == -1:
60            x.ram_quota_total = None
61        else:
62            x.ram_quota_total = total
[2132]63
[2135]64    if opts.memsingle != None:
65        single = int(opts.memsingle)
66        if single == -1:
67            x.ram_quota_single = None
68        else:
69            x.ram_quota_single = single
[2132]70
[2135]71    if opts.disktotal != None:
72        total = int(opts.disktotal)
73        if total == -1:
74            x.disk_quota_total = None
75        else:
76            x.disk_quota_total = total
[2134]77
[2135]78    if opts.disksingle != None:
79        single = int(opts.disksingle)
80        if single == -1:
81            x.disk_quota_single = None
82        else:
83            x.disk_quota_single = single
[2134]84
[2135]85    if opts.vmstotal != None:
86        total = int(opts.vmstotal)
87        if total == -1:
88            x.vms_quota_total = None
89        else:
90            x.vms_quota_total = total
[2134]91
[2135]92    if opts.vmsactive != None:
93        active = int(opts.vmsactive)
94        if active == -1:
95            x.vms_quota_active = None
96        else:
97            x.vms_quota_active = active
[2134]98
[2135]99    session.commit()
100    print str(x)
101    return 0
[2132]102
103if __name__ == '__main__':
104    exit(main(argv))
Note: See TracBrowser for help on using the repository browser.