#NEWLINE# @ extensions . expected_errors ( ( 400 , 404 , 409 , 501 ) ) #NEWLINE# @ wsgi . action ( 'rescue' ) #NEWLINE# @ validation . schema ( rescue . rescue ) #NEWLINE# def _rescue( self , req , id , body ) : #NEWLINE# #INDENT# 'Rescue an instance.' #NEWLINE# context = req . environ [ 'nova.context' ] #NEWLINE# authorize ( context ) #NEWLINE# if ( body [ 'rescue' ] and ( 'adminPass' in body [ 'rescue' ] ) ) : #NEWLINE# #INDENT# password = body [ 'rescue' ] [ 'adminPass' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# password = utils . generate_password ( ) #NEWLINE# #UNINDENT# instance = common . get_instance ( self . compute_api , context , id ) #NEWLINE# rescue_image_ref = None #NEWLINE# if ( body [ 'rescue' ] and ( 'rescue_image_ref' in body [ 'rescue' ] ) ) : #NEWLINE# #INDENT# rescue_image_ref = body [ 'rescue' ] [ 'rescue_image_ref' ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . compute_api . rescue ( context , instance , rescue_password = password , rescue_image_ref = rescue_image_ref ) #NEWLINE# #UNINDENT# except exception . InstanceUnknownCell as e : #NEWLINE# #INDENT# raise exc . HTTPNotFound ( explanation = e . format_message ( ) ) #NEWLINE# #UNINDENT# except exception . InstanceIsLocked as e : #NEWLINE# #INDENT# raise exc . HTTPConflict ( explanation = e . format_message ( ) ) #NEWLINE# #UNINDENT# except exception . InstanceInvalidState as state_error : #NEWLINE# #INDENT# common . raise_http_conflict_for_instance_invalid_state ( state_error , 'rescue' , id ) #NEWLINE# #UNINDENT# except exception . InvalidVolume as volume_error : #NEWLINE# #INDENT# raise exc . HTTPConflict ( explanation = volume_error . format_message ( ) ) #NEWLINE# #UNINDENT# except exception . InstanceNotRescuable as non_rescuable : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( explanation = non_rescuable . format_message ( ) ) #NEWLINE# #UNINDENT# if CONF . enable_instance_password : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'adminPass' : password , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# }