#NEWLINE# @ utils . transaction_guard #NEWLINE# def delete_subnet( self , context , id ) : #NEWLINE# #INDENT# LOG . debug ( 'Deleting subnet %s' , id ) #NEWLINE# session = context . session #NEWLINE# while True : #NEWLINE# #INDENT# with session . begin ( subtransactions = True ) : #NEWLINE# #INDENT# record = self . _get_subnet ( context , id ) #NEWLINE# subnet = self . _make_subnet_dict ( alloc , None , context = context ) #NEWLINE# qry_allocated = session . query ( models_v2 . IPAllocation ) . filter_by ( subnet_id = id ) . join ( models_v2 . Port ) #NEWLINE# is_auto_addr_subnet = ipv6_utils . is_auto_address_subnet ( subnet ) #NEWLINE# if is_auto_addr_subnet : #NEWLINE# #INDENT# self . _subnet_check_ip_allocations_internal_router_ports ( context , id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# qry_allocated = qry_allocated . filter ( models_v2 . Port . device_owner . in_ ( db_base_plugin_v2 . AUTO_DELETE_PORT_OWNERS ) ) #NEWLINE# #UNINDENT# allocated = qry_allocated . all ( ) #NEWLINE# if allocated : #NEWLINE# #INDENT# for x in allocated : #NEWLINE# #INDENT# session . delete ( x ) #NEWLINE# #UNINDENT# #UNINDENT# LOG . debug ( 'Ports to auto-deallocate: %s' , allocated ) #NEWLINE# if ( not is_auto_addr_subnet ) : #NEWLINE# #INDENT# alloc = self . _subnet_check_ip_allocations ( context , id ) #NEWLINE# if alloc : #NEWLINE# #INDENT# user_alloc = self . _subnet_get_user_allocation ( context , id ) #NEWLINE# if user_alloc : #NEWLINE# #INDENT# LOG . info ( _LI ( 'Found port (%(port_id)s, %(ip)s) having IP allocation on subnet %(subnet)s, cannot delete' ) , { #NEWLINE# #INDENT# 'ip' : user_alloc . ip_address , #NEWLINE# 'port_id' : user_alloc . port_id , #NEWLINE# 'subnet' : id , #NEWLINE# #UNINDENT# } ) #NEWLINE# raise exc . SubnetInUse ( subnet_id = id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise os_db_exception . RetryRequest ( exc . SubnetInUse ( subnet_id = id ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# db_base_plugin_v2 . _check_subnet_not_used ( context , id ) #NEWLINE# if ( not allocated ) : #NEWLINE# #INDENT# network = self . get_network ( context , subnet [ 'network_id' ] ) #NEWLINE# mech_context = driver_context . SubnetContext ( self , context , subnet , network ) #NEWLINE# self . mechanism_manager . delete_subnet_precommit ( mech_context ) #NEWLINE# LOG . debug ( 'Deleting subnet record' ) #NEWLINE# session . delete ( record ) #NEWLINE# self . ipam . delete_subnet ( context , id ) #NEWLINE# LOG . debug ( 'Committing transaction' ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# for a in allocated : #NEWLINE# #INDENT# if a . port : #NEWLINE# #INDENT# data = { #NEWLINE# #INDENT# attributes . PORT : { #NEWLINE# #INDENT# 'fixed_ips' : [ { #NEWLINE# #INDENT# 'subnet_id' : ip . subnet_id , #NEWLINE# 'ip_address' : ip . ip_address , #NEWLINE# #UNINDENT# } for ip in a . port . fixed_ips if ( ip . subnet_id != id ) ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# self . update_port ( context , a . port_id , data ) #NEWLINE# #UNINDENT# except exc . PortNotFound : #NEWLINE# #INDENT# LOG . debug ( 'Port %s deleted concurrently' , a . port_id ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# LOG . exception ( _LE ( 'Exception deleting fixed_ip from port %s' ) , a . port_id ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# self . mechanism_manager . delete_subnet_postcommit ( mech_context ) #NEWLINE# #UNINDENT# except ml2_exc . MechanismDriverError : #NEWLINE# #INDENT# LOG . error ( _LE ( 'mechanism_manager.delete_subnet_postcommit failed' ) )