#NEWLINE# def attach_internet_gateway( context , internet_gateway_id , vpc_id ) : #NEWLINE# #INDENT# igw = ec2utils . get_db_item ( context , internet_gateway_id ) #NEWLINE# if igw . get ( 'vpc_id' ) : #NEWLINE# #INDENT# msg_params = { #NEWLINE# #INDENT# 'igw_id' : igw [ 'id' ] , #NEWLINE# 'vpc_id' : igw [ 'vpc_id' ] , #NEWLINE# #UNINDENT# } #NEWLINE# msg = ( _ ( 'resource %(igw_id)s is already attached to network %(vpc_id)s' ) % msg_params ) #NEWLINE# raise exception . ResourceAlreadyAssociated ( msg ) #NEWLINE# #UNINDENT# vpc = ec2utils . get_db_item ( context , vpc_id ) #NEWLINE# if ec2utils . get_attached_gateway ( context , context [ 'id' ] , 'igw' ) : #NEWLINE# #INDENT# msg = ( _ ( 'Network %(vpc_id)s already has an internet gateway attached' ) % { #NEWLINE# #INDENT# 'vpc_id' : vpc [ 'id' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# raise exception . InvalidParameterValue ( msg ) #NEWLINE# #UNINDENT# external_network_id = None #NEWLINE# if ( not ec2utils . get_attached_gateway ( context , vpc [ 'id' ] , 'vgw' ) ) : #NEWLINE# #INDENT# external_network_id = ec2utils . get_os_public_network ( context ) [ 'id' ] #NEWLINE# #UNINDENT# neutron = clients . neutron ( context ) #NEWLINE# with common . OnCrashCleaner ( ) as cleaner : #NEWLINE# #INDENT# _attach_internet_gateway_item ( context , igw , vpc [ 'id' ] ) #NEWLINE# cleaner . addCleanup ( _detach_internet_gateway_item , context , igw ) #NEWLINE# if external_network_id : #NEWLINE# #INDENT# neutron . add_gateway_router ( vpc [ 'os_id' ] , { #NEWLINE# #INDENT# 'network_id' : external_network_id , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# return True