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 ID and the ID of any subnets.

    $ openstack network list --internal
    +---------------+---------------------------------+---------------+
    | ID            | Name                            | Subnets       |
    +---------------+---------------------------------+---------------+
    | a8ef0cd7-e    | testnet                         | c9a203a4-3    |
    | <network_id>  | PUBLIC EXTERNAL - DO NOT MODIFY | <subnet_id>   |
    +---------------+---------------------------------+---------------+
    
  2. Check for instances associated with a fixed and floating IP address 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.7, 184.94.253.77 | 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 this network.

    $ openstack server remove floating ip instance01 184.94.253.77
    
  4. Check for associations with the subnet ID of the network to delete. You can see the subnet ID in the Fixed IP Addresses column. There are three ports active on the subnet.

    $ openstack port list
       
    +------------+------+-------------------+---------------------------------------------------+--------+
    | ID         | Name | MAC Address       | Fixed IP Addresses                                | Status |
    +------------+------+-------------------+---------------------------------------------------+--------+
    | <port_id>  |      | fa:16:3e:ab:ca:fd | ip_address='192.168.8.2', subnet_id='<subnet_id>' | ACTIVE |
    | <port_id>  |      | fa:16:3e:02:cc:41 | ip_address='192.168.8.1', subnet_id='<subnet_id>' | ACTIVE |
    | 77c3704f-6 |      | fa:16:3e:a0:3e:bb | ip_address='192.168.8.7', subnet_id='c9a203a4-3'  | ACTIVE |
    | <port_id>  |      | fa:16:3e:10:3d:29 | ip_address='192.168.0.8', subnet_id='<subnet_id>' | ACTIVE |
    +------------+------+-------------------+---------------------------------------------------+--------+
    

    Note

    • Use the --long option to see the Device Owner column, which helps to indentify a router or an instance interface.
    • Shorten the list by using a pipe to the grep command to locate the subnet ID: | grep <SUBNET_ID>
  5. Delete the port with the same fixed IP address as the instance to disassociate the fixed IP address. In this example, the fixed IP of the instance is 192.168.8.7 associated with port ID 77c3704f-6.

    $ openstack port delete 77c3704f-6
    
  6. Disconnect the router from the subnet. The router is seen in the port list with the device owner network:router_interface. You may have to list the ports with the router option to confirm you are removing the correct router: $ openstack port list --router <ROUTER_NAME>

    $ openstack router remove subnet <ROUTER_NAME> c9a203a4-3
    
  7. Delete the network.

    $ openstack network delete a8ef0cd7-e