From ac48bf5c1b4701640e69747c43ca10cf3442e6ff Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Tue, 24 Aug 2010 22:41:34 -0400 Subject: work towards volumes using db layer --- nova/db/api.py | 11 ++++++++++- nova/db/sqlalchemy/api.py | 12 ++++++++++++ nova/endpoint/cloud.py | 12 +++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/nova/db/api.py b/nova/db/api.py index e4d79d16f..edc3b7bdc 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -195,7 +195,6 @@ def instance_get_by_name(context, name): return _impl.instance_get_by_project(context, name) - def instance_get_by_project(context, project_id): """Get all instance belonging to a project.""" return _impl.instance_get_by_project(context, project_id) @@ -356,6 +355,16 @@ def volume_get(context, volume_id): return _impl.volume_get(context, volume_id) +def volume_get_all(context): + """Get all volumes.""" + return _impl.volume_get_all(context) + + +def volume_get_by_project(context, project_id): + """Get all volumes belonging to a project.""" + return _impl.volume_get_by_project(context, project_id) + + def volume_get_shelf_and_blade(context, volume_id): """Get the shelf and blade allocated to the volume.""" return _impl.volume_get_shelf_and_blade(context, volume_id) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 2c5434b8f..2ce54a1d7 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -441,6 +441,18 @@ def volume_get(context, volume_id): return models.Volume.find(volume_id) +def volume_get_all(context): + return models.Volume.all() + + +def volume_get_by_project(context, project_id): + session = models.NovaBase.get_session() + query = session.query(models.Volume) + results = query.filter_by(project_id=project_id).all() + session.commit() + return results + + def volume_get_shelf_and_blade(context, volume_id): volume_ref = volume_get(context, volume_id) export_device = volume_ref.export_device diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py index 97d978ccd..e261abc7b 100644 --- a/nova/endpoint/cloud.py +++ b/nova/endpoint/cloud.py @@ -256,11 +256,13 @@ class CloudController(object): @rbac.allow('projectmanager', 'sysadmin') def describe_volumes(self, context, **kwargs): - volumes = [] - for volume in self.volumes: - if context.user.is_admin() or volume['project_id'] == context.project.id: - v = self.format_volume(context, volume) - volumes.append(v) + if context.user.is_admin(): + volumes = db.volume_get_all(context) + else: + volumes = db.volume_get_by_project(context, context.project.id) + + voluems = [self.format_volume(context, v) for v in volumes] + return defer.succeed({'volumeSet': volumes}) def format_volume(self, context, volume): -- cgit