Changeset 2187 for trunk/packages/invirt-database/python/database/owner.py
- Timestamp:
- Feb 25, 2009, 4:00:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-database/python/database/owner.py
r2158 r2187 1 MAX_MEMORY_TOTAL = 512 2 MAX_MEMORY_SINGLE = 512 3 MAX_DISK_TOTAL = 50 4 MAX_DISK_SINGLE = 50 5 MAX_VMS_TOTAL = 10 6 MAX_VMS_ACTIVE = 4 1 from record import NullableRecord 7 2 8 class Owner(object): 9 def __repr__(self): 10 a = self.ram_quota_total 11 b = self.ram_quota_single 12 c = self.disk_quota_total 13 d = self.disk_quota_single 14 e = self.vms_quota_total 15 f = self.vms_quota_active 16 if not a: 17 a = MAX_MEMORY_TOTAL 18 if not b: 19 b = MAX_MEMORY_SINGLE 20 if not c: 21 c = MAX_DISK_TOTAL 22 if not d: 23 d = MAX_DISK_SINGLE 24 if not e: 25 e = MAX_VMS_TOTAL 26 if not f: 27 f = MAX_VMS_ACTIVE 28 return """<Owner %s: ram_quota_total=%s MiB ram_quota_single=%s MiB 29 disk_quota_total=%s GiB disk_quota_single=%s GiB 30 vms_quota_total=%s vms_quota_active=%s >""" % (self.owner_id, a,b,c,d,e,f) 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 31 18 def getMemoryQuotas(owner): 32 19 owner_info = Owner.query().filter_by(owner_id=owner).first() 33 if owner_info != None: 34 quota_total = owner_info.ram_quota_total 35 if quota_total == None: 36 quota_total = MAX_MEMORY_TOTAL 37 quota_single = owner_info.ram_quota_single 38 if quota_single == None: 39 quota_single = MAX_MEMORY_SINGLE 40 else: 41 quota_total = MAX_MEMORY_TOTAL 42 quota_single = MAX_MEMORY_SINGLE 43 return (quota_total, quota_single) 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')) 44 23 getMemoryQuotas = staticmethod(getMemoryQuotas) 24 45 25 def getDiskQuotas(owner): 46 26 owner_info = Owner.query().filter_by(owner_id=owner).first() 47 if owner_info != None: 48 quota_total = owner_info.disk_quota_total 49 if quota_total == None: 50 quota_total = MAX_DISK_TOTAL 51 quota_single = owner_info.disk_quota_single 52 if quota_single == None: 53 quota_single = MAX_DISK_SINGLE 54 else: 55 quota_total = MAX_DISK_TOTAL 56 quota_single = MAX_DISK_SINGLE 57 return (quota_total, quota_single) 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')) 58 30 getDiskQuotas = staticmethod(getDiskQuotas) 31 59 32 def getVMQuotas(owner): 60 33 owner_info = Owner.query().filter_by(owner_id=owner).first() 61 if owner_info != None: 62 quota_total = owner_info.vms_quota_total 63 if quota_total == None: 64 quota_total = MAX_VMS_TOTAL 65 quota_active = owner_info.vms_quota_active 66 if quota_active == None: 67 quota_active = MAX_VMS_ACTIVE 68 else: 69 quota_total = MAX_VMS_TOTAL 70 quota_active = MAX_VMS_ACTIVE 71 return (quota_total, quota_active) 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')) 72 37 getVMQuotas = staticmethod(getVMQuotas) 38 39 def _ignore(self): 40 return super(Owner, self)._ignore() + ['getMemoryQuotas', 'getDiskQuotas', 'getVMQuotas']
Note: See TracChangeset
for help on using the changeset viewer.