+invirt-database (0.1.8) unstable; urgency=low
+
+ [Peter Iannucci]
+ * Added Record superclass for models, handling __repr__ consistently.
+
+ [Greg Price]
+ * use self.c rather than self.__dict__ for SQLAlchemy fields
+ * make Record._ignore, Owner.get* classmethods
+
+ -- Greg Price <price@mit.edu> Thu, 26 Feb 2009 22:38:02 -0500
+
invirt-database (0.1.7) unstable; urgency=low
* Disk quotas are measured in gibibytes.
_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()
+ @classmethod
+ def getMemoryQuotas(cls, owner):
+ owner_info = cls.query().filter_by(owner_id=owner).first()
if owner_info == None:
- owner_info = Owner(owner_id=owner)
+ owner_info = cls(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()
+ @classmethod
+ def getDiskQuotas(cls, owner):
+ owner_info = cls.query().filter_by(owner_id=owner).first()
if owner_info == None:
- owner_info = Owner(owner_id=owner)
+ owner_info = cls(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()
+ @classmethod
+ def getVMQuotas(cls, owner):
+ owner_info = cls.query().filter_by(owner_id=owner).first()
if owner_info == None:
- owner_info = Owner(owner_id=owner)
+ owner_info = cls(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']
class Record(object):
_identity_field = None
+
def get(self, field):
try:
return self.__getattribute__(field)
except:
return None
+
def _formatField(self, field):
v = self.get(field)
if callable(v):
return '[%d x %s]'%(len(v), type(v[0]))
else:
return repr(v)
+
+ @classmethod
+ def _ignore(cls):
+ return [cls._identity_field]
+
def _fields(self):
ignore = self._ignore()
- keys = sorted(self.__class__.__dict__.keys())
- return [(k,self._formatField(k)) for k in keys if k[0]!="_" and k not in ignore]
+ keys = sorted(self.c.keys())
+ return [(k,self._formatField(k)) for k in keys if k not in ignore]
+
def __repr__(self):
classname = self.__class__.__name__
payload = ": "+payload
return "<%s%s%s>" % (classname, identity, payload)
- def _ignore(self):
- return [self._identity_field, 'c', 'query', 'get']
class FormattableRecord(Record):
_format = {}