Changeset 2194 for trunk


Ignore:
Timestamp:
Feb 27, 2009, 2:11:39 AM (16 years ago)
Author:
price
Message:

invirt-quota: refactor; print full help

Location:
trunk/packages/invirt-database
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-database/debian/changelog

    r2192 r2194  
    55
    66  [Greg Price]
     7  invirt.database.record, .owner:
    78  * use self.c rather than self.__dict__ for SQLAlchemy fields
    89  * make Record._ignore, Owner.get* classmethods
    910  * fold FormattableRecord, NullableRecord into Record
    1011  * shorten types in lists to __name__
     12 
     13  invirt-quota:
     14  * refactor code that sets values
     15  * print full help on no arguments
    1116
    1217 -- Greg Price <price@mit.edu>  Thu, 26 Feb 2009 22:51:43 -0500
  • trunk/packages/invirt-database/scripts/invirt-quota

    r2176 r2194  
    55for an owner.  Invoking with only an owner name returns the current quotas for
    66that owner.  Setting a parameter to -1 restores the default.
    7 
    8 Examples:
    9 
    10     invirt-quota joeuser -mt 512 -ms -1
    117"""
    128
     
    1612
    1713def main(argv):
    18     parser = OptionParser(usage = '%prog owner [options]',
    19             description = __doc__.strip().split('\n\n')[0])
    20     parser.add_option('-m', '--mem-total',
     14    parser = OptionParser(usage = '%prog <owner> [options]',
     15            description = __doc__.strip())
     16    parser.add_option('-m', '--ram-total',
    2117            type = 'int',
    22             dest = 'memtotal',
     18            dest = 'ramtotal',
    2319            help = 'set total concurrent RAM quota')
    24     parser.add_option('-n', '--mem-single',
     20    parser.add_option('-n', '--ram-single',
    2521            type = 'int',
    26             dest = 'memsingle',
     22            dest = 'ramsingle',
    2723            help = 'set single VM RAM quota')
    2824    parser.add_option('-d', '--disk-total',
     
    4541
    4642    if len(args) != 1:
    47         print >> stderr, __doc__.strip()
     43        parser.print_help(stderr)
    4844        return 1
    4945    owner = args[0]
     
    5248   
    5349    x = Owner.query().filter_by(owner_id=owner).first()
    54     if x == None:
     50    if x is None:
    5551        x = Owner(owner_id=owner)
    5652
    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
    63 
    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
    70 
    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
    77 
    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
    84 
    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
    91 
    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
     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)
     57        if opt is not None:
     58            val = int(opt)
     59            setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)
    9860
    9961    session.commit()
Note: See TracChangeset for help on using the changeset viewer.