From 586e752e69ca891714f390bf59ad30d5081d4498 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Fri, 26 Apr 2013 12:52:26 +0400 Subject: Refactor nova.volume.cinder.API to reduce roundtrips with Cinder Make cinder.API methods accept volume_id instead of the whole volume object. This will remove redundant roundtrip to get the volume before passing it to other methods as in fact they only need the id. Fixes bug 1172297 Change-Id: I5e7f944c1c29b2f211ece2ef86c0959c81e806df --- nova/api/ec2/cloud.py | 10 ++++------ nova/api/openstack/compute/contrib/volumes.py | 11 ++++------- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 3d210404c..33ffbbc21 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -391,8 +391,8 @@ class CloudController(object): LOG.audit(_("Create snapshot of volume %s"), volume_id, context=context) volume_id = ec2utils.ec2_vol_id_to_uuid(volume_id) - volume = self.volume_api.get(context, volume_id) - args = (context, volume, kwargs.get('name'), kwargs.get('description')) + args = (context, volume_id, kwargs.get('name'), + kwargs.get('description')) if kwargs.get('force', False): snapshot = self.volume_api.create_snapshot_force(*args) else: @@ -403,8 +403,7 @@ class CloudController(object): def delete_snapshot(self, context, snapshot_id, **kwargs): snapshot_id = ec2utils.ec2_snap_id_to_uuid(snapshot_id) - snapshot = self.volume_api.get_snapshot(context, snapshot_id) - self.volume_api.delete_snapshot(context, snapshot) + self.volume_api.delete_snapshot(context, snapshot_id) return True def describe_key_pairs(self, context, key_name=None, **kwargs): @@ -863,8 +862,7 @@ class CloudController(object): validate_ec2_id(volume_id) volume_id = ec2utils.ec2_vol_id_to_uuid(volume_id) try: - volume = self.volume_api.get(context, volume_id) - self.volume_api.delete(context, volume) + self.volume_api.delete(context, volume_id) except exception.InvalidVolume: raise exception.EC2APIError(_('Delete Failed')) diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index 640ac0c76..6b598c6eb 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -187,8 +187,7 @@ class VolumeController(wsgi.Controller): LOG.audit(_("Delete volume with id: %s"), id, context=context) try: - vol = self.volume_api.get(context, id) - self.volume_api.delete(context, vol) + self.volume_api.delete(context, id) except exception.NotFound: raise exc.HTTPNotFound() return webob.Response(status_int=202) @@ -573,8 +572,7 @@ class SnapshotController(wsgi.Controller): LOG.audit(_("Delete snapshot with id: %s"), id, context=context) try: - snapshot = self.volume_api.get_snapshot(context, id) - self.volume_api.delete_snapshot(context, snapshot) + self.volume_api.delete_snapshot(context, id) except exception.NotFound: return exc.HTTPNotFound() return webob.Response(status_int=202) @@ -610,7 +608,6 @@ class SnapshotController(wsgi.Controller): snapshot = body['snapshot'] volume_id = snapshot['volume_id'] - vol = self.volume_api.get(context, volume_id) force = snapshot.get('force', False) LOG.audit(_("Create snapshot from volume %s"), volume_id, @@ -622,12 +619,12 @@ class SnapshotController(wsgi.Controller): if utils.bool_from_str(force): new_snapshot = self.volume_api.create_snapshot_force(context, - vol, + volume_id, snapshot.get('display_name'), snapshot.get('display_description')) else: new_snapshot = self.volume_api.create_snapshot(context, - vol, + volume_id, snapshot.get('display_name'), snapshot.get('display_description')) -- cgit