From ffb955602999aee1885640e97db2f5dda8c5034c Mon Sep 17 00:00:00 2001 From: TommyLike Date: Wed, 19 Sep 2018 11:37:03 +0800 Subject: [PATCH] [Optimize] Use OVO when retrieve volume object Use OVO instead of db object when collecting volume resource. Change-Id: I7645090cdb8c96468a8801a3ec5cb214eaca2e05 --- cinder/transfer/api.py | 8 +++++--- cinder/volume/manager.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index 91e95b881fa..380a98a7ee3 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -68,7 +68,8 @@ class API(base.Base): """Make the RPC call to delete a volume transfer.""" transfer = self.db.transfer_get(context, transfer_id) - volume_ref = self.db.volume_get(context, transfer.volume_id) + volume_ref = objects.Volume.get_by_id(context, + transfer.volume_id) context.authorize(policy.DELETE_POLICY, target_obj=volume_ref) volume_utils.notify_about_volume_usage(context, volume_ref, "transfer.delete.start") @@ -116,7 +117,7 @@ class API(base.Base): def create(self, context, volume_id, display_name, no_snapshots=False): """Creates an entry in the transfers table.""" LOG.info("Generating transfer record for volume %s", volume_id) - volume_ref = self.db.volume_get(context, volume_id) + volume_ref = objects.Volume.get_by_id(context, volume_id) context.authorize(policy.CREATE_POLICY, target_obj=volume_ref) if volume_ref['status'] != "available": raise exception.InvalidVolume(reason=_("status must be available")) @@ -300,7 +301,8 @@ class API(base.Base): QUOTAS.rollback(context, snap_donor_res, project_id=donor_id) - vol_ref = self.db.volume_get(context, volume_id) + vol_ref = objects.Volume.get_by_id(context.elevated(), + volume_id) volume_utils.notify_about_volume_usage(context, vol_ref, "transfer.accept.end") return {'id': transfer_id, diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 1d1301dbe15..ce651287914 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -2570,7 +2570,7 @@ class VolumeManager(manager.CleanableManager, extra_usage_info=extra_usage_info, host=self.host) if not volumes: - volumes = self.db.volume_get_all_by_generic_group( + volumes = objects.VolumeList.get_all_by_generic_group( context, group.id) if volumes: for volume in volumes: