Deleting Network Resources using the CLI

You create and connect network resources in a specific order because of their dependencies; therefore, you cannot delete a resource until you disconnect all interdependent resources. For example, if you attempt to delete a network in use, you will receive an error message regarding a conflict:

$ openstack network delete <NETWORK_ID>
Failed to delete network with name or ID <NETWORK_ID>: HttpException: Conflict
1 of 1 networks failed to delete.

To disassociate resources and delete a private network:

  1. Identify the network to delete. Note the network name and ID and the subnet name and ID.

    $ openstack network list --internal
    +---------------+---------------------------------+---------------+
    | ID            | Name                            | Subnets       |
    +---------------+---------------------------------+---------------+
    | <network_id>  | testnet                         | <subnet_id>   |
    | <network_id>  | PUBLIC EXTERNAL - DO NOT MODIFY | <subnet_id>   |
    +---------------+---------------------------------+---------------+
    
  2. Check for instances associated with fixed and floating IP addresses on the network to delete. The Networks column shows the private, fixed IP address and the public, floating IP address.

    $ openstack server list
    
    +-----------------+-------------+--------+------------------------------------+-----------------------------------+
    | ID              | Name        | Status | Networks                           | Image Name                        |
    +-----------------+-------------+--------+------------------------------------+-----------------------------------+
    | <instance_id>   | instance01  | ACTIVE | testnet=192.168.8.3, <floating_ip> | ubuntu-16.04.1-server-amd64       |
    +-----------------+-------------+--------+------------------------------------+-----------------------------------+
    
  3. Disassociate the floating IP address from the instance. Repeat this command for every instance associated with a floating IP address on the private network.

    $ openstack server remove floating ip <INSTANCE_ID> <FLOATING_IP>
    
  4. Check for associations with the subnet ID of the private network. Using the --long option allows you to see the Device Owner column, which helps to identify a router or an instance interface.

    $ openstack port list --network <NETWORK_ID> --long
       
    +---------------------+------+-------------------+---------------------------------------------------+--------+--------------------------+
    | ID                  | Name | MAC Address       | Fixed IP Addresses                                | Status | Device Owner             |
    +---------------------+------+-------------------+---------------------------------------------------+--------+--------------------------+
    | <network_port_id>   |      | fa:16:3e:ab:ca:fd | ip_address='192.168.8.2', subnet_id='<subnet_id>' | ACTIVE | network:dhcp             |
    | <router_port_id>    |      | fa:16:3e:02:cc:41 | ip_address='192.168.8.1', subnet_id='<subnet_id>' | ACTIVE | network:router_interface |
    | <instance_port_id>  |      | fa:16:3e:a0:3e:bb | ip_address='192.168.8.3', subnet_id='<subnet_id>' | ACTIVE | compute:<az>             |
    +---------------------+------+-------------------+---------------------------------------------------+--------+--------------------------+
    

    Note
    Shorten the list by using a pipe to the grep command to locate the subnet ID: | grep <SUBNET_ID>

  5. Detach the interface from the instance. In the above port list, there are three ports: the network, a router, and an instance. The instance port ID belongs to the compute:<az> device owner.

    $ openstack port delete <INSTANCE_PORT_ID>
    
  6. Use the port ID for the network:router_interface device owner to get the router ID. The device_id field value contains the router ID.

    $ openstack port show <ROUTER_PORT_ID>
    +-----------------------+-----------------------------------------------------------------------------------------------+
    | Field                 | Value                                                                                         |
    +-----------------------+-----------------------------------------------------------------------------------------------+
    | admin_state_up        | UP                                                                                            |
    | allowed_address_pairs |                                                                                               |
    | binding_host_id       | None                                                                                          |
    | binding_profile       | None                                                                                          |
    | binding_vif_details   | None                                                                                          |
    | binding_vif_type      | None                                                                                          |
    | binding_vnic_type     | normal                                                                                        |
    | created_at            | None                                                                                          |
    | data_plane_status     | None                                                                                          |
    | description           | None                                                                                          |
    | device_id             | <network:router_interface_id>                                                                 |
    | device_owner          | network:router_interface                                                                      |
    | dns_assignment        | fqdn='host-192-168-8-1.openstacklocal.', hostname='host-192-168-8-1', ip_address='192.168.8.1'|
    | dns_name              |                                                                                               |
    | extra_dhcp_opts       |                                                                                               |
    | fixed_ips             | ip_address='192.168.8.1', subnet_id='<subnet_id>'                                             |
    | id                    | <port_id>                                                                                     |
    | ip_address            | None                                                                                          |
    | mac_address           | fa:16:3e:02:cc:41                                                                             |
    | name                  |                                                                                               |
    | network_id            | <network_id>                                                                                  |
    | option_name           | None                                                                                          |
    | option_value          | None                                                                                          |
    | port_security_enabled | False                                                                                         |
    | project_id            | <project_id>                                                                                  |
    | qos_policy_id         | None                                                                                          |
    | revision_number       | None                                                                                          |
    | security_group_ids    |                                                                                               |
    | status                | ACTIVE                                                                                        |
    | subnet_id             | None                                                                                          |
    | trunk_details         | None                                                                                          |
    | updated_at            | None                                                                                          |
    +-----------------------+-----------------------------------------------------------------------------------------------+
    
  7. Disconnect the router from the subnet using the device ID associated with the network:router_interface device owner.

    $ openstack router remove subnet <ROUTER_ID> <SUBNET_ID>
    
  8. Delete the network.

    $ openstack network delete <NETWORK_ID>