source: trunk/packages/invirt-database/python/database/owner.py @ 2134

Last change on this file since 2134 was 2134, checked in by iannucci, 15 years ago

Added all the other quotas for great win.

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1MAX_MEMORY_TOTAL = 512
2MAX_MEMORY_SINGLE = 512
3MAX_DISK_TOTAL = 50
4MAX_DISK_SINGLE = 50
5MAX_VMS_TOTAL = 10
6MAX_VMS_ACTIVE = 4
7
8class Owner(object):
9    def __repr__(self):
10        return """<Owner %s: ram_quota_total=%s MB ram_quota_single=%s MB
11disk_quota_total=%s MB disk_quota_single=%s MB
12vms_quota_total=%s vms_quota_active=%s >""" % (self.owner_id, self.ram_quota_total, self.ram_quota_single, self.disk_quota_total, self.disk_quota_single, self.vms_quota_total, self.vms_quota_active)
13    def getMemoryQuotas(owner):
14        owner_info = Owner.query().filter_by(owner_id=owner).first()
15        if owner_info != None:
16            quota_total = owner_info.ram_quota_total
17            if quota_total == None:
18                quota_total = MAX_MEMORY_TOTAL
19            quota_single = owner_info.ram_quota_single
20            if quota_single == None:
21                quota_single = MAX_MEMORY_SINGLE
22        else:
23            quota_total = MAX_MEMORY_TOTAL
24            quota_single = MAX_MEMORY_SINGLE
25        return (quota_total, quota_single)
26    getMemoryQuotas = staticmethod(getMemoryQuotas)
27    def getDiskQuotas(owner):
28        owner_info = Owner.query().filter_by(owner_id=owner).first()
29        if owner_info != None:
30            quota_total = owner_info.disk_quota_total
31            if quota_total == None:
32                quota_total = MAX_DISK_TOTAL
33            quota_single = owner_info.disk_quota_single
34            if quota_single == None:
35                quota_single = MAX_DISK_SINGLE
36        else:
37            quota_total = MAX_DISK_TOTAL
38            quota_single = MAX_DISK_SINGLE
39        return (quota_total, quota_single)
40    getDiskQuotas = staticmethod(getDiskQuotas)
41    def getVMQuotas(owner):
42        owner_info = Owner.query().filter_by(owner_id=owner).first()
43        if owner_info != None:
44            quota_total = owner_info.vms_quota_total
45            if quota_total == None:
46                quota_total = MAX_VMS_TOTAL
47            quota_active = owner_info.vms_quota_active
48            if quota_active == None:
49                quota_active = MAX_VMS_ACTIVE
50        else:
51            quota_total = MAX_VMS_TOTAL
52            quota_single = MAX_VMS_ACTIVE
53        return (quota_total, quota_active)
54    getVMQuotas = staticmethod(getVMQuotas)
Note: See TracBrowser for help on using the repository browser.