Changeset 2134


Ignore:
Timestamp:
Feb 17, 2009, 1:54:26 AM (16 years ago)
Author:
iannucci
Message:

Added all the other quotas for great win.

Location:
trunk/packages
Files:
8 edited
1 moved

Legend:

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

    r2132 r2134  
    33  * added invirt-setquota script (self-documenting)
    44
    5  -- Peter A. Iannucci <iannucci@mit.edu>  Mon, 16 Feb 2009 23:48:25 -0500
     5 -- Peter A. Iannucci <iannucci@mit.edu>  Tue, 17 Feb 2009 01:43:54 -0500
    66
    77invirt-base (0.0.20) unstable; urgency=low
  • trunk/packages/invirt-base/scripts/invirt-setquotas

    r2132 r2134  
    22
    33"""
    4 invirt-setquota allows an administrator to set the RAM quotas for an owner.
    5 Invoking with only an owner name returns the current quotas for that owner.
    6 Setting a parameter to -1 restores the default.
     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.
    77
    88Examples:
    99
    10     invirt-setquota joeuser -t 512 -s None
     10    invirt-setquota joeuser -mt 512 -ms None
    1111"""
    1212
     
    2121        parser = OptionParser(usage = '%prog owner [options]',
    2222                description = __doc__.strip().split('\n\n')[0])
    23         parser.add_option('-t', '--total',
     23        parser.add_option('-m', '--mem-total',
    2424                type = 'int',
    25                 dest = 'total',
    26                 help = 'set the total concurrent RAM quota')
    27         parser.add_option('-s', '--single',
     25                dest = 'memtotal',
     26                help = 'set total concurrent RAM quota')
     27        parser.add_option('-n', '--mem-single',
    2828                type = 'int',
    29                 dest = 'single',
    30                 help = 'set the single VM RAM quota')
     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')
    3147        opts, args = parser.parse_args()
    3248
     49        print opts
    3350        if len(args) != 1:
    3451            raise invirt_exception(__doc__.strip())
     
    4057
    4158        edited = False
    42         if opts.total != None:
    43             total = int(opts.total)
     59        if opts.memtotal != None:
     60            total = int(opts.memtotal)
    4461            if total == -1:
    4562                x.ram_quota_total = None
     
    4865            edited = True
    4966
    50         if opts.single != None:
    51             single = int(opts.single)
     67        if opts.memsingle != None:
     68            single = int(opts.memsingle)
    5269            if single == -1:
    5370                x.ram_quota_single = None
    5471            else:
    5572                x.ram_quota_single = single
     73            edited = True
     74
     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
     82
     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
     90
     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
     98
     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
    56105            edited = True
    57106
  • trunk/packages/invirt-database/debian/changelog

    r2132 r2134  
    11invirt-database (0.1.3) unstable; urgency=low
    22
    3   * Added owner table with ram quotas.
     3  * Added owner table to database with ram, disk, and VM quotas
    44  * Refactored Owner class into separate sourcefile
    55
    6  -- Peter A. Iannucci <iannucci@mit.edu>  Mon, 16 Feb 2009 23:49:39 -0500
     6 -- Peter A. Iannucci <iannucci@mit.edu>  Tue, 17 Feb 2009 01:31:53 -0500
    77
    88invirt-database (0.1.2) unstable; urgency=low
  • trunk/packages/invirt-database/python/database/models.py

    r2132 r2134  
    8888       Column('owner_id', String, primary_key=True, nullable=False),
    8989       Column('ram_quota_total', Integer, nullable=True),
    90        Column('ram_quota_single', Integer, nullable=True))
     90       Column('ram_quota_single', Integer, nullable=True),
     91       Column('disk_quota_total', Integer, nullable=True),
     92       Column('disk_quota_single', Integer, nullable=True),
     93       Column('vms_quota_total', Integer, nullable=True),
     94       Column('vms_quota_active', Integer, nullable=True))
    9195
    9296machine_access_table = Table('machine_access', meta,
  • trunk/packages/invirt-database/python/database/owner.py

    r2132 r2134  
    11MAX_MEMORY_TOTAL = 512
    22MAX_MEMORY_SINGLE = 512
     3MAX_DISK_TOTAL = 50
     4MAX_DISK_SINGLE = 50
     5MAX_VMS_TOTAL = 10
     6MAX_VMS_ACTIVE = 4
     7
    38class Owner(object):
    49    def __repr__(self):
    5         return "<Owner %s: ram_quota_total=%s MB ram_quota_single=%s MB>" % (self.owner_id, self.ram_quota_total, self.ram_quota_single)
    6     def getQuotas(owner):
     10        return """<Owner %s: ram_quota_total=%s MB ram_quota_single=%s MB
     11disk_quota_total=%s MB disk_quota_single=%s MB
     12vms_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)
     13    def getMemoryQuotas(owner):
    714        owner_info = Owner.query().filter_by(owner_id=owner).first()
    815        if owner_info != None:
     
    1724            quota_single = MAX_MEMORY_SINGLE
    1825        return (quota_total, quota_single)
    19     getQuotas = staticmethod(getQuotas)
     26    getMemoryQuotas = staticmethod(getMemoryQuotas)
     27    def getDiskQuotas(owner):
     28        owner_info = Owner.query().filter_by(owner_id=owner).first()
     29        if owner_info != None:
     30            quota_total = owner_info.disk_quota_total
     31            if quota_total == None:
     32                quota_total = MAX_DISK_TOTAL
     33            quota_single = owner_info.disk_quota_single
     34            if quota_single == None:
     35                quota_single = MAX_DISK_SINGLE
     36        else:
     37            quota_total = MAX_DISK_TOTAL
     38            quota_single = MAX_DISK_SINGLE
     39        return (quota_total, quota_single)
     40    getDiskQuotas = staticmethod(getDiskQuotas)
     41    def getVMQuotas(owner):
     42        owner_info = Owner.query().filter_by(owner_id=owner).first()
     43        if owner_info != None:
     44            quota_total = owner_info.vms_quota_total
     45            if quota_total == None:
     46                quota_total = MAX_VMS_TOTAL
     47            quota_active = owner_info.vms_quota_active
     48            if quota_active == None:
     49                quota_active = MAX_VMS_ACTIVE
     50        else:
     51            quota_total = MAX_VMS_TOTAL
     52            quota_single = MAX_VMS_ACTIVE
     53        return (quota_total, quota_active)
     54    getVMQuotas = staticmethod(getVMQuotas)
  • trunk/packages/invirt-remote/debian/changelog

    r2132 r2134  
    55    refuse to create VMs
    66  * added memory quota validation to invirt-remote-create
    7   * added owner table to database with ram_quota_total and ram_quota_single
    8 
    9  -- Peter A. Iannucci <iannucci@mit.edu>  Mon, 16 Feb 2009 23:49:14 -0500
     7
     8 -- Peter A. Iannucci <iannucci@mit.edu>  Tue, 17 Feb 2009 01:31:20 -0500
    109
    1110invirt-remote (0.3.3) unstable; urgency=low
  • trunk/packages/invirt-remote/server/usr/sbin/invirt-remote-create

    r2132 r2134  
    2020    """
    2121    machines = invirt.database.Machine.query().filter_by(owner=owner)
    22     (quota_total, quota_single) = invirt.database.Owner.getQuotas(owner)
     22    (quota_total, quota_single) = invirt.database.Owner.getMemoryQuotas(owner)
    2323
    2424    active_machines = [m for m in machines if m.name in xmlist]
  • trunk/packages/invirt-web/code/validation.py

    r2132 r2134  
    1111
    1212MIN_MEMORY_SINGLE = 16
    13 MAX_DISK_TOTAL = 50
    14 MAX_DISK_SINGLE = 50
    1513MIN_DISK_SINGLE = 0.1
    16 MAX_VMS_TOTAL = 10
    17 MAX_VMS_ACTIVE = 4
    1814
    1915class Validate:
     
    9086    returned.
    9187    """
    92     (quota_total, quota_single) = Owner.getQuotas(machine.owner if machine else owner)
     88    (quota_total, quota_single) = Owner.getMemoryQuotas(machine.owner if machine else owner)
    9389
    9490    if not on:
     
    105101    return the maximum that a given machine can be changed to.
    106102    """
     103    (quota_total, quota_single) = Owner.getDiskQuotas(machine.owner if machine else owner)
     104
    107105    if machine is not None:
    108106        machine_id = machine.machine_id
     
    112110                     join('machine').\
    113111                     filter_by(owner=owner).sum(Disk.c.size) or 0
    114     return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.)
     112    return min(quota_single, quota_total-disk_usage/1024.)
    115113
    116114def cantAddVm(owner, g):
    117115    machines = getMachinesByOwner(owner)
    118116    active_machines = [m for m in machines if m.name in g.xmlist_raw]
    119     if machines.count() >= MAX_VMS_TOTAL:
     117    (quota_total, quota_active) = Owner.getVMQuotas(machine.owner if machine else owner)
     118    if machines.count() >= quota_total:
    120119        return 'You have too many VMs to create a new one.'
    121     if len(active_machines) >= MAX_VMS_ACTIVE:
     120    if len(active_machines) >= quota_active:
    122121        return ('You already have the maximum number of VMs turned on.  '
    123122                'To create more, turn one off.')
  • trunk/packages/invirt-web/debian/changelog

    r2132 r2134  
    33  * modified quota checking to refer to invirt.database.Owner for quotas and defaults
    44
    5  -- Peter A. Iannucci <iannucci@mit.edu>  Mon, 16 Feb 2009 23:49:21 -0500
     5 -- Peter A. Iannucci <iannucci@mit.edu>  Tue, 17 Feb 2009 01:31:01 -0500
    66
    77invirt-web (0.0.18) unstable; urgency=low
Note: See TracChangeset for help on using the changeset viewer.