From c97bac299751775294e8abc5f01d1bfb7bb681cf Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 1 Jun 2017 16:46:27 -0500 Subject: [PATCH] Do less work when deleting a server and floating ips When we delete a server with floating ips, we tell get_server to not fetch a bare server, which does the work to fill in the network info from neutron. Then we look in the server for the floating ip address and look up the port it goes with. This is not necessary. We can tell get_server to get us a bare server, then look up floating ips by device_id. Then just delete them. Change-Id: I5ec04dc2a356aa20cf561866e8f43f9e28b2db21 --- shade/openstackcloud.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index e08758ab0..dfa5900b5 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -5617,7 +5617,7 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ # If delete_ips is True, we need the server to not be bare. - server = self.get_server(name_or_id, bare=not delete_ips) + server = self.get_server(name_or_id, bare=True) if not server: return False @@ -5635,22 +5635,11 @@ class OpenStackCloud( return False if delete_ips: - # Don't pass public=True because we're just deleting. Testing - # for connectivity is not useful. - floating_ip = meta.get_server_ip(server, ext_tag='floating') - if floating_ip: - ips = self.search_floating_ips(filters={ - 'floating_ip_address': floating_ip}) - if len(ips) != 1: - raise OpenStackCloudException( - "Tried to delete floating ip {floating_ip}" - " associated with server {id} but there was" - " an error finding it. Something is exceptionally" - " broken.".format( - floating_ip=floating_ip, - id=server['id'])) + ips = self.search_floating_ips(filters={ + 'device_id': server['id']}) + for ip in ips: deleted = self.delete_floating_ip( - ips[0]['id'], retry=delete_ip_retry) + ip['id'], retry=delete_ip_retry) if not deleted: raise OpenStackCloudException( "Tried to delete floating ip {floating_ip}"