Skip to content

Commit 9e86cf9

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 0b76a3b commit 9e86cf9

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

wrapanapi/systems/openstack.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
)
4444
from wrapanapi.systems.base import System
4545

46-
4746
# TODO The following monkeypatch nonsense is criminal, and would be
4847
# greatly simplified if openstack made it easier to specify a custom
4948
# client class. This is a trivial PR that they're likely to accept.
@@ -230,7 +229,9 @@ def assign_floating_ip(self, floating_ip_pool, safety_timer=5):
230229
if len(free_ips) > 1:
231230
# There are 2 and more ips, so we will take the first one (eldest)
232231
ip = free_ips[0]
233-
self.logger.info("Reusing %s from pool %s", ip.floating_ip_address, floating_ip_pool)
232+
self.logger.info(
233+
"Reusing %s from pool %s", ip.floating_ip_address, floating_ip_pool
234+
)
234235
else:
235236
# There is one or none, so create one.
236237
try:
@@ -252,7 +253,9 @@ def assign_floating_ip(self, floating_ip_pool, safety_timer=5):
252253
raise NoMoreFloatingIPs(f"Provider {self.system.auth_url} ran out of FIPs")
253254
self.logger.info("Created %s in pool %s", ip.floating_ip_address, floating_ip_pool)
254255
# Use openstacksdk to associate floating IP with server
255-
self.system.openstack_conn.compute.add_floating_ip_to_server(instance, ip.floating_ip_address)
256+
self.system.openstack_conn.compute.add_floating_ip_to_server(
257+
instance, ip.floating_ip_address
258+
)
256259

257260
# Now the grace period in which a FIP theft could happen
258261
time.sleep(safety_timer)
@@ -276,10 +279,15 @@ def unassign_floating_ip(self):
276279
return None
277280
floating_ip = floating_ips[0]
278281
self.logger.info(
279-
"Detaching floating IP %s/%s from %s", floating_ip.id, floating_ip.floating_ip_address, instance.name
282+
"Detaching floating IP %s/%s from %s",
283+
floating_ip.id,
284+
floating_ip.floating_ip_address,
285+
instance.name,
280286
)
281287
# Use openstacksdk to disassociate floating IP from server
282-
self.system.openstack_conn.compute.remove_floating_ip_from_server(instance, floating_ip.floating_ip_address)
288+
self.system.openstack_conn.compute.remove_floating_ip_from_server(
289+
instance, floating_ip.floating_ip_address
290+
)
283291
wait_for(lambda: self.ip is None, delay=1, timeout="1m")
284292
return floating_ip
285293

@@ -773,22 +781,30 @@ def _list_floating_ips(self, **filters):
773781
openstack_filters["fixed_ip_address"] = filters["fixed_ip"]
774782
if "pool" in filters and filters["pool"]:
775783
# Pool in nova corresponds to network in openstack sdk
776-
networks = list(self.openstack_conn.network.networks(name=filters["pool"], is_router_external=True))
784+
networks = list(
785+
self.openstack_conn.network.networks(name=filters["pool"], is_router_external=True)
786+
)
777787
if networks:
778788
openstack_filters["floating_network_id"] = networks[0].id
779789

780790
floating_ips = list(self.openstack_conn.network.floating_ips(**openstack_filters))
781791

782792
# Post-process for fixed_ip=None case (unassigned floating IPs)
783793
if "fixed_ip" in filters and filters["fixed_ip"] is None:
784-
floating_ips = [fip for fip in floating_ips if fip.fixed_ip_address is None or fip.fixed_ip_address == ""]
794+
floating_ips = [
795+
fip
796+
for fip in floating_ips
797+
if fip.fixed_ip_address is None or fip.fixed_ip_address == ""
798+
]
785799

786800
return floating_ips
787801

788802
def _create_floating_ip(self, pool_name):
789803
"""Create floating IP using openstacksdk."""
790804
# Find the external network by name
791-
networks = list(self.openstack_conn.network.networks(name=pool_name, is_router_external=True))
805+
networks = list(
806+
self.openstack_conn.network.networks(name=pool_name, is_router_external=True)
807+
)
792808
if not networks:
793809
raise Exception(f"External network '{pool_name}' not found")
794810

@@ -1127,7 +1143,9 @@ def volume_attachments(self, volume_id):
11271143

11281144
def free_fips(self, pool):
11291145
"""Returns list of free floating IPs sorted by ip address."""
1130-
return sorted(self._list_floating_ips(fixed_ip=None, pool=pool), key=lambda ip: ip.floating_ip_address)
1146+
return sorted(
1147+
self._list_floating_ips(fixed_ip=None, pool=pool), key=lambda ip: ip.floating_ip_address
1148+
)
11311149

11321150
def delete_floating_ip(self, floating_ip):
11331151
"""Deletes an existing FIP.
@@ -1148,7 +1166,9 @@ def delete_floating_ip(self, floating_ip):
11481166
if not floating_ip_list:
11491167
return False
11501168
floating_ip = floating_ip_list[0]
1151-
self.logger.info("Deleting floating IP %s/%s", floating_ip.id, floating_ip.floating_ip_address)
1169+
self.logger.info(
1170+
"Deleting floating IP %s/%s", floating_ip.id, floating_ip.floating_ip_address
1171+
)
11521172
self.openstack_conn.network.delete_floating_ip(floating_ip)
11531173
wait_for(
11541174
lambda: len(self._list_floating_ips(ip=floating_ip.floating_ip_address)) == 0,

0 commit comments

Comments
 (0)