Skip to content

fix: filter ports by network_id for floating IP attachment#7

Draft
Koan-Bot wants to merge 2 commits into
atoomic:masterfrom
Koan-Bot:koan.atoomic/fix-floating-ip-port-filter
Draft

fix: filter ports by network_id for floating IP attachment#7
Koan-Bot wants to merge 2 commits into
atoomic:masterfrom
Koan-Bot:koan.atoomic/fix-floating-ip-port-filter

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

What

add_floating_ip_to_server() now filters ports by network_id instead of blindly picking the first port.

Why

On multi-homed VMs (multiple NICs on different networks), the old code grabbed ports->[0] — whichever port the API returned first. This could attach the floating IP to the wrong interface (e.g. a management NIC instead of the production one). The original code even had a comment acknowledging this: # pick the first port for now (maybe need to check the network_id...).

How

  • Added optional network_id parameter to add_floating_ip_to_server() via %opts hash
  • When provided, filters the server's ports to find the one on the specified network
  • create_vm() now passes $network->{id} (the VM's internal network) to ensure correct port selection
  • Omitting network_id preserves backward-compatible first-port behavior

Testing

  • New test file t/floating-ip-port-filter.t with 3 scenarios:
    • Multi-homed VM: correct port selected by network_id
    • No matching port: dies with descriptive error
    • No network_id: backward-compatible first-port fallback
  • Full suite passes (7 files, 27 tests)

🤖 Generated with Claude Code


Quality Report

Changes: 4 files changed, 191 insertions(+), 6 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Koan-Bot and others added 2 commits April 20, 2026 07:22
Demonstrates the bug where add_floating_ip_to_server() blindly picks
the first port instead of filtering by network_id. On multi-homed VMs
with multiple NICs, this attaches the floating IP to the wrong port.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On multi-homed VMs with multiple NICs, the old code blindly picked the
first port returned by the API, which could attach the floating IP to
the wrong network interface. Now accepts an optional network_id param
to filter ports, and create_vm passes the VM's network_id to ensure
correct port selection. Backward compatible — omitting network_id
preserves the old first-port behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Koan-Bot
Koan-Bot force-pushed the koan.atoomic/fix-floating-ip-port-filter branch from ababae8 to 481cd71 Compare April 20, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant