From 1f4e8a3ccfc4db56823ae756b707b94e19236233 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Sat, 20 Apr 2013 16:49:23 +0800 Subject: [PATCH] Apply Oslo ModelBase to NeutronBase 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 | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/neutron/db/model_base.py b/neutron/db/model_base.py index 3caa4ff61..7f8f051f9 100644 --- a/neutron/db/model_base.py +++ b/neutron/db/model_base.py @@ -16,21 +16,14 @@ 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))