@utils.expects_func_args('image_id', 'instance')
def delete_image_on_error(function):
 @functools.wraps(function)
 def decorated_function(self, context, image_id, instance, *args, **kwargs):
  try:
   return function(self, context, image_id, instance, *args, **kwargs)
  except Exception:
   with excutils.save_and_reraise_exception():
    LOG.debug('Cleaning up image %s', image_id, exc_info=True, instance=instance)
    try:
     self.image_api.delete(context, image_id)
    except exception.ImageNotFound:
     pass
    except Exception:
     LOG.exception(_LE('Error while trying to clean up image %s'), image_id, instance=instance)
 return decorated_function

@ utils . expects_func_args ( 'image_id' , 'instance' ) def delete_image_on_error ( function ) : @ functools . wraps ( function ) def decorated_function ( self , context , image_id , instance , * args , ** kwargs ) : try : return function ( self , context , image_id , instance , * args , ** kwargs ) except Exception : with excutils . save_and_reraise_exception ( ) : LOG . debug ( 'Cleaning up image %s' , image_id , exc_info = True , instance = instance ) try : self . image_api . delete ( context , image_id ) except exception . ImageNotFound : pass except Exception : LOG . exception ( _LE ( 'Error while trying to clean up image %s' ) , image_id , instance = instance ) return decorated_function
used for snapshot related method to ensure the image created in compute .