Skip to content

Commit

Permalink
Improve floating IP handling for consistent behavior across single an…
Browse files Browse the repository at this point in the history
…d multiple node deployments.
  • Loading branch information
skanthed committed Nov 19, 2024
1 parent dce236c commit 6564fdf
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions esi_ui/api/esi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,28 @@ def deploy_node(request, node):

network_id = kwargs['nics'][0]['network']

if kwargs['floatingIPOption'] == 'none':
kwargs['nics'] = [{'network': network_id}]
else:
connection = esiclient(request)
ironic_node = connection.baremetal.get_node(node)
port = networks.create_port(connection, ironic_node.name, connection.network.get_network(network_id))
kwargs['nics'] = [{'port': port.id}]

floating_ip_option = kwargs.get('floatingIPOption')
if floating_ip_option == 'attach':
floating_ip_address = kwargs['selectedFloatingIP']
floating_ip = connection.network.find_ip(floating_ip_address)
connection.network.update_ip(floating_ip, port_id=port.id)
elif floating_ip_option == 'create':
external_network_id = settings.ESI_EXTERNAL_NETWORK
floating_ip = connection.network.create_ip(floating_network_id=external_network_id)
connection.network.update_ip(floating_ip, port_id=port.id)

del kwargs['floatingIPOption']
if 'selectedFloatingIP' in kwargs:
del kwargs['selectedFloatingIP']
if 'floatingIPOption' in kwargs:
floating_ip_option = kwargs['floatingIPOption']
if floating_ip_option == 'none':
kwargs['nics'] = [{'network': network_id}]
elif floating_ip_option:
connection = esiclient(request)
ironic_node = connection.baremetal.get_node(node)
port = networks.create_port(connection, ironic_node.name, connection.network.get_network(network_id))
kwargs['nics'] = [{'port': port.id}]

if floating_ip_option == 'attach':
floating_ip_address = kwargs['selectedFloatingIP']
floating_ip = connection.network.find_ip(floating_ip_address)
connection.network.update_ip(floating_ip, port_id=port.id)
elif floating_ip_option == 'create':
external_network_id = settings.ESI_EXTERNAL_NETWORK
floating_ip = connection.network.create_ip(floating_network_id=external_network_id)
connection.network.update_ip(floating_ip, port_id=port.id)

del kwargs['floatingIPOption']
if 'selectedFloatingIP' in kwargs:
del kwargs['selectedFloatingIP']

provisioner.provision_node(node, **kwargs)

Expand Down

0 comments on commit 6564fdf

Please sign in to comment.