Fix get*Quotas 0.1.9
authorQuentin Smith <quentin@mit.edu>
Fri, 27 Feb 2009 19:18:03 +0000 (14:18 -0500)
committerQuentin Smith <quentin@mit.edu>
Fri, 27 Feb 2009 19:18:03 +0000 (14:18 -0500)
svn path=/trunk/packages/invirt-database/; revision=2213

debian/changelog
python/database/models.py
python/database/owner.py

index 2ce6710..8d71f91 100644 (file)
@@ -1,3 +1,11 @@
+invirt-database (0.1.9) unstable; urgency=low
+
+  * Make get*Quotas idempotent
+  * Move Owner import so that Owner can access session in
+    invirt.database.models
+
+ -- Quentin Smith <quentin@mit.edu>  Fri, 27 Feb 2009 14:17:53 -0500
+
 invirt-database (0.1.8) unstable; urgency=low
 
   [Peter Iannucci]
index 067f9ca..420c1ae 100644 (file)
@@ -6,7 +6,6 @@ from sqlalchemy.ext.sessioncontext import SessionContext
 from sqlalchemy.ext.assignmapper import assign_mapper
 
 from invirt.database import record
-from invirt.database.owner import Owner
 
 __all__ = ['meta',
            'session',
@@ -126,6 +125,8 @@ class CDROM(record.Record):
 class Autoinstall(record.Record):
     _identity_field = 'autoinstall_id'
 
+from invirt.database.owner import Owner
+
 session.mapper(Machine, machine_table,
               properties={'nics': relation(NIC, backref="machine"),
                           'disks': relation(Disk, backref="machine"),
index 1a27c9b..ac8ecfd 100755 (executable)
@@ -1,4 +1,5 @@
 from invirt.database import record
+from invirt.database.models import session
 
 class Owner(record.Record):
     _f = {
@@ -17,21 +18,24 @@ class Owner(record.Record):
 
     @classmethod
     def getMemoryQuotas(cls, owner):
-        owner_info = cls.query().filter_by(owner_id=owner).first()
+        owner_info = cls.query().get(owner)
         if owner_info == None:
             owner_info = cls(owner_id=owner)
+            session.expunge(owner_info)
         return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single'))
 
     @classmethod
     def getDiskQuotas(cls, owner):
-        owner_info = cls.query().filter_by(owner_id=owner).first()
+        owner_info = cls.query().get(owner)
         if owner_info == None:
             owner_info = cls(owner_id=owner)
+            session.expunge(owner_info)
         return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single'))
 
     @classmethod
     def getVMQuotas(cls, owner):
-        owner_info = cls.query().filter_by(owner_id=owner).first()
+        owner_info = cls.query().get(owner)
         if owner_info == None:
             owner_info = cls(owner_id=owner)
+            session.expunge(owner_info)
         return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active'))