1 from invirt.database import record
3 class Owner(record.Record):
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, '')
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'
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'))
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'))
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'))