#NEWLINE# @ wsgi . response ( 202 ) #NEWLINE# @ wsgi . action ( 'rebuild' ) #NEWLINE# def _action_rebuild( self , req , id , body ) : #NEWLINE# #INDENT# 'Rebuild an instance with the given attributes.' #NEWLINE# body = body [ 'rebuild' ] #NEWLINE# try : #NEWLINE# #INDENT# image_href = body [ 'imageRef' ] #NEWLINE# #UNINDENT# except ( KeyError , TypeError ) : #NEWLINE# #INDENT# msg = _ ( 'Could not parse imageRef from request.' ) #NEWLINE# raise exc . HTTPBadRequest ( explanation = msg ) #NEWLINE# #UNINDENT# image_href = self . _image_uuid_from_href ( image_href ) #NEWLINE# password = self . _get_server_admin_password ( body ) #NEWLINE# context = req . environ [ 'nova.context' ] #NEWLINE# instance = self . _get_server ( context , req , id ) #NEWLINE# attr_map = { #NEWLINE# #INDENT# 'personality' : 'files_to_inject' , #NEWLINE# 'name' : 'display_name' , #NEWLINE# 'accessIPv4' : 'access_ip_v4' , #NEWLINE# 'accessIPv6' : 'access_ip_v6' , #NEWLINE# 'metadata' : 'metadata' , #NEWLINE# 'auto_disk_config' : 'auto_disk_config' , #NEWLINE# #UNINDENT# } #NEWLINE# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( self . ext_mgr . is_loaded ( 'os-preserve-ephemeral-rebuild' ) and ( 'preserve_ephemeral' in body ) ) : #NEWLINE# #INDENT# kwargs [ 'preserve_ephemeral' ] = strutils . bool_from_string ( body [ 'preserve_ephemeral' ] , strict = True ) #NEWLINE# #UNINDENT# if ( 'accessIPv4' in body ) : #NEWLINE# #INDENT# self . _validate_access_ipv4 ( body [ 'accessIPv4' ] ) #NEWLINE# #UNINDENT# if ( 'accessIPv6' in body ) : #NEWLINE# #INDENT# self . _validate_access_ipv6 ( body [ 'accessIPv6' ] ) #NEWLINE# #UNINDENT# if ( 'name' in body ) : #NEWLINE# #INDENT# self . _validate_server_name ( body [ 'name' ] ) #NEWLINE# #UNINDENT# for ( request_attribute , instance_attribute ) in attr_map . items ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# kwargs [ instance_attribute ] = body [ request_attribute ] #NEWLINE# #UNINDENT# except ( KeyError , TypeError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# self . _validate_metadata ( kwargs . get ( 'metadata' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# if ( 'files_to_inject' in kwargs ) : #NEWLINE# #INDENT# personality = kwargs . pop ( 'files_to_inject' ) #NEWLINE# files_to_inject = self . _get_injected_files ( personality ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# files_to_inject = None #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . compute_api . rebuild ( context , instance , image_href , password , files_to_inject = files_to_inject , ** kwargs ) #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 , 'rebuild' , id ) #NEWLINE# #UNINDENT# except exception . InstanceNotFound : #NEWLINE# #INDENT# msg = _ ( 'Instance could not be found' ) #NEWLINE# raise exc . HTTPNotFound ( explanation = msg ) #NEWLINE# #UNINDENT# except exception . InvalidMetadataSize as error : #NEWLINE# #INDENT# raise exc . HTTPRequestEntityTooLarge ( explanation = error . format_message ( ) ) #NEWLINE# #UNINDENT# except exception . ImageNotFound : #NEWLINE# #INDENT# msg = _ ( 'Cannot find image for rebuild' ) #NEWLINE# raise exc . HTTPBadRequest ( explanation = msg ) #NEWLINE# #UNINDENT# except exception . QuotaError as error : #NEWLINE# #INDENT# raise exc . HTTPForbidden ( explanation = error . format_message ( ) ) #NEWLINE# #UNINDENT# except ( exception . ImageNotActive , exception . FlavorDiskTooSmall , exception . FlavorMemoryTooSmall , exception . InvalidMetadata , exception . AutoDiskConfigDisabledByImage ) as error : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( explanation = error . format_message ( ) ) #NEWLINE# #UNINDENT# instance = self . _get_server ( context , req , id , is_detail = True ) #NEWLINE# view = self . _view_builder . show ( req , instance ) #NEWLINE# if CONF . enable_instance_password : #NEWLINE# #INDENT# view [ 'server' ] [ 'adminPass' ] = password #NEWLINE# #UNINDENT# robj = wsgi . ResponseObject ( view ) #NEWLINE# return self . _add_location ( robj )