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

Last change on this file since 2367 was 2213, checked in by quentin, 15 years ago

Fix get*Quotas

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1from invirt.database import record
2from invirt.database.models import session
3
4class Owner(record.Record):
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
19    @classmethod
20    def getMemoryQuotas(cls, owner):
21        owner_info = cls.query().get(owner)
22        if owner_info == None:
23            owner_info = cls(owner_id=owner)
24            session.expunge(owner_info)
25        return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single'))
26
27    @classmethod
28    def getDiskQuotas(cls, owner):
29        owner_info = cls.query().get(owner)
30        if owner_info == None:
31            owner_info = cls(owner_id=owner)
32            session.expunge(owner_info)
33        return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single'))
34
35    @classmethod
36    def getVMQuotas(cls, owner):
37        owner_info = cls.query().get(owner)
38        if owner_info == None:
39            owner_info = cls(owner_id=owner)
40            session.expunge(owner_info)
41        return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active'))
Note: See TracBrowser for help on using the repository browser.