source: trunk/packages/invirt-database/python/database/owner.py @ 2459

Last change on this file since 2459 was 2213, checked in by quentin, 16 years ago

Fix get*Quotas

  • Property svn:executable set to *
File size: 1.5 KB
RevLine 
[2200]1from invirt.database import record
[2213]2from invirt.database.models import session
[2134]3
[2200]4class Owner(record.Record):
[2187]5    _f = {
6        'ram_quota_total': (512, 'MiB'),
7        'ram_quota_single': (512, 'MiB'),
8        'disk_quota_total': (50, 'GiB'),
9        'disk_quota_single': (50, 'GiB'),
10        'vms_quota_total': (10, ''),
11        'vms_quota_active': (4, '')
12    }
13    _default = dict([(_k,_v[0]) for _k,_v in _f.items()])
14    def _unitFormatter(unit):
15        return lambda v:'%s%s'%(v,unit)
16    _format = dict([(_k,_unitFormatter(_v[1])) for _k,_v in _f.items()])
17    _identity_field = 'owner_id'
18
[2191]19    @classmethod
20    def getMemoryQuotas(cls, owner):
[2213]21        owner_info = cls.query().get(owner)
[2187]22        if owner_info == None:
[2191]23            owner_info = cls(owner_id=owner)
[2213]24            session.expunge(owner_info)
[2187]25        return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single'))
26
[2191]27    @classmethod
28    def getDiskQuotas(cls, owner):
[2213]29        owner_info = cls.query().get(owner)
[2187]30        if owner_info == None:
[2191]31            owner_info = cls(owner_id=owner)
[2213]32            session.expunge(owner_info)
[2187]33        return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single'))
34
[2191]35    @classmethod
36    def getVMQuotas(cls, owner):
[2213]37        owner_info = cls.query().get(owner)
[2187]38        if owner_info == None:
[2191]39            owner_info = cls(owner_id=owner)
[2213]40            session.expunge(owner_info)
[2187]41        return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active'))
Note: See TracBrowser for help on using the repository browser.