Made some changes requested by Broder.
[invirt/packages/invirt-database.git] / python / database / owner.py
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
7
8 class Owner(object):
9     def __repr__(self):
10         return """<Owner %s: ram_quota_total=%s MB ram_quota_single=%s MB
11 disk_quota_total=%s MB disk_quota_single=%s MB
12 vms_quota_total=%s vms_quota_active=%s >""" % (self.owner_id, 
13                self.ram_quota_total if self.ram_quota_total else MAX_MEMORY_TOTAL,
14                self.ram_quota_single if self.ram_quota_single else MAX_MEMORY_SINGLE, 
15                self.disk_quota_total if self.disk_quota_total else MAX_DISK_TOTAL,
16                self.disk_quota_single if self.disk_quota_single else MAX_DISK_SINGLE, 
17                self.vms_quota_total if self.vms_quota_total else MAX_VMS_TOTAL,
18                self.vms_quota_active if self.vms_quota_active else MAX_VMS_ACTIVE)
19     def getMemoryQuotas(owner):
20         owner_info = Owner.query().filter_by(owner_id=owner).first()
21         if owner_info != None:
22             quota_total = owner_info.ram_quota_total
23             if quota_total == None:
24                 quota_total = MAX_MEMORY_TOTAL
25             quota_single = owner_info.ram_quota_single
26             if quota_single == None:
27                 quota_single = MAX_MEMORY_SINGLE
28         else:
29             quota_total = MAX_MEMORY_TOTAL
30             quota_single = MAX_MEMORY_SINGLE
31         return (quota_total, quota_single)
32     getMemoryQuotas = staticmethod(getMemoryQuotas)
33     def getDiskQuotas(owner):
34         owner_info = Owner.query().filter_by(owner_id=owner).first()
35         if owner_info != None:
36             quota_total = owner_info.disk_quota_total
37             if quota_total == None:
38                 quota_total = MAX_DISK_TOTAL
39             quota_single = owner_info.disk_quota_single
40             if quota_single == None:
41                 quota_single = MAX_DISK_SINGLE
42         else:
43             quota_total = MAX_DISK_TOTAL
44             quota_single = MAX_DISK_SINGLE
45         return (quota_total, quota_single)
46     getDiskQuotas = staticmethod(getDiskQuotas)
47     def getVMQuotas(owner):
48         owner_info = Owner.query().filter_by(owner_id=owner).first()
49         if owner_info != None:
50             quota_total = owner_info.vms_quota_total
51             if quota_total == None:
52                 quota_total = MAX_VMS_TOTAL
53             quota_active = owner_info.vms_quota_active
54             if quota_active == None:
55                 quota_active = MAX_VMS_ACTIVE
56         else:
57             quota_total = MAX_VMS_TOTAL
58             quota_single = MAX_VMS_ACTIVE
59         return (quota_total, quota_active)
60     getVMQuotas = staticmethod(getVMQuotas)