Changeset 2135 for trunk/packages


Ignore:
Timestamp:
Feb 17, 2009, 2:16:12 AM (16 years ago)
Author:
iannucci
Message:

Made some changes requested by Broder.

Location:
trunk/packages
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-base/scripts/invirt-setquotas

    r2134 r2135  
    88Examples:
    99
    10     invirt-setquota joeuser -mt 512 -ms None
     10    invirt-setquota joeuser -mt 512 -ms -1
    1111"""
    1212
     
    1515from optparse import OptionParser
    1616
    17 class invirt_exception(Exception): pass
     17def main(argv):
     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()
    1845
    19 def main(argv):
    20     try:
    21         parser = OptionParser(usage = '%prog owner [options]',
    22                 description = __doc__.strip().split('\n\n')[0])
    23         parser.add_option('-m', '--mem-total',
    24                 type = 'int',
    25                 dest = 'memtotal',
    26                 help = 'set total concurrent RAM quota')
    27         parser.add_option('-n', '--mem-single',
    28                 type = 'int',
    29                 dest = 'memsingle',
    30                 help = 'set single VM RAM quota')
    31         parser.add_option('-d', '--disk-total',
    32                 type = 'int',
    33                 dest = 'disktotal',
    34                 help = 'set total disk quota')
    35         parser.add_option('-e', '--disk-single',
    36                 type = 'int',
    37                 dest = 'disksingle',
    38                 help = 'set single VM disk quota')
    39         parser.add_option('-v', '--vms-total',
    40                 type = 'int',
    41                 dest = 'vmstotal',
    42                 help = 'set total VM quota')
    43         parser.add_option('-w', '--vms-active',
    44                 type = 'int',
    45                 dest = 'vmsactive',
    46                 help = 'set active VM quota')
    47         opts, args = parser.parse_args()
     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)
    4858
    49         print opts
    50         if len(args) != 1:
    51             raise invirt_exception(__doc__.strip())
    52         owner = args[0]
    53         connect()
    54         session.begin()
    55        
    56         x = Owner.query().filter_by(owner_id=owner).first()
     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
    5765
    58         edited = False
    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
    65             edited = True
     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
    6672
    67         if opts.memsingle != None:
    68             single = int(opts.memsingle)
    69             if single == -1:
    70                 x.ram_quota_single = None
    71             else:
    72                 x.ram_quota_single = single
    73             edited = True
     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
    7479
    75         if opts.disktotal != None:
    76             total = int(opts.disktotal)
    77             if total == -1:
    78                 x.disk_quota_total = None
    79             else:
    80                 x.disk_quota_total = total
    81             edited = True
     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
    8286
    83         if opts.disksingle != None:
    84             single = int(opts.disksingle)
    85             if single == -1:
    86                 x.disk_quota_single = None
    87             else:
    88                 x.disk_quota_single = single
    89             edited = True
     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
    9093
    91         if opts.vmstotal != None:
    92             total = int(opts.vmstotal)
    93             if total == -1:
    94                 x.vms_quota_total = None
    95             else:
    96                 x.vms_quota_total = total
    97             edited = True
     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
    98100
    99         if opts.vmsactive != None:
    100             active = int(opts.vmsactive)
    101             if active == -1:
    102                 x.vms_quota_active = None
    103             else:
    104                 x.vms_quota_active = active
    105             edited = True
    106 
    107         if edited:
    108             session.commit()
    109         print str(x)
    110 
    111     except invirt_exception, ex:
    112         print >> stderr, ex
    113         return 1
     101    session.commit()
     102    print str(x)
     103    return 0
    114104
    115105if __name__ == '__main__':
  • trunk/packages/invirt-database/python/database/models.py

    r2134 r2135  
    55from sqlalchemy.ext.sessioncontext import SessionContext
    66from sqlalchemy.ext.assignmapper import assign_mapper
     7
     8from owner import Owner
    79
    810__all__ = ['meta',
     
    131133        return "<Autoinstall %s: %s (%s)>" % (self.autoinstall_id, self.description, self.type.type_id)
    132134
    133 from owner import Owner
    134 
    135135session.mapper(Machine, machine_table,
    136136              properties={'nics': relation(NIC, backref="machine"),
  • trunk/packages/invirt-database/python/database/owner.py

    r2134 r2135  
    1010        return """<Owner %s: ram_quota_total=%s MB ram_quota_single=%s MB
    1111disk_quota_total=%s MB disk_quota_single=%s MB
    12 vms_quota_total=%s vms_quota_active=%s >""" % (self.owner_id, self.ram_quota_total, self.ram_quota_single, self.disk_quota_total, self.disk_quota_single, self.vms_quota_total, self.vms_quota_active)
     12vms_quota_total=%s vms_quota_active=%s >""" % (self.owner_id,
     13               self.ram_quota_total if self.ram_quota_total else MAX_MEMORY_TOTAL,
     14               self.ram_quota_single if self.ram_quota_single else MAX_MEMORY_SINGLE,
     15               self.disk_quota_total if self.disk_quota_total else MAX_DISK_TOTAL,
     16               self.disk_quota_single if self.disk_quota_single else MAX_DISK_SINGLE,
     17               self.vms_quota_total if self.vms_quota_total else MAX_VMS_TOTAL,
     18               self.vms_quota_active if self.vms_quota_active else MAX_VMS_ACTIVE)
    1319    def getMemoryQuotas(owner):
    1420        owner_info = Owner.query().filter_by(owner_id=owner).first()
  • trunk/packages/invirt-remote/debian/changelog

    r2134 r2135  
     1invirt-remote (0.3.5) unstable; urgency=low
     2
     3  * updated quota support to refer to renamed owner table columns
     4
     5 -- Peter A. Iannucci <iannucci@mit.edu>  Tue, 17 Feb 2009 02:13:44 -0500
     6
    17invirt-remote (0.3.4) unstable; urgency=low
    28
  • trunk/packages/invirt-remote/server/usr/sbin/invirt-remote-create

    r2134 r2135  
    2424    active_machines = [m for m in machines if m.name in xmlist]
    2525    mem_usage = sum([x.memory for x in active_machines])
    26     return min(quota_single, quota_total-mem_usage)
     26    return min(quota_single, quota_total - mem_usage)
    2727
    2828def choose_host():
     
    3838    machine_name = argv[2]
    3939    args = argv[3:]
    40    
     40
     41    invirt.database.connect()
     42
    4143    if operation == 'install':
    4244        options = dict(arg.split('=', 1) for arg in args)
     
    6365
    6466    if operation == "create":
    65         invirt.database.connect()
    6667        machine = invirt.database.Machine.query().filter_by(name=machine_name).first()
    6768
Note: See TracChangeset for help on using the changeset viewer.