[Optimize] Use OVO when retrieve volume object

Use OVO instead of db object when collecting
volume resource.

Change-Id: I7645090cdb8c96468a8801a3ec5cb214eaca2e05
This commit is contained in:
TommyLike 2018-09-19 11:37:03 +08:00
parent ab911c1b47
commit ffb9556029
2 changed files with 6 additions and 4 deletions

View File

@ -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,

View File

@ -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: