[2187] | 1 | from record import NullableRecord |
---|
[2134] | 2 | |
---|
[2187] | 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 | |
---|
[2191] | 18 | @classmethod |
---|
| 19 | def getMemoryQuotas(cls, owner): |
---|
| 20 | owner_info = cls.query().filter_by(owner_id=owner).first() |
---|
[2187] | 21 | if owner_info == None: |
---|
[2191] | 22 | owner_info = cls(owner_id=owner) |
---|
[2187] | 23 | return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single')) |
---|
| 24 | |
---|
[2191] | 25 | @classmethod |
---|
| 26 | def getDiskQuotas(cls, owner): |
---|
| 27 | owner_info = cls.query().filter_by(owner_id=owner).first() |
---|
[2187] | 28 | if owner_info == None: |
---|
[2191] | 29 | owner_info = cls(owner_id=owner) |
---|
[2187] | 30 | return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single')) |
---|
| 31 | |
---|
[2191] | 32 | @classmethod |
---|
| 33 | def getVMQuotas(cls, owner): |
---|
| 34 | owner_info = cls.query().filter_by(owner_id=owner).first() |
---|
[2187] | 35 | if owner_info == None: |
---|
[2191] | 36 | owner_info = cls(owner_id=owner) |
---|
[2187] | 37 | return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active')) |
---|