def _safe_copy_vdi(session, sr_ref, instance, vdi_to_copy_ref):
 with _dummy_vm(session, instance, vdi_to_copy_ref) as vm_ref:
  label = 'snapshot'
  with snapshot_attached_here(session, instance, vm_ref, label) as vdi_uuids:
   imported_vhds = session.call_plugin_serialized('workarounds', 'safe_copy_vdis', sr_path=get_sr_path(session), vdi_uuids=vdi_uuids, uuid_stack=_make_uuid_stack())
 root_uuid = imported_vhds['root']['uuid']
 scan_default_sr(session)
 vdi_ref = session.call_xenapi('VDI.get_by_uuid', root_uuid)
 return vdi_ref

def _safe_copy_vdi ( session , sr_ref , instance , vdi_to_copy_ref ) : with _dummy_vm ( session , instance , vdi_to_copy_ref ) as vm_ref : label = 'snapshot' with snapshot_attached_here ( session , instance , vm_ref , label ) as vdi_uuids : imported_vhds = session . call_plugin_serialized ( 'workarounds' , 'safe_copy_vdis' , sr_path = get_sr_path ( session ) , vdi_uuids = vdi_uuids , uuid_stack = _make_uuid_stack ( ) ) root_uuid = imported_vhds [ 'root' ] [ 'uuid' ] scan_default_sr ( session ) vdi_ref = session . call_xenapi ( 'VDI.get_by_uuid' , root_uuid ) return vdi_ref
copy a vdi and return the new vdis reference .