summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-09-10 07:34:10 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-09-10 07:34:10 -0700
commitf8a25024ff4a3225b3c7ba7de0927916b39126fc (patch)
tree627199f8cecfc165e3c031fbcc760c9bd5a01b1f
parent953b79702500d129d40b557db668f095c303910d (diff)
add a simple iterator to NovaBase to support converting into dictionary
-rw-r--r--nova/db/sqlalchemy/models.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 679a44d21..6818f838c 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -24,8 +24,7 @@ import sys
import datetime
# TODO(vish): clean up these imports
-from sqlalchemy.orm import relationship, backref, validates, exc
-from sqlalchemy.sql import func
+from sqlalchemy.orm import relationship, backref, exc, object_mapper
from sqlalchemy import Column, Integer, String
from sqlalchemy import ForeignKey, DateTime, Boolean, Text
from sqlalchemy.ext.declarative import declarative_base
@@ -113,6 +112,14 @@ class NovaBase(object):
def __getitem__(self, key):
return getattr(self, key)
+ def __iter__(self):
+ self._i = iter(object_mapper(self).columns)
+ return self
+
+ def next(self):
+ n = self._i.next().name
+ return n, getattr(self, n)
+
# TODO(vish): Store images in the database instead of file system
#class Image(BASE, NovaBase):
# """Represents an image in the datastore"""