#NEWLINE# def delete_subnet( self , context , id ) : #NEWLINE# #INDENT# with context . session . begin ( subtransactions = True ) : #NEWLINE# #INDENT# subnet = self . _get_subnet ( context , id ) #NEWLINE# _check_subnet_not_used ( context , is_auto_addr_subnet ) #NEWLINE# qry_network_ports = context . session . query ( models_v2 . IPAllocation ) . filter_by ( subnet_id = subnet [ '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_network_ports = qry_network_ports . filter ( models_v2 . Port . device_owner . in_ ( AUTO_DELETE_PORT_OWNERS ) ) #NEWLINE# #UNINDENT# network_ports = qry_network_ports . all ( ) #NEWLINE# if network_ports : #NEWLINE# #INDENT# for port in network_ports : #NEWLINE# #INDENT# context . session . delete ( port ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not is_auto_addr_subnet ) : #NEWLINE# #INDENT# alloc = self . _subnet_check_ip_allocations ( context , id ) #NEWLINE# if 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' : alloc . ip_address , #NEWLINE# 'port_id' : alloc . port_id , #NEWLINE# 'subnet' : id , #NEWLINE# #UNINDENT# } ) #NEWLINE# raise exc . SubnetInUse ( subnet_id = id ) #NEWLINE# #UNINDENT# #UNINDENT# context . session . delete ( subnet ) #NEWLINE# self . ipam . delete_subnet ( context , id )