#NEWLINE# def _build_metadata( context , ec2_instance , ec2_reservation , os_instance_id , remote_ip ) : #NEWLINE# #INDENT# metadata = { #NEWLINE# #INDENT# 'ami-id' : ec2_instance [ 'imageId' ] , #NEWLINE# 'ami-launch-index' : ec2_instance [ 'amiLaunchIndex' ] , #NEWLINE# 'ami-manifest-path' : 'FIXME' , #NEWLINE# 'ancestor-ami-ids' : [ ] , #NEWLINE# 'block-device-mapping' : _build_block_device_mappings ( context , ec2_instance , os_instance_id ) , #NEWLINE# 'hostname' : ec2_instance [ 'privateDnsName' ] , #NEWLINE# 'instance-action' : 'none' , #NEWLINE# 'instance-id' : ec2_instance [ 'instanceId' ] , #NEWLINE# 'instance-type' : ec2_instance [ 'instanceType' ] , #NEWLINE# 'local-hostname' : ec2_instance [ 'privateDnsName' ] , #NEWLINE# 'local-ipv4' : ( ec2_instance [ 'privateIpAddress' ] or remote_ip ) , #NEWLINE# 'placement' : { #NEWLINE# #INDENT# 'availability-zone' : ec2_instance [ 'placement' ] [ 'availabilityZone' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 'product-codes' : [ ] , #NEWLINE# 'public-hostname' : ec2_instance [ 'dnsName' ] , #NEWLINE# 'public-ipv4' : ec2_instance . get ( 'ipAddress' , '' ) , #NEWLINE# 'reservation-id' : ec2_reservation [ 'reservationId' ] , #NEWLINE# 'security-groups' : [ sg [ 'groupName' ] for sg in ec2_reservation . get ( 'groupSet' , [ ] ) ] , #NEWLINE# #UNINDENT# } #NEWLINE# if ( 'kernelId' in ec2_instance ) : #NEWLINE# #INDENT# metadata [ 'kernel-id' ] = ec2_instance [ 'kernelId' ] #NEWLINE# #UNINDENT# if ( 'ramdiskId' in ec2_instance ) : #NEWLINE# #INDENT# metadata [ 'ramdisk-id' ] = ec2_instance [ 'ramdiskId' ] #NEWLINE# #UNINDENT# if ec2_instance [ 'keyName' ] : #NEWLINE# #INDENT# metadata [ 'public-keys' ] = { #NEWLINE# #INDENT# '0' : { #NEWLINE# #INDENT# '_name' : ( '0=' + ec2_instance [ 'keyName' ] ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# nova = clients . nova ( context ) #NEWLINE# os_instance = nova . servers . get ( os_instance_id ) #NEWLINE# try : #NEWLINE# #INDENT# keypair = nova . keypairs . _get ( ( '/%s/%s?user_id=%s' % ( nova . keypairs . keypair_prefix , ec2_instance [ 'keyName' ] , os_instance . user_id ) ) , 'keypair' ) #NEWLINE# #UNINDENT# except nova_exception . NotFound : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# metadata [ 'public-keys' ] [ '0' ] [ 'openssh-key' ] = keypair . public_key #NEWLINE# #UNINDENT# #UNINDENT# full_metadata = { #NEWLINE# #INDENT# 'meta-data' : context , #NEWLINE# #UNINDENT# } #NEWLINE# userdata = instance_api . describe_instance_attribute ( context , ec2_instance [ 'instanceId' ] , 'userData' ) #NEWLINE# if ( 'userData' in userdata ) : #NEWLINE# #INDENT# userdata = userdata [ 'userData' ] [ 'value' ] #NEWLINE# userdata = base64 . b64decode ( userdata ) #NEWLINE# userdata = userdata . decode ( 'utf-8' ) #NEWLINE# full_metadata [ 'user-data' ] = userdata #NEWLINE# #UNINDENT# return full_metadata