]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Apply Oslo ModelBase to NeutronBase
authorZhongyue Luo <zhongyue.nah@intel.com>
Sat, 20 Apr 2013 08:49:23 +0000 (16:49 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Mon, 8 Jul 2013 02:14:26 +0000 (10:14 +0800)
Oslo.db has ModelBase which implements most of NeutronBase's code.
Therefore NeutronBase should inherit from ModelBase to keep things DRY.

Fixes bug #1171055

Change-Id: I1a08636a6aa225da8b5d43a0bbcb9b59c057df42

neutron/db/model_base.py

index 3caa4ff6123e09755003a3624cbc1a8d3cf22954..7f8f051f9737a1ea7cf69bcbe02c06852425c82e 100644 (file)
 from sqlalchemy.ext import declarative
 from sqlalchemy import orm
 
+from neutron.openstack.common.db.sqlalchemy import models
 
-class NeutronBase(object):
+
+class NeutronBase(models.ModelBase):
     """Base class for Neutron Models."""
 
     __table_args__ = {'mysql_engine': 'InnoDB'}
 
-    def __setitem__(self, key, value):
-        setattr(self, key, value)
-
-    def __getitem__(self, key):
-        return getattr(self, key)
-
-    def get(self, key, default=None):
-        return getattr(self, key, default)
-
     def __iter__(self):
         self._i = iter(orm.object_mapper(self).columns)
         return self
@@ -39,22 +32,6 @@ class NeutronBase(object):
         n = self._i.next().name
         return n, getattr(self, n)
 
-    def update(self, values):
-        """Make the model object behave like a dict."""
-        for k, v in values.iteritems():
-            setattr(self, k, v)
-
-    def iteritems(self):
-        """Make the model object behave like a dict.
-
-        Includes attributes from joins.
-        """
-        local = dict(self)
-        joined = dict([(k, v) for k, v in self.__dict__.iteritems()
-                       if not k[0] == '_'])
-        local.update(joined)
-        return local.iteritems()
-
     def __repr__(self):
         """sqlalchemy based automatic __repr__ method."""
         items = ['%s=%r' % (col.name, getattr(self, col.name))