diff options
author | Soren Hansen <soren.hansen@rackspace.com> | 2010-09-15 14:04:07 +0200 |
---|---|---|
committer | Soren Hansen <soren.hansen@rackspace.com> | 2010-09-15 14:04:07 +0200 |
commit | 9196b74080d5effd8dcfacce9de7d2dd37fcba1b (patch) | |
tree | 442a9d7490346bd1e1febed82faee3055c9f442c | |
parent | 0cb25fddcad2626ce617f5c2472cea1c02f1d961 (diff) | |
download | nova-9196b74080d5effd8dcfacce9de7d2dd37fcba1b.tar.gz nova-9196b74080d5effd8dcfacce9de7d2dd37fcba1b.tar.xz nova-9196b74080d5effd8dcfacce9de7d2dd37fcba1b.zip |
Clean up use of ORM to remove the need for scoped_session.
-rw-r--r-- | nova/db/api.py | 6 | ||||
-rw-r--r-- | nova/db/sqlalchemy/api.py | 9 | ||||
-rw-r--r-- | nova/db/sqlalchemy/session.py | 4 | ||||
-rw-r--r-- | nova/endpoint/cloud.py | 4 |
4 files changed, 12 insertions, 11 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index 1d10b1987..fa937dab2 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -463,12 +463,12 @@ def security_group_get(context, security_group_id): def security_group_get_by_name(context, project_id, group_name): """Returns a security group with the specified name from a project""" - return IMPL.securitygroup_get_by_name(context, project_id, group_name) + return IMPL.security_group_get_by_name(context, project_id, group_name) def security_group_get_by_project(context, project_id): """Get all security groups belonging to a project""" - return IMPL.securitygroup_get_by_project(context, project_id) + return IMPL.security_group_get_by_project(context, project_id) def security_group_get_by_instance(context, instance_id): @@ -478,7 +478,7 @@ def security_group_get_by_instance(context, instance_id): def securitygroup_exists(context, project_id, group_name): """Indicates if a group name exists in a project""" - return IMPL.securitygroup_exists(context, project_id, group_name) + return IMPL.security_group_exists(context, project_id, group_name) def security_group_create(context, values): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 11779e30c..038bb7f23 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -646,10 +646,11 @@ def security_group_get(_context, security_group_id): ).get(security_group_id) -def securitygroup_get_by_name(context, project_id, group_name): +def security_group_get_by_name(context, project_id, group_name): session = get_session() group_ref = session.query(models.SecurityGroup ).options(eagerload('rules') + ).options(eagerload('instances') ).filter_by(project_id=project_id ).filter_by(name=group_name ).filter_by(deleted=False @@ -662,7 +663,7 @@ def securitygroup_get_by_name(context, project_id, group_name): return group_ref -def securitygroup_get_by_project(_context, project_id): +def security_group_get_by_project(_context, project_id): session = get_session() return session.query(models.SecurityGroup ).options(eagerload('rules') @@ -681,9 +682,9 @@ def security_group_get_by_instance(_context, instance_id): ).all() -def securitygroup_exists(_context, project_id, group_name): +def security_group_exists(_context, project_id, group_name): try: - group = securitygroup_get_by_name(_context, project_id, group_name) + group = security_group_get_by_name(_context, project_id, group_name) return group != None except exception.NotFound: return False diff --git a/nova/db/sqlalchemy/session.py b/nova/db/sqlalchemy/session.py index fffbd3443..826754f6a 100644 --- a/nova/db/sqlalchemy/session.py +++ b/nova/db/sqlalchemy/session.py @@ -20,7 +20,7 @@ Session Handling for SQLAlchemy backend """ from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker, scoped_session +from sqlalchemy.orm import sessionmaker from nova import flags @@ -36,7 +36,7 @@ def get_session(autocommit=True, expire_on_commit=False): if not _MAKER: if not _ENGINE: _ENGINE = create_engine(FLAGS.sql_connection, echo=False) - _MAKER = scoped_session(sessionmaker(bind=_ENGINE, + _MAKER = (sessionmaker(bind=_ENGINE, autocommit=autocommit, expire_on_commit=expire_on_commit)) session = _MAKER() diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py index ab3f5b2d9..d2606e3a7 100644 --- a/nova/endpoint/cloud.py +++ b/nova/endpoint/cloud.py @@ -326,7 +326,7 @@ class CloudController(object): security_group = db.security_group_get_by_name(context, context.project.id, group_name) - values = { 'parent_group' : security_group } + values = { 'parent_group_id' : security_group.id } if source_security_group_name: source_project_id = self._get_source_project_id(context, @@ -353,7 +353,7 @@ class CloudController(object): security_group_rule = db.security_group_rule_create(context, values) - self._refresh_security_group(security_group) + self._trigger_refresh_security_group(security_group) return True |