#NEWLINE# @ wsgi . response ( 202 ) #NEWLINE# @ wsgi . action ( 'createImage' ) #NEWLINE# @ common . check_snapshots_enabled #NEWLINE# def _action_create_image( self , req , id , body ) : #NEWLINE# #INDENT# 'Snapshot a server instance.' #NEWLINE# context = req . environ [ 'nova.context' ] #NEWLINE# entity = body . get ( 'createImage' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# image_name = entity . get ( 'name' ) #NEWLINE# if ( not context ) : #NEWLINE# #INDENT# msg = _ ( 'createImage entity requires name attribute' ) #NEWLINE# raise exc . HTTPBadRequest ( explanation = msg ) #NEWLINE# #UNINDENT# props = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# metadata = entity . get ( 'metadata' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# common . check_img_metadata_properties_quota ( context , metadata ) #NEWLINE# try : #NEWLINE# #INDENT# props . update ( metadata ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# msg = _ ( 'Invalid metadata' ) #NEWLINE# raise exc . HTTPBadRequest ( explanation = msg ) #NEWLINE# #UNINDENT# instance = self . _get_server ( context , req , id ) #NEWLINE# bdms = objects . BlockDeviceMappingList . get_by_instance_uuid ( context , instance . uuid ) #NEWLINE# try : #NEWLINE# #INDENT# if self . compute_api . is_volume_backed_instance ( context , instance , bdms ) : #NEWLINE# #INDENT# policy . enforce ( context , 'compute:snapshot_volume_backed' , { #NEWLINE# #INDENT# 'project_id' : context . project_id , #NEWLINE# 'user_id' : context . user_id , #NEWLINE# #UNINDENT# } ) #NEWLINE# image = self . compute_api . snapshot_volume_backed ( context , instance , image_name , extra_properties = props ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# image = self . compute_api . snapshot ( context , instance , image_name , extra_properties = props ) #NEWLINE# #UNINDENT# #UNINDENT# except exception . InstanceInvalidState as state_error : #NEWLINE# #INDENT# common . raise_http_conflict_for_instance_invalid_state ( state_error , 'createImage' , id ) #NEWLINE# #UNINDENT# except exception . Invalid as err : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( explanation = err . format_message ( ) ) #NEWLINE# #UNINDENT# image_id = str ( image [ 'id' ] ) #NEWLINE# url_prefix = self . _view_builder . _update_glance_link_prefix ( req . application_url ) #NEWLINE# image_ref = common . url_join ( url_prefix , context . project_id , 'images' , image_id ) #NEWLINE# resp = webob . Response ( status_int = 202 ) #NEWLINE# resp . headers [ 'Location' ] = image_ref #NEWLINE# return resp