X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-database.git/blobdiff_plain/fe334bb175017b9c5988159652718e29dafe83cd..e2d288987a8ed40aea40f8c8ac01efeb3749719f:/python/database/owner.py diff --git a/python/database/owner.py b/python/database/owner.py index 59080bc..adb176c 100755 --- a/python/database/owner.py +++ b/python/database/owner.py @@ -1,19 +1,40 @@ -MAX_MEMORY_TOTAL = 512 -MAX_MEMORY_SINGLE = 512 -class Owner(object): - def __repr__(self): - return "" % (self.owner_id, self.ram_quota_total, self.ram_quota_single) - def getQuotas(owner): +from record import NullableRecord + +class Owner(NullableRecord): + _f = { + 'ram_quota_total': (512, 'MiB'), + 'ram_quota_single': (512, 'MiB'), + 'disk_quota_total': (50, 'GiB'), + 'disk_quota_single': (50, 'GiB'), + 'vms_quota_total': (10, ''), + 'vms_quota_active': (4, '') + } + _default = dict([(_k,_v[0]) for _k,_v in _f.items()]) + def _unitFormatter(unit): + return lambda v:'%s%s'%(v,unit) + _format = dict([(_k,_unitFormatter(_v[1])) for _k,_v in _f.items()]) + _identity_field = 'owner_id' + + def getMemoryQuotas(owner): owner_info = Owner.query().filter_by(owner_id=owner).first() - if owner_info != None: - quota_total = owner_info.ram_quota_total - if quota_total == None: - quota_total = MAX_MEMORY_TOTAL - quota_single = owner_info.ram_quota_single - if quota_single == None: - quota_single = MAX_MEMORY_SINGLE - else: - quota_total = MAX_MEMORY_TOTAL - quota_single = MAX_MEMORY_SINGLE - return (quota_total, quota_single) - getQuotas = staticmethod(getQuotas) + if owner_info == None: + owner_info = Owner(owner_id=owner) + return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single')) + getMemoryQuotas = staticmethod(getMemoryQuotas) + + def getDiskQuotas(owner): + owner_info = Owner.query().filter_by(owner_id=owner).first() + if owner_info == None: + owner_info = Owner(owner_id=owner) + return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single')) + getDiskQuotas = staticmethod(getDiskQuotas) + + def getVMQuotas(owner): + owner_info = Owner.query().filter_by(owner_id=owner).first() + if owner_info == None: + owner_info = Owner(owner_id=owner) + return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active')) + getVMQuotas = staticmethod(getVMQuotas) + + def _ignore(self): + return super(Owner, self)._ignore() + ['getMemoryQuotas', 'getDiskQuotas', 'getVMQuotas']