From 3b0ae6c43fcbbc16f251beb9807de6786a6cbf9e Mon Sep 17 00:00:00 2001 From: Jakob Meng Date: Thu, 5 Jan 2023 09:07:27 +0100 Subject: [PATCH] Use Neutron instead of Nova when detaching floating ips if available Nova's API for detaching floating ips is deprecated and will fail with a 404 starting from microversion 2.44. It has been replaced with Neutron networking service API [0]. Previously, this did not cause issues because openstacksdk was not passing a microversion for server actions, but this has been fixed in [1]. [0] https://docs.openstack.org/api-ref/compute/#remove-disassociate-floating-ip-removefloatingip-action-deprecated [1] https://review.opendev.org/c/openstack/openstacksdk/+/867890 Change-Id: Idad68d12f4ee163480877418caa93146ea873237 --- plugins/modules/floating_ip.py | 8 ++++++-- plugins/modules/server.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/modules/floating_ip.py b/plugins/modules/floating_ip.py index fbfda7f1..77c976ed 100644 --- a/plugins/modules/floating_ip.py +++ b/plugins/modules/floating_ip.py @@ -368,8 +368,12 @@ class NetworkingFloatingIPModule(OpenStackModule): for ip in ips: if ip['fixed_ip_address']: # Silently ignore that ip might not be attached to server - self.conn.compute.remove_floating_ip_from_server( - self.server, ip['floating_ip_address']) + # + # self.conn.network.update_ip(ip_id, port_id=None) does not + # handle nova network but self.conn.detach_ip_from_server() + # does so + self.conn.detach_ip_from_server(server_id=self.server['id'], + floating_ip_id=ip['id']) # OpenStackSDK sets {"port_id": None} to detach a floating # ip from an instance, but there might be a delay until a diff --git a/plugins/modules/server.py b/plugins/modules/server.py index 127ce532..f058c922 100644 --- a/plugins/modules/server.py +++ b/plugins/modules/server.py @@ -1111,8 +1111,9 @@ class ServerModule(OpenStackModule): for ip in remove_ips: ip_id = self.conn.network.find_ip(name_or_id=ip, ignore_missing=False).id - # self.network.update_ip(ip_id, port_id=None) would not handle - # nova network which self.conn.detach_ip_from_server() does + # self.conn.network.update_ip(ip_id, port_id=None) does not + # handle nova network but self.conn.detach_ip_from_server() + # does so self.conn.detach_ip_from_server(server_id=server.id, floating_ip_id=ip_id) return server