#NEWLINE# def bdm_update_or_create_at_top( self , message , bdm , create ) : #NEWLINE# #INDENT# "Create or update a block device mapping in API cells.  If\n        create is True, only try to create.  If create is None, try to\n        update but fall back to create.  If create is False, only attempt\n        to update.  This maps to nova-conductor's behavior.\n        " #NEWLINE# if ( not self . _at_the_top ( ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# items_to_remove = [ 'id' ] #NEWLINE# for key in items_to_remove : #NEWLINE# #INDENT# bdm . pop ( key , None ) #NEWLINE# #UNINDENT# if ( create is None ) : #NEWLINE# #INDENT# LOG . debug ( 'Calling db.block_device_mapping_update_or_create from API cell with values: %s' , bdm ) #NEWLINE# self . db . block_device_mapping_update_or_create ( message . ctxt , bdm , legacy = False ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( create is True ) : #NEWLINE# #INDENT# LOG . debug ( 'Calling db.block_device_mapping_create from API cell with values: %s' , bdm ) #NEWLINE# self . db . block_device_mapping_create ( message . ctxt , bdm , legacy = False ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# dev_name = bdm [ 'device_name' ] #NEWLINE# vol_id = bdm [ 'volume_id' ] #NEWLINE# instance_bdms = self . db . block_device_mapping_get_all_by_instance ( message . ctxt , bdm [ 'instance_uuid' ] ) #NEWLINE# for instance_bdm in instance_bdms : #NEWLINE# #INDENT# if ( dev_name and ( instance_bdm [ 'device_name' ] == dev_name ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( vol_id and ( instance_bdm [ 'volume_id' ] == vol_id ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# LOG . warning ( _LW ( 'No match when trying to update BDM: %(bdm)s' ) , dict ( bdm = bdm ) ) #NEWLINE# return #NEWLINE# #UNINDENT# LOG . debug ( 'Calling db.block_device_mapping_update from API cell with bdm id %s and values: %s' , instance_bdm [ 'id' ] , bdm ) #NEWLINE# self . db . block_device_mapping_update ( message . ctxt , instance_bdm [ 'id' ] , bdm , legacy = False )