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

Last change on this file since 2191 was 2191, checked in by price, 16 years ago

small fixes to Record

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