Detaching and Deleting Ports Attached to Network Resources

In this solution:

If you attempt to delete a network resource that has ports attached to it, such as a subnet or router, you may get an error.

In the Dashboard, the error message may look like the following screenshot:

delete_subnet_error.png 

In the CLI, the error message may explicitly refer to this issue, as with the following:

Failed to delete subnet with name or ID '<SUBNET_NAME>': HttpException: Conflict, Unable to complete operation on subnet <SUBNET_UUID>. One or more ports have an IP allocation from this subnet.
1 of 1 subnets failed to delete.

The solution is to perform the following actions before deleting each affected resource:

  1. Detach any ports from the resource.
  2. Delete the newly detached ports. 

Finding Ports Attached to a Router

If the resource you are trying to remove is a router, take the following steps to find its attached ports.

1. Locate the router you want to detach ports from: 

$ openstack router list
+--------------------------------------+-------------------------------------+--------+-------+-------------+-------+----------------------------------+
| ID                                   | Name                                | Status | State | Distributed | HA    | Project                          |
+--------------------------------------+-------------------------------------+--------+-------+-------------+-------+----------------------------------+
| <ROUTER_UUID>                        | router1                             | ACTIVE | UP    | False       | False | <PROJECT_UUID>                   |
| <ROUTER_UUID>                        | router2                             | ACTIVE | UP    | False       | False |                                  |
| <ROUTER_UUID>                        | router3                             | ACTIVE | UP    | False       | False | <PROJECT_UUID>                   |
+--------------------------------------+-------------------------------------+--------+-------+-------------+-------+----------------------------------+

2. Get IP address of the router, which appears in the external_gateway_info field returned by the following command:

$ openstack router show <ROUTER_UUID>
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                   | Value                                                                                                                                                                |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| admin_state_up          | UP                                                                                                                                                                   |
| availability_zone_hints | None                                                                                                                                                                 |
| availability_zones      | None                                                                                                                                                                 |
| created_at              | None                                                                                                                                                                 |
| description             | None                                                                                                                                                                 |
| distributed             | False                                                                                                                                                                |
| external_gateway_info   | {"network_id": "<NETWORK_UUID>", "external_fixed_ips": [{"subnet_id": "<SUBNET_UUID>", "ip_address": "<PORT_IP_ADDRESS>"}]}                                          |
| flavor_id               | None                                                                                                                                                                 |
| ha                      | False                                                                                                                                                                |
| id                      | <ROUTER_UUID>                                                                                                                                                        |
| name                    | router1                                                                                                                                                              |
| project_id              | <PROJECT_UUID>                                                                                                                                                       |
| revision_number         | None                                                                                                                                                                 |
| routes                  |                                                                                                                                                                      |
| status                  | ACTIVE                                                                                                                                                               |
| updated_at              | None                                                                                                                                                                 |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3. Use the IP address to find the port attached to that router:

$ openstack port list | grep <PORT_IP_ADDRESS>
| <PORT_UUID |             | <MAC_ADDRESS> | ip_address='<PORT_IP_ADDRESS>', subnet_id='<SUBNET_UUID>'  | ACTIVE |

Finding Ports Attached to a Subnet

If the resource you are trying to remove is a subnet, take the following steps to find attached ports.

1. View a list of networks, so that you can get the ID of the subnet with the ports you want to delete:

$ openstack network list
+--------------------------------------+---------------------------------+--------------------------------------+
| ID                                   | Name                            | Subnets                              |
+--------------------------------------+---------------------------------+--------------------------------------+
| <EXTERNAL_NETWORK_UUID>              | PUBLIC EXTERNAL - DO NOT MODIFY | <EXTERNAL_SUBNET_UUID>               |
| <INTERNAL_NETWORK_UUID>              | network2                        | <INTERNAL_SUBNET_UUID>               |
+--------------------------------------+---------------------------------+--------------------------------------+

2. Get a list of ports attached to the subnet:

$ openstack port list | grep <INTERNAL_SUBNET_UUID>
| <PORT_UUID> |        | <MAC_ADDRESS> | ip_address='<IPV4_ADDRESS', subnet_id='<INTERNAL_SUBNET_UUID>'       | ACTIVE |
| <PORT_UUID  |        | <MAC_ADDRESS> | ip_address='<IPV4_ADDRESS', subnet_id='<INTERNAL_SUBNET_UUID>'       | ACTIVE |

Identifying the Device Owners of Ports in a Subnet

A device owner is the virtual device that a port is attached to in a subnet, such as a VM. To identify the device owner before detaching and deleting a port, take the following steps.

1. View information about each port you identified from the port list in the preceding step:

$ openstack port show <PORT_UUID>
+-----------------------+---------------------------------------------------------------------------------------+
| Field                 | Value                                                                                 |
+-----------------------+---------------------------------------------------------------------------------------+
| admin_state_up        | UP                                                                                    |
| allowed_address_pairs |                                                                                       |
| binding_host_id       | <HOST_MHV_NAME>                                                                       |
| binding_profile       |                                                                                       |
| binding_vif_details   | port_filter='True'                                                                    |
| binding_vif_type      | bridge                                                                                |
| binding_vnic_type     | normal                                                                                |
| created_at            | None                                                                                  |
| description           | None                                                                                  |
| device_id             | <DEVICE_UUID>                                                                         |
| device_owner          | compute:stage1                                                                        |
| dns_assignment        | fqdn='host-<IP>.openstacklocal.', hostname='host-<IP>', ip_address='<IP>'             |
| dns_name              |                                                                                       |
| extra_dhcp_opts       |                                                                                       |
| fixed_ips             | ip_address='10.0.1.3', subnet_id='0a996369-cca1-4f60-80b1-af7f96c137a3'               |
| id                    | <PORT_UUID>                                                                           |
| ip_address            | None                                                                                  |
| mac_address           | <MAC_ADDRESS>                                                                         |
| name                  |                                                                                       |
| network_id            | <NETWORK_UUID>                                                                        |
| option_name           | None                                                                                  |
| option_value          | None                                                                                  |
| port_security_enabled | False                                                                                 |
| project_id            | <PROJECT_UUID>                                                                        |
| qos_policy_id         | None                                                                                  |
| revision_number       | None                                                                                  |
| security_groups       | <SECURITY_GROUPS_UUIDS>                                                               |
| status                | ACTIVE                                                                                |
| subnet_id             | None                                                                                  |
| updated_at            | None                                                                                  |
+-----------------------+---------------------------------------------------------------------------------------+

Note: A device owner value that begins with the string compute: indicates a VM.

2. To make sure you want to detach and delete a port attached to a given VM, get more information about the VM:

$ openstack server show <DEVICE_UUID>
+-------------------------------------+--------------------------------------------------------------------------+
| Field                               | Value                                                                    |
+-------------------------------------+--------------------------------------------------------------------------+
| OS-DCF:diskConfig                   | AUTO                                                                     |
| OS-EXT-AZ:availability_zone         | <AZ_NAME>                                                                |
| OS-EXT-SRV-ATTR:host                | <HOST_MHV_NAME>                                                          |
| OS-EXT-SRV-ATTR:hypervisor_hostname | <HOST_MHV_NAME>                                                          |
| OS-EXT-SRV-ATTR:instance_name       | <INSTANCE_NAME>                                                          |
| OS-EXT-STS:power_state              | Running                                                                  |
| OS-EXT-STS:task_state               | None                                                                     |
| OS-EXT-STS:vm_state                 | active                                                                   |
| OS-SRV-USG:launched_at              | 2017-06-13T20:54:11.000000                                               |
| OS-SRV-USG:terminated_at            | None                                                                     |
| accessIPv4                          |                                                                          |
| accessIPv6                          |                                                                          |
| addresses                           | network2=<IP>                                                            |
| config_drive                        |                                                                          |
| created                             | 2017-06-13T20:54:05Z                                                     |
| flavor                              | m1.small (2)                                                             |
| hostId                              | <HOST_MHV_UUID>                                                          |
| id                                  | <INSTANCE_UUID>                                                          |
| image                               | <IMAGE_NAME> (<IMAGE_UUID>)                                              |
| key_name                            | None                                                                     |
| name                                | <INSTANCE_NAME>                                                          |
| progress                            | 0                                                                        |
| project_id                          | <PROJECT_UUID>                                                           |
| properties                          |                                                                          |
| security_groups                     | name='default'                                                           |
| status                              | ACTIVE                                                                   |
| updated                             | 2017-06-13T20:54:11Z                                                     |
| user_id                             | <USER_UUID>                                                              |
| volumes_attached                    |                                                                          |
+-------------------------------------+--------------------------------------------------------------------------+

Detaching and Deleting Ports

After you find the ports attached to the service you want to remove, detach and delete them.

1. Detach each port from the device owner:

$ openstack port set <PORT_UUID> --device-owner none

2. Delete each port:

$ openstack port delete <PORT_UUID>

If the deletion is successful, the CLI provides no output from the command.

Have more questions? Submit a request
Powered by Zendesk