#NEWLINE# def _format_attachment( context , volume , os_volume , instances = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , os_instances = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , instance_id = None ) : #NEWLINE# #INDENT# os_attachment = next ( iter ( os_volume . attachments ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# os_instance_id = os_attachment . get ( 'server_id' ) #NEWLINE# if ( ( not instance_id ) and os_instance_id ) : #NEWLINE# #INDENT# instance = ec2utils . get_db_item_by_os_id ( context , 'i' , os_instance_id , instances ) #NEWLINE# instance_id = instance [ 'id' ] #NEWLINE# #UNINDENT# ec2_attachment = { #NEWLINE# #INDENT# 'device' : os_attachment . get ( 'device' ) , #NEWLINE# 'instanceId' : instance_id , #NEWLINE# 'status' : ( os_volume . status if ( os_volume . status in ( 'attaching' , 'detaching' ) ) else ( 'attached' if os_attachment else 'detached' ) ) , #NEWLINE# 'volumeId' : volume [ 'id' ] , #NEWLINE# #UNINDENT# } #NEWLINE# if ( os_instance_id in os_instances ) : #NEWLINE# #INDENT# os_instance = os_instances [ os_instance_id ] #NEWLINE# volumes_attached = getattr ( os_instance , 'os-extended-volumes:volumes_attached' , [ ] ) #NEWLINE# volume_attached = next ( ( va for va in volumes_attached if ( va [ 'id' ] == os_volume [ 'os_id' ] ) ) , None ) #NEWLINE# if ( volume_attached and ( 'delete_on_termination' in volume_attached ) ) : #NEWLINE# #INDENT# ec2_attachment [ 'deleteOnTermination' ] = volume_attached [ 'delete_on_termination' ] #NEWLINE# #UNINDENT# #UNINDENT# return ec2_attachment