@contextlib.contextmanager
def _dummy_vm(session, instance, vdi_ref):
 name_label = 'dummy'
 vm_ref = create_vm(session, instance, name_label, None, None)
 try:
  vbd_ref = create_vbd(session, vm_ref, vdi_ref, 'autodetect', read_only=True)
  try:
   (yield vm_ref)
  finally:
   try:
    destroy_vbd(session, vbd_ref)
   except exception.StorageError:
    pass
 finally:
  destroy_vm(session, instance, vm_ref)

@ contextlib . contextmanager def _dummy_vm ( session , instance , vdi_ref ) : name_label = 'dummy' vm_ref = create_vm ( session , instance , name_label , None , None ) try : vbd_ref = create_vbd ( session , vm_ref , vdi_ref , 'autodetect' , read_only = True ) try : ( yield vm_ref ) finally : try : destroy_vbd ( session , vbd_ref ) except exception . StorageError : pass finally : destroy_vm ( session , instance , vm_ref )
this creates a temporary vm so that we can snapshot a vdi .