#NEWLINE# def _get_ec2_instance_and_reservation( context , os_instance_id ) : #NEWLINE# #INDENT# instance_id = ec2utils . os_id_to_ec2_id ( context , 'i' , os_instance_id ) #NEWLINE# try : #NEWLINE# #INDENT# ec2_reservations = instance_api . describe_instances ( context , [ instance_id ] ) #NEWLINE# #UNINDENT# except exception . InvalidInstanceIDNotFound : #NEWLINE# #INDENT# ec2_reservations = instance_api . describe_instances ( context , filter = [ { #NEWLINE# #INDENT# 'name' : 'instance-id' , #NEWLINE# 'value' : [ instance_id ] , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# #UNINDENT# if ( ( len ( ec2_reservations [ 'reservationSet' ] ) != 1 ) or ( len ( ec2_reservations [ 'reservationSet' ] [ 0 ] [ 'instancesSet' ] ) != 1 ) ) : #NEWLINE# #INDENT# LOG . error ( _ ( 'Failed to get metadata for instance id: %s' ) , os_instance_id ) #NEWLINE# raise exception . EC2MetadataNotFound ( ) #NEWLINE# #UNINDENT# ec2_reservation = ec2_reservations [ 'reservationSet' ] [ 0 ] #NEWLINE# ec2_instance = ec2_reservation [ 'instancesSet' ] [ 0 ] #NEWLINE# return ( ec2_instance , ec2_reservation )