1. 程式人生 > >OpenStack neutron刪除網路裝置出錯解決辦法

OpenStack neutron刪除網路裝置出錯解決辦法

From: https://www.cnblogs.com/starof/p/4224342.html

目標:要刪除外網Ext-Net2

直接刪網路也會出錯:因為有一個或多個埠在使用該網路

複製程式碼

[email protected]:~# neutron net-list
+--------------------------------------+-------------+----------------------------------------------------+
| id                                   | name        | subnets                                            |
+--------------------------------------+-------------+----------------------------------------------------+
| 739485b6-bc45-4a53-953d-f3c4cb07f601 | Ext-Net2    | ef86e785-8cec-486a-b67f-dcbba5311293 10.100.0.0/24 |
| 7c22bbd9-166c-4610-9a3d-3b8b92c77518 | tenantA-Net | c37d8ed0-372e-4b24-9ba2-897c38c6ddbf 10.0.0.0/24   |
| c8699820-7c6d-4441-9602-3425f2c630ec | Ext-Net     | 2c4155c9-5a2e-471c-a4d8-40a86b45ab0a 10.1.101.0/24 |
+--------------------------------------+-------------+----------------------------------------------------+
[email protected]
:~# neutron net-delete 739485b6-bc45-4a53-953d-f3c4cb07f601 Unable to complete operation on network 739485b6-bc45-4a53-953d-f3c4cb07f601. There are one or more ports still in use on the network.

複製程式碼

檢視子網:刪除子網會出錯:一個或多個埠用了這個子網分配的浮動IP。

複製程式碼

[email protected]:~# neutron subnet-list
+--------------------------------------+-----------------+---------------+--------------------------------------------------+
| id                                   | name            | cidr          | allocation_pools                                 |
+--------------------------------------+-----------------+---------------+--------------------------------------------------+
| 2c4155c9-5a2e-471c-a4d8-40a86b45ab0a |                 | 10.1.101.0/24 | {"start": "10.1.101.80", "end": "10.1.101.100"}  |
| c37d8ed0-372e-4b24-9ba2-897c38c6ddbf |                 | 10.0.0.0/24   | {"start": "10.0.0.2", "end": "10.0.0.254"}       |
| ef86e785-8cec-486a-b67f-dcbba5311293 | subNet-Ext-Net2 | 10.100.0.0/24 | {"start": "10.100.0.100", "end": "10.100.0.120"} |
+--------------------------------------+-----------------+---------------+--------------------------------------------------+

複製程式碼

[email protected]:~# neutron subnet-delete ef86e785-8cec-486a-b67f-dcbba5311293
409-{u'NeutronError': {u'message': u'Unable to complete operation on subnet ef86e785-8cec-486a-b67f-dcbba5311293. One or more ports have an IP allocation from this subnet.', u'type': u'SubnetInUse', u'detail': u''}}

直接刪port會出錯,因為埠有浮點IP所以不能直接刪除

複製程式碼

[email protected]:~# neutron port-list
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
| id                                   | name | mac_address       | fixed_ips                                                                           |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
| 1653ec91-ad7d-40d9-b777-f74aec697026 |      | fa:16:3e:51:a2:97 | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.9"}     |
| 2df7c3ed-dfbb-480d-9cd3-fdefa079e66a |      | fa:16:3e:da:41:49 | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.3"}     |
| 81388454-30e0-45e4-b3dd-b7b2e8dbf067 |      | fa:16:3e:f7:e6:9c | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.1"}     |
| accd8dbf-0f16-4aec-b797-bbb33abcdc83 |      | fa:16:3e:97:ee:cb | {"subnet_id": "ef86e785-8cec-486a-b67f-dcbba5311293", "ip_address": "10.100.0.103"} |
| bfe7eaa4-26bc-4fe9-9da2-550abf44beaa |      | fa:16:3e:e1:00:41 | {"subnet_id": "2c4155c9-5a2e-471c-a4d8-40a86b45ab0a", "ip_address": "10.1.101.83"}  |
| d7233b80-9d4b-4ef6-a60d-19b3be661069 |      | fa:16:3e:75:e0:5a | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.10"}    |
| eb60f9c4-2ddb-49ee-8b78-2fc2564a7600 |      | fa:16:3e:78:39:e9 | {"subnet_id": "2c4155c9-5a2e-471c-a4d8-40a86b45ab0a", "ip_address": "10.1.101.80"}  |
| f6812a11-c4ce-4880-8566-2206afcc612a |      | fa:16:3e:9e:75:a2 | {"subnet_id": "2c4155c9-5a2e-471c-a4d8-40a86b45ab0a", "ip_address": "10.1.101.82"}  |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+

複製程式碼

[email protected]:~# neutron port-delete accd8dbf-0f16-4aec-b797-bbb33abcdc83
409-{u'NeutronError': {u'message': u'Port accd8dbf-0f16-4aec-b797-bbb33abcdc83 has owner network:floatingip and therefore cannot be deleted directly via the port API.', u'type': u'L3PortInUse', u'detail': u''}}

但是卻查不到浮動IP

[email protected]:~# nova  floating-ip-list
+----+-----------+----------+------+
| Ip | Server Id | Fixed Ip | Pool |
+----+-----------+----------+------+
+----+-----------+----------+------+
[email protected]:~# nova floating-ip-delete 10.100.0.103
ERROR: Floating ip 10.100.0.103 not found.

解除繫結浮動IP:這樣做也不可行,因為這個ID不是虛擬機器的ID。

複製程式碼

[email protected]:~# neutron port-list
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
| id                                   | name | mac_address       | fixed_ips                                                                           |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
| 1653ec91-ad7d-40d9-b777-f74aec697026 |      | fa:16:3e:51:a2:97 | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.9"}     |
| 2df7c3ed-dfbb-480d-9cd3-fdefa079e66a |      | fa:16:3e:da:41:49 | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.3"}     |
| 81388454-30e0-45e4-b3dd-b7b2e8dbf067 |      | fa:16:3e:f7:e6:9c | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.1"}     |
| accd8dbf-0f16-4aec-b797-bbb33abcdc83 |      | fa:16:3e:97:ee:cb | {"subnet_id": "ef86e785-8cec-486a-b67f-dcbba5311293", "ip_address": "10.100.0.103"} |
| bfe7eaa4-26bc-4fe9-9da2-550abf44beaa |      | fa:16:3e:e1:00:41 | {"subnet_id": "2c4155c9-5a2e-471c-a4d8-40a86b45ab0a", "ip_address": "10.1.101.83"}  |
| d7233b80-9d4b-4ef6-a60d-19b3be661069 |      | fa:16:3e:75:e0:5a | {"subnet_id": "c37d8ed0-372e-4b24-9ba2-897c38c6ddbf", "ip_address": "10.0.0.10"}    |
| eb60f9c4-2ddb-49ee-8b78-2fc2564a7600 |      | fa:16:3e:78:39:e9 | {"subnet_id": "2c4155c9-5a2e-471c-a4d8-40a86b45ab0a", "ip_address": "10.1.101.80"}  |
| f6812a11-c4ce-4880-8566-2206afcc612a |      | fa:16:3e:9e:75:a2 | {"subnet_id": "2c4155c9-5a2e-471c-a4d8-40a86b45ab0a", "ip_address": "10.1.101.82"}  |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
[email protected]:~# nova floating-ip-disassociate accd8dbf-0f16-4aec-b797-bbb33abcdc83 10.100.0.103
ERROR: No server with a name or ID of 'accd8dbf-0f16-4aec-b797-bbb33abcdc83' exists.

複製程式碼

通過horizon檢視,發現該浮動IP,沒有被分配,但是用命令卻查不到

[email protected]:~# nova --os-tenant-name TenantA --os-username UserA --os-password password  --os-auth-url=http://localhost:5000/v2.0  floating-ip-list              
ERROR: The server has either erred or is incapable of performing the requested operation. (HTTP 500) (Request-ID: req-294eb77b-1615-46fb-93de-d10660a46b70)

沒辦法,只能手動從horizon釋放掉浮動IP了。登入UserA,手動釋放掉浮動IP10.100.0.3,現在就可以正常刪除了。

現在刪除Ext-Net2就沒問題了。

複製程式碼

[email protected]:~# neutron net-list
+--------------------------------------+-------------+----------------------------------------------------+
| id                                   | name        | subnets                                            |
+--------------------------------------+-------------+----------------------------------------------------+
| 739485b6-bc45-4a53-953d-f3c4cb07f601 | Ext-Net2    | ef86e785-8cec-486a-b67f-dcbba5311293 10.100.0.0/24 |
| 7c22bbd9-166c-4610-9a3d-3b8b92c77518 | tenantA-Net | c37d8ed0-372e-4b24-9ba2-897c38c6ddbf 10.0.0.0/24   |
| c8699820-7c6d-4441-9602-3425f2c630ec | Ext-Net     | 2c4155c9-5a2e-471c-a4d8-40a86b45ab0a 10.1.101.0/24 |
+--------------------------------------+-------------+----------------------------------------------------+
[email protected]:~# neutron net-delete 739485b6-bc45-4a53-953d-f3c4cb07f601
Deleted network: 739485b6-bc45-4a53-953d-f3c4cb07f601

複製程式碼

總結:用admin刪除網路時注意,admin看不到租戶分配的浮動IP,所以得用租戶登入釋放掉浮動IP。

目標:刪除租戶的網路

複製程式碼

[email protected]:~# neutron net-list
+--------------------------------------+-------------+-------------------------------------------------------+
| id                                   | name        | subnets                                               |
+--------------------------------------+-------------+-------------------------------------------------------+
| 3ccfd309-df88-4301-bd96-7f9852bec855 | TenantB-Net | aa4b016f-dbf2-435e-9388-57824ae2c235 192.168.0.0/24   |
| b009f565-10b5-407b-93e4-e187636cd99d | ext-net     | ba2ddac5-5eaf-409a-a9c1-fdafd04d21d9 10.0.200.0/24    |
+--------------------------------------+-------------+-------------------------------------------------------+
[email protected]:~# neutron net-delete TenantB-Net
Unable to complete operation on network 3ccfd309-df88-4301-bd96-7f9852bec855. There are one or more ports still in use on the network. (HTTP 409) (Request-ID: req-bcb58ccf-f95b-4a02-8f28-5384562dc0eb)

複製程式碼

看一下子網

複製程式碼

[email protected]:~# neutron subnet-list
+--------------------------------------+--------------------+------------------+------------------------------------------------------+
| id                                   | name               | cidr             | allocation_pools                                     |
+--------------------------------------+--------------------+------------------+------------------------------------------------------+
| aa4b016f-dbf2-435e-9388-57824ae2c235 | TenantB-Net-SubNet | 192.168.0.0/24   | {"start": "192.168.0.2", "end": "192.168.0.254"}     |
| ba2ddac5-5eaf-409a-a9c1-fdafd04d21d9 | ext-subnet         | 10.0.200.0/24    | {"start": "10.0.200.100", "end": "10.0.200.250"}     |
| 7fa4a398-b67b-462b-a9b3-c65802952f79 | sub_lxp_net        | 192.168.1.0/24   | {"start": "192.168.1.150", "end": "192.168.1.200"}   |
| 2e985c9f-3668-417f-8b40-d7f551e668c0 | sub_lxp_net2       | 192.168.100.0/24 | {"start": "192.168.100.1", "end": "192.168.100.254"} |
+--------------------------------------+--------------------+------------------+------------------------------------------------------+
[email protected]:~# neutron port-list
+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+
| id                                   | name | mac_address       | fixed_ips                                                                            |
+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+
| 6d0ec7ba-37e8-4784-8076-b2e39c3b8f00 |      | fa:16:3e:8b:62:98 | {"subnet_id": "2e985c9f-3668-417f-8b40-d7f551e668c0", "ip_address": "192.168.100.3"} |
| 7915e60f-a4d6-4f2c-875b-b402f8828571 |      | fa:16:3e:54:f1:51 | {"subnet_id": "2e985c9f-3668-417f-8b40-d7f551e668c0", "ip_address": "192.168.100.1"} |
| 963ceaa8-3750-449b-bebd-3f8e89e6dd0d |      | fa:16:3e:96:29:98 | {"subnet_id": "7fa4a398-b67b-462b-a9b3-c65802952f79", "ip_address": "192.168.1.150"} |
| a56330b4-3409-4b40-aadf-b0f2302b2c16 |      | fa:16:3e:be:c9:54 | {"subnet_id": "2e985c9f-3668-417f-8b40-d7f551e668c0", "ip_address": "192.168.100.2"} |
| b7792c1a-d284-494c-b1b8-8609f33957c3 |      | fa:16:3e:1d:c1:d1 | {"subnet_id": "aa4b016f-dbf2-435e-9388-57824ae2c235", "ip_address": "192.168.0.1"}   |
| cdabb78e-11f1-4b0d-ab4d-59abba4c0ab1 |      | fa:16:3e:1e:32:7f | {"subnet_id": "ba2ddac5-5eaf-409a-a9c1-fdafd04d21d9", "ip_address": "10.0.200.100"}  |
+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+
[email protected]:~# neutron port-delete b7792c1a-d284-494c-b1b8-8609f33957c3
Port b7792c1a-d284-494c-b1b8-8609f33957c3 has owner network:router_interface and therefore cannot be deleted directly via the port API. (HTTP 409) (Request-ID: req-500d34ea-9cdc-4566-b931-25fb934d9864)

複製程式碼

要刪port,先看路由

複製程式碼

[email protected]:~# neutron router-list
+--------------------------------------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+-------+
| id                                   | name           | external_gateway_info                                                                                                                                                                    | distributed | ha    |
+--------------------------------------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+-------+
| 9a5054d7-35a4-441f-a0fb-d5bf7070edc7 | TenantB-Router | {"network_id": "b009f565-10b5-407b-93e4-e187636cd99d", "enable_snat": true, "external_fixed_ips": [{"subnet_id": "ba2ddac5-5eaf-409a-a9c1-fdafd04d21d9", "ip_address": "10.0.200.100"}]} | False       | False |
+--------------------------------------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+-------+
[email protected]:~# neutron router-delete TenantB-Router
Router 9a5054d7-35a4-441f-a0fb-d5bf7070edc7 still has ports (HTTP 409) (Request-ID: req-282fe122-4cab-4595-9f63-825ad81f13b9)

複製程式碼

路由接著外網和私網的子網。

所以先刪路由上的閘道器

[email protected]:~# neutron router-gateway-clear TenantB-Router
Removed gateway from router TenantB-Router

再刪路由上的介面,刪除某個路由的某個介面

[email protected]:~# neutron router-interface-delete  TenantB-Router TenantB-Net-SubNet
Removed interface from router TenantB-Router.
[email protected]:~# 

port是關聯路由和子網的。所以清掉路由上的介面,那port就沒有了。

[email protected]:~# neutron router-delete TenantB-Router
Deleted router: TenantB-Router

接著刪子網

[email protected]:~# neutron subnet-delete TenantB-Net-SubNet
Deleted subnet: TenantB-Net-SubNet

最後網路就可以刪掉了

[email protected]:~# neutron net-delete TenantB-Net
Deleted network: TenantB-Net