adb176c8ffaee8605f64fe8badb002cfaba75d90
[invirt/packages/invirt-database.git] / python / database / owner.py
1 from record import NullableRecord
2
3 class 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     def getMemoryQuotas(owner):
19         owner_info = Owner.query().filter_by(owner_id=owner).first()
20         if owner_info == None:
21             owner_info = Owner(owner_id=owner)
22         return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single'))
23     getMemoryQuotas = staticmethod(getMemoryQuotas)
24
25     def getDiskQuotas(owner):
26         owner_info = Owner.query().filter_by(owner_id=owner).first()
27         if owner_info == None:
28             owner_info = Owner(owner_id=owner)
29         return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single'))
30     getDiskQuotas = staticmethod(getDiskQuotas)
31
32     def getVMQuotas(owner):
33         owner_info = Owner.query().filter_by(owner_id=owner).first()
34         if owner_info == None:
35             owner_info = Owner(owner_id=owner)
36         return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active'))
37     getVMQuotas = staticmethod(getVMQuotas)
38
39     def _ignore(self):
40         return super(Owner, self)._ignore() + ['getMemoryQuotas', 'getDiskQuotas', 'getVMQuotas']