[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 | |
---|
[2134] | 18 | def getMemoryQuotas(owner): |
---|
[2132] | 19 | owner_info = Owner.query().filter_by(owner_id=owner).first() |
---|
[2187] | 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')) |
---|
[2134] | 23 | getMemoryQuotas = staticmethod(getMemoryQuotas) |
---|
[2187] | 24 | |
---|
[2134] | 25 | def getDiskQuotas(owner): |
---|
| 26 | owner_info = Owner.query().filter_by(owner_id=owner).first() |
---|
[2187] | 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')) |
---|
[2134] | 30 | getDiskQuotas = staticmethod(getDiskQuotas) |
---|
[2187] | 31 | |
---|
[2134] | 32 | def getVMQuotas(owner): |
---|
| 33 | owner_info = Owner.query().filter_by(owner_id=owner).first() |
---|
[2187] | 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')) |
---|
[2134] | 37 | getVMQuotas = staticmethod(getVMQuotas) |
---|
[2187] | 38 | |
---|
| 39 | def _ignore(self): |
---|
| 40 | return super(Owner, self)._ignore() + ['getMemoryQuotas', 'getDiskQuotas', 'getVMQuotas'] |
---|